diff --git a/modules/claims_api/lib/bgs_service/local_bgs.rb b/modules/claims_api/lib/bgs_service/local_bgs.rb index e260e9f9712..70cec2d24df 100644 --- a/modules/claims_api/lib/bgs_service/local_bgs.rb +++ b/modules/claims_api/lib/bgs_service/local_bgs.rb @@ -188,8 +188,14 @@ def find_intent_to_file_by_ptcpnt_id_itf_type_cd(id, type) itf_type_cd = body.at 'itfTypeCd' itf_type_cd.content = type.to_s - make_request(endpoint: 'IntentToFileWebServiceBean/IntentToFileWebService', - action: 'findIntentToFileByPtcpntIdItfTypeCd', body:, key: 'IntentToFileDTO') + response = + make_request( + endpoint: 'IntentToFileWebServiceBean/IntentToFileWebService', + action: 'findIntentToFileByPtcpntIdItfTypeCd', + body: + ) + + Array.wrap(response[:intent_to_file_dto]) end # BEGIN: switching v1 from evss to bgs. Delete after EVSS is no longer available. Fix controller first. @@ -261,35 +267,21 @@ def full_body(action:, body:, namespace:, namespaces:) body.to_s end - def parsed_response(res, action, key = nil) - parsed = Hash.from_xml(res.body) - if action == 'findIntentToFileByPtcpntIdItfTypeCd' - itf_response = [] - [parsed.dig('Envelope', 'Body', "#{action}Response", key)].flatten.each do |itf| - return itf_response if itf.nil? + def parsed_response(response, action:, key:, transform:) + body = Hash.from_xml(response.body) + keys = ['Envelope', 'Body', "#{action}Response"] + keys << key if key.present? - temp = itf.deep_transform_keys(&:underscore) - &.deep_symbolize_keys - itf_response.push(temp) + body.dig(*keys).to_h.tap do |value| + if transform + value.deep_transform_keys! do |key| + key.underscore.to_sym + end end - return itf_response end - if key.nil? - parsed.dig('Envelope', 'Body', "#{action}Response") - &.deep_transform_keys(&:underscore) - &.deep_symbolize_keys || {} - else - parsed.dig('Envelope', 'Body', "#{action}Response", key) - &.deep_transform_keys(&:underscore) - &.deep_symbolize_keys || {} - end - end - - def namespaces - {} end - def make_request(endpoint:, action:, body:, key: nil) # rubocop:disable Metrics/MethodLength + def make_request(endpoint:, action:, body:, key: nil, namespaces: {}, transform_response: true) # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists connection = log_duration event: 'establish_ssl_connection' do Faraday::Connection.new(ssl: { verify_mode: @ssl_verify_mode }) do |f| f.use :breakers @@ -324,7 +316,7 @@ def make_request(endpoint:, action:, body:, key: nil) # rubocop:disable Metrics/ soap_error_handler.handle_errors(response) if response log_duration(event: 'parsed_response', key:) do - parsed_response(response, action, key) + parsed_response(response, action:, key:, transform: transform_response) end end diff --git a/modules/claims_api/lib/bgs_service/manage_representative_service.rb b/modules/claims_api/lib/bgs_service/manage_representative_service.rb index 490c6143c89..34686744e0c 100644 --- a/modules/claims_api/lib/bgs_service/manage_representative_service.rb +++ b/modules/claims_api/lib/bgs_service/manage_representative_service.rb @@ -5,14 +5,15 @@ module ClaimsApi class ManageRepresentativeService < ClaimsApi::LocalBGS - def endpoint - 'VDC/ManageRepresentativeService' - end + private - def namespaces - { - 'data' => '/data' - } + def make_request(**args) + super( + endpoint: 'VDC/ManageRepresentativeService', + namespaces: { 'data' => '/data' }, + transform_response: false, + **args + ) end end end diff --git a/modules/claims_api/lib/bgs_service/manage_representative_service/read_poa_request.rb b/modules/claims_api/lib/bgs_service/manage_representative_service/read_poa_request.rb index 5c668e78869..a1ed4b1133d 100644 --- a/modules/claims_api/lib/bgs_service/manage_representative_service/read_poa_request.rb +++ b/modules/claims_api/lib/bgs_service/manage_representative_service/read_poa_request.rb @@ -30,7 +30,6 @@ def read_poa_request(poa_codes: nil, statuses: nil) end make_request( - endpoint:, action: 'readPOARequest', body: builder.doc.at('root').children.to_xml, key: 'POARequestRespondReturnVO' diff --git a/modules/claims_api/lib/bgs_service/manage_representative_service/update_poa_request.rb b/modules/claims_api/lib/bgs_service/manage_representative_service/update_poa_request.rb index 3710688cde8..af494d328af 100644 --- a/modules/claims_api/lib/bgs_service/manage_representative_service/update_poa_request.rb +++ b/modules/claims_api/lib/bgs_service/manage_representative_service/update_poa_request.rb @@ -16,7 +16,6 @@ def update_poa_request(representative:, proc_id:) EOXML make_request( - endpoint:, action: 'updatePOARequest', body: body.to_s, key: 'POARequestUpdate' diff --git a/modules/claims_api/spec/lib/claims_api/manage_representative_service/read_poa_request_spec.rb b/modules/claims_api/spec/lib/claims_api/manage_representative_service/read_poa_request_spec.rb index 9bcd9d6f55b..24ba183322a 100644 --- a/modules/claims_api/spec/lib/claims_api/manage_representative_service/read_poa_request_spec.rb +++ b/modules/claims_api/spec/lib/claims_api/manage_representative_service/read_poa_request_spec.rb @@ -138,30 +138,30 @@ let(:expected) do { - poa_request_respond_return_vo_list: { - vso_user_email: nil, - vso_user_first_name: 'VDC USER', - vso_user_last_name: nil, - change_address_auth: 'Y', - claimant_city: 'SEASIDE', - claimant_country: 'USA', - claimant_military_po: nil, - claimant_military_postal_code: nil, - claimant_state: 'MT', - claimant_zip: '95102', - date_request_actioned: '2015-08-05T11:33:20-05:00', - date_request_received: '2015-08-05T11:33:20-05:00', - declined_reason: nil, - health_info_auth: 'N', - poa_code: '091', - proc_id: '52095', - secondary_status: 'New', - vet_first_name: 'Wallace', - vet_last_name: 'Webb', - vet_middle_name: 'R', - vet_ptcpnt_id: '600043200' + 'poaRequestRespondReturnVOList' => { + 'VSOUserEmail' => nil, + 'VSOUserFirstName' => 'VDC USER', + 'VSOUserLastName' => nil, + 'changeAddressAuth' => 'Y', + 'claimantCity' => 'SEASIDE', + 'claimantCountry' => 'USA', + 'claimantMilitaryPO' => nil, + 'claimantMilitaryPostalCode' => nil, + 'claimantState' => 'MT', + 'claimantZip' => '95102', + 'dateRequestActioned' => '2015-08-05T11:33:20-05:00', + 'dateRequestReceived' => '2015-08-05T11:33:20-05:00', + 'declinedReason' => nil, + 'healthInfoAuth' => 'N', + 'poaCode' => '091', + 'procID' => '52095', + 'secondaryStatus' => 'New', + 'vetFirstName' => 'Wallace', + 'vetLastName' => 'Webb', + 'vetMiddleName' => 'R', + 'vetPtcpntID' => '600043200' }, - total_nbr_of_records: '1' + 'totalNbrOfRecords' => '1' } end diff --git a/modules/claims_api/spec/lib/claims_api/manage_representative_service/update_poa_request_spec.rb b/modules/claims_api/spec/lib/claims_api/manage_representative_service/update_poa_request_spec.rb index 2e0b72304f0..525f504f95b 100644 --- a/modules/claims_api/spec/lib/claims_api/manage_representative_service/update_poa_request_spec.rb +++ b/modules/claims_api/spec/lib/claims_api/manage_representative_service/update_poa_request_spec.rb @@ -47,13 +47,13 @@ use_bgs_cassette('happy_path') do expect(subject).to eq( { - vso_user_email: nil, - vso_user_first_name: params[:representative].first_name, - vso_user_last_name: params[:representative].last_name, - declined_reason: nil, - proc_id: params[:proc_id], - secondary_status: 'OBS', - date_request_actioned: + 'VSOUserEmail' => nil, + 'VSOUserFirstName' => params[:representative].first_name, + 'VSOUserLastName' => params[:representative].last_name, + 'declinedReason' => nil, + 'procId' => params[:proc_id], + 'secondaryStatus' => 'OBS', + 'dateRequestActioned' => # Formatting this to show the difference between the date returned # in response and the date sent in request. Time.current.in_time_zone('America/Chicago').iso8601