From 1dc20f808fbcf773a9c67cbb2c801abfb0daf25b Mon Sep 17 00:00:00 2001 From: Tyler Date: Mon, 4 Nov 2024 08:58:46 -0800 Subject: [PATCH] [API-40542] Create POA Request - Return Proc ID (#19210) * rename create function; add procId to response * add test * add procId to response in docs --- .../power_of_attorney/request_controller.rb | 11 +- .../swagger/claims_api/v2/dev/swagger.json | 8 +- modules/claims_api/config/routes.rb | 2 +- .../request_controller_spec.rb | 136 ++++++++++++++++++ .../power_of_attorney_request_spec.rb | 24 ---- .../veterans/rswag_power_of_attorney_spec.rb | 5 +- .../request_representative/submit.json | 5 + 7 files changed, 159 insertions(+), 32 deletions(-) diff --git a/modules/claims_api/app/controllers/claims_api/v2/veterans/power_of_attorney/request_controller.rb b/modules/claims_api/app/controllers/claims_api/v2/veterans/power_of_attorney/request_controller.rb index 1bc1175d576..a3d87aaa0d9 100644 --- a/modules/claims_api/app/controllers/claims_api/v2/veterans/power_of_attorney/request_controller.rb +++ b/modules/claims_api/app/controllers/claims_api/v2/veterans/power_of_attorney/request_controller.rb @@ -59,7 +59,7 @@ def decide render json: res, status: :ok end - def request_representative + def create # validate target veteran exists target_veteran @@ -81,10 +81,11 @@ def request_representative # skip the BGS API calls in lower environments to prevent 3rd parties from creating data in external systems unless Flipper.enabled?(:lighthouse_claims_v2_poa_requests_skip_bgs) - ClaimsApi::PowerOfAttorneyRequestService::Orchestrator.new(target_veteran.participant_id, - bgs_form_attributes.deep_symbolize_keys, - user_profile&.profile&.participant_id, - :poa).submit_request + res = ClaimsApi::PowerOfAttorneyRequestService::Orchestrator.new(target_veteran.participant_id, + bgs_form_attributes.deep_symbolize_keys, + user_profile&.profile&.participant_id, + :poa).submit_request + form_attributes['procId'] = res['procId'] end # return only the form information consumers provided diff --git a/modules/claims_api/app/swagger/claims_api/v2/dev/swagger.json b/modules/claims_api/app/swagger/claims_api/v2/dev/swagger.json index 1cfab6991e9..3b533de5580 100644 --- a/modules/claims_api/app/swagger/claims_api/v2/dev/swagger.json +++ b/modules/claims_api/app/swagger/claims_api/v2/dev/swagger.json @@ -17357,7 +17357,8 @@ "SICKLE_CELL", "HIV", "ALCOHOLISM" - ] + ], + "procId": "3857415" } } }, @@ -17638,6 +17639,11 @@ "consentAddressChange": { "description": "AUTHORIZATION FOR REPRESENTATIVE TO ACT ON CLAIMANT'S BEHALF TO CHANGE CLAIMANT'S ADDRESS.", "type": "boolean" + }, + "procId": { + "description": "The process ID of the new Power of Attorney request.", + "type": "string", + "example": "12345" } } } diff --git a/modules/claims_api/config/routes.rb b/modules/claims_api/config/routes.rb index b4c18720249..d52efd8ccf2 100644 --- a/modules/claims_api/config/routes.rb +++ b/modules/claims_api/config/routes.rb @@ -50,8 +50,8 @@ post '/:veteranId/2122a/validate', to: 'individual#validate' post '/:veteranId/2122a', to: 'individual#submit' get '/:veteranId/power-of-attorney/:id', to: 'base#status' - post '/:veteranId/power-of-attorney-request', to: 'request#request_representative' # Power of Attorney Requests + post '/:veteranId/power-of-attorney-request', to: 'request#create' post '/power-of-attorney-requests', to: 'request#index' post '/power-of-attorney-requests/decide', to: 'request#decide' end diff --git a/modules/claims_api/spec/controllers/v2/veterans/power_of_attorney/request_controller_spec.rb b/modules/claims_api/spec/controllers/v2/veterans/power_of_attorney/request_controller_spec.rb index e6a15022cd8..df757335784 100644 --- a/modules/claims_api/spec/controllers/v2/veterans/power_of_attorney/request_controller_spec.rb +++ b/modules/claims_api/spec/controllers/v2/veterans/power_of_attorney/request_controller_spec.rb @@ -124,6 +124,136 @@ end end + describe '#create' do + let(:scopes) { %w[claim.write] } + let(:form_attributes) do + { + veteran: { + service_number: '123678453', + service_branch: 'ARMY', + address: { + address_line1: '2719 Hyperion Ave', + address_line2: 'Apt 2', + city: 'Los Angeles', + country: 'USA', + state_code: 'CA', + zip_code: '92264', + zip_code_suffix: '0200' + }, + phone: { + area_code: '555', + phone_number: '5551234' + }, + email: 'test@test.com', + insurance_number: '1234567890' + }, + poa: { + poa_code: '003', + registration_number: '12345', + job_title: 'MyJob' + }, + record_consent: true, + consent_address_change: true, + consent_limits: %w[ + DRUG_ABUSE + SICKLE_CELL + HIV + ALCOHOLISM + ] + } + end + let(:veteran_id) { '1012667145V762142' } + let(:representative_data) do + { + 'poa' => { + 'firstName' => 'John', + 'lastName' => 'Doe' + } + } + end + let(:terminate_existing_requests) do + instance_double(ClaimsApi::PowerOfAttorneyRequestService::TerminateExistingRequests) + end + let(:create_request) do + instance_double(ClaimsApi::PowerOfAttorneyRequestService::CreateRequest) + end + let(:create_request_response) do + { + 'addressLine1' => '2719 Hyperion Ave', + 'addressLine2' => 'Apt 2', + 'addressLine3' => nil, + 'changeAddressAuth' => 'true', + 'city' => 'Los Angeles', + 'claimantPtcpntId' => '185953', + 'claimantRelationship' => nil, + 'formTypeCode' => '21-22', + 'insuranceNumbers' => '1234567890', + 'limitationAlcohol' => 'true', + 'limitationDrugAbuse' => 'true', + 'limitationHIV' => 'true', + 'limitationSCA' => 'true', + 'organizationName' => nil, + 'otherServiceBranch' => nil, + 'phoneNumber' => '5555551234', + 'poaCode' => '003', + 'postalCode' => '92264', + 'procId' => '3857415', + 'representativeFirstName' => nil, + 'representativeLastName' => nil, + 'representativeLawFirmOrAgencyName' => nil, + 'representativeTitle' => 'MyJob', + 'representativeType' => 'Recognized Veterans Service Organization', + 'section7332Auth' => 'true', + 'serviceBranch' => 'Army', + 'serviceNumber' => '123678453', + 'state' => 'CA', + 'vdcStatus' => 'Submitted', + 'veteranPtcpntId' => '185953', + 'acceptedBy' => nil, + 'claimantFirstName' => 'TAMARA', + 'claimantLastName' => 'ELLIS', + 'claimantMiddleName' => nil, + 'declinedBy' => nil, + 'declinedReason' => nil, + 'secondaryStatus' => nil, + 'veteranFirstName' => 'TAMARA', + 'veteranLastName' => 'ELLIS', + 'veteranMiddleName' => nil, + 'veteranSSN' => '796130115', + 'veteranVAFileNumber' => '00123456' + } + end + + before do + allow_any_instance_of(ClaimsApi::FormSchemas).to receive(:validate!).and_return(nil) + allow_any_instance_of(described_class).to receive(:validate_accredited_representative) + .with(anything, anything) + .and_return(nil) + allow_any_instance_of(described_class).to receive(:validate_accredited_organization) + .with(anything) + .and_return(nil) + allow_any_instance_of(described_class).to receive(:representative_data).and_return(representative_data) + Flipper.disable(:lighthouse_claims_v2_poa_requests_skip_bgs) + allow(ClaimsApi::PowerOfAttorneyRequestService::TerminateExistingRequests).to receive(:new) + .with(anything) + .and_return(terminate_existing_requests) + allow(terminate_existing_requests).to receive(:call).and_return(nil) + allow(ClaimsApi::PowerOfAttorneyRequestService::CreateRequest).to receive(:new) + .with(anything, anything, anything, anything) + .and_return(create_request) + allow(create_request).to receive(:call).and_return(create_request_response) + end + + it 'returns a created status and procId in the response' do + mock_ccg(scopes) do |auth_header| + create_request_with(veteran_id:, form_attributes:, auth_header:) + + expect(response).to have_http_status(:created) + expect(JSON.parse(response.body)['data']['attributes']['procId']).to eq('3857415') + end + end + end + def index_request_with(poa_codes:, auth_header:) post v2_veterans_power_of_attorney_requests_path, params: { data: { attributes: { poaCodes: poa_codes } } }.to_json, @@ -135,4 +265,10 @@ def decide_request_with(proc_id:, decision:, auth_header:) params: { data: { attributes: { procId: proc_id, decision: } } }.to_json, headers: auth_header end + + def create_request_with(veteran_id:, form_attributes:, auth_header:) + post "/services/claims/v2/veterans/#{veteran_id}/power-of-attorney-request", + params: { data: { attributes: form_attributes } }.to_json, + headers: auth_header + end end diff --git a/modules/claims_api/spec/requests/v2/veterans/power_of_attorney/power_of_attorney_request_spec.rb b/modules/claims_api/spec/requests/v2/veterans/power_of_attorney/power_of_attorney_request_spec.rb index f6de56a3d2a..8d86b0f9788 100644 --- a/modules/claims_api/spec/requests/v2/veterans/power_of_attorney/power_of_attorney_request_spec.rb +++ b/modules/claims_api/spec/requests/v2/veterans/power_of_attorney/power_of_attorney_request_spec.rb @@ -168,30 +168,6 @@ end end end - - context 'lighthouse_claims_v2_poa_requests_skip_bgs disabled' do - before do - Flipper.disable(:lighthouse_claims_v2_poa_requests_skip_bgs) - end - - it 'responds with created status and the original request body' do - VCR.use_cassette('claims_api/mpi/find_candidate/valid_icn_full') do - mock_ccg(scopes) do |auth_header| - # the final return from BGS does not matter at this point in time, the calls need only to succeed - allow_any_instance_of(ClaimsApi::PowerOfAttorneyRequestService::Orchestrator) - .to receive(:submit_request) - .and_return(true) - - post request_path, params: request_body, headers: auth_header - - response_body = JSON.parse(response.body) - - expect(response).to have_http_status(:created) - expect(response_body).to eq(JSON.parse(request_body)) - end - end - end - end end end diff --git a/modules/claims_api/spec/requests/v2/veterans/rswag_power_of_attorney_spec.rb b/modules/claims_api/spec/requests/v2/veterans/rswag_power_of_attorney_spec.rb index 37c169a0164..193b4d7182f 100644 --- a/modules/claims_api/spec/requests/v2/veterans/rswag_power_of_attorney_spec.rb +++ b/modules/claims_api/spec/requests/v2/veterans/rswag_power_of_attorney_spec.rb @@ -987,7 +987,10 @@ after do |example| example.metadata[:response][:content] = { 'application/json' => { - example: JSON.parse(response.body, symbolize_names: true) + example: JSON.parse(response.body, symbolize_names: true).tap do |json| + json[:data][:attributes] + .merge!(procId: '3857415') + end } } end diff --git a/spec/support/schemas/claims_api/v2/veterans/power_of_attorney/request_representative/submit.json b/spec/support/schemas/claims_api/v2/veterans/power_of_attorney/request_representative/submit.json index 6ab10cc0046..cf96cf0ff0c 100644 --- a/spec/support/schemas/claims_api/v2/veterans/power_of_attorney/request_representative/submit.json +++ b/spec/support/schemas/claims_api/v2/veterans/power_of_attorney/request_representative/submit.json @@ -267,6 +267,11 @@ "consentAddressChange": { "description": "AUTHORIZATION FOR REPRESENTATIVE TO ACT ON CLAIMANT'S BEHALF TO CHANGE CLAIMANT'S ADDRESS.", "type": "boolean" + }, + "procId": { + "description": "The process ID of the new Power of Attorney request.", + "type": "string", + "example": "12345" } } }