From 225805b190a44e3bf8646552996a700cf41ebf26 Mon Sep 17 00:00:00 2001 From: Khoa Nguyen <134089461+Khoa-V-Nguyen@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:07:16 -0600 Subject: [PATCH 1/3] BE | Ask Va Api: `Inquiries` retriever error handling (#16489) * update inquiries retriever error handling * remove authenticate for InquiriesController#show action --------- Co-authored-by: khoa-v-nguyen --- .../ask_va_api/v0/inquiries_controller.rb | 4 ++- .../app/lib/ask_va_api/inquiries/retriever.rb | 7 ++++- .../ask_va_api/inquiries/retriever_spec.rb | 20 ++++++++----- .../spec/requests/v0/inquiries_spec.rb | 30 +++++++++---------- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/modules/ask_va_api/app/controllers/ask_va_api/v0/inquiries_controller.rb b/modules/ask_va_api/app/controllers/ask_va_api/v0/inquiries_controller.rb index 9cc82b5a60e..12f91508ed1 100644 --- a/modules/ask_va_api/app/controllers/ask_va_api/v0/inquiries_controller.rb +++ b/modules/ask_va_api/app/controllers/ask_va_api/v0/inquiries_controller.rb @@ -6,7 +6,7 @@ class InquiriesController < ApplicationController around_action :handle_exceptions before_action :get_inquiries_by_icn, only: [:index] before_action :get_inquiry_by_id, only: [:show] - skip_before_action :authenticate, only: %i[unauth_create upload_attachment test_create] + skip_before_action :authenticate, only: %i[unauth_create upload_attachment test_create show] skip_before_action :verify_authenticity_token, only: %i[unauth_create upload_attachment test_create] def index @@ -63,6 +63,8 @@ def create_reply private def get_inquiry_by_id + entity_class = AskVAApi::Inquiries::Entity + retriever = Inquiries::Retriever.new(user_mock_data: params[:mock], entity_class:) inq = retriever.fetch_by_id(id: params[:id]) @inquiry = Result.new(payload: Inquiries::Serializer.new(inq).serializable_hash, status: :ok) end diff --git a/modules/ask_va_api/app/lib/ask_va_api/inquiries/retriever.rb b/modules/ask_va_api/app/lib/ask_va_api/inquiries/retriever.rb index 0951d724eb8..073c35f8832 100644 --- a/modules/ask_va_api/app/lib/ask_va_api/inquiries/retriever.rb +++ b/modules/ask_va_api/app/lib/ask_va_api/inquiries/retriever.rb @@ -57,7 +57,12 @@ def filter_data(data, id = nil) end def handle_response_data(response) - response[:Data].presence || raise(InquiriesRetrieverError, response[:Message]) + if response[:Data].nil? + error = JSON.parse(response[:body], symbolize_names: true) + raise InquiriesRetrieverError, error[:Message] + else + response[:Data] + end end end end diff --git a/modules/ask_va_api/spec/app/lib/ask_va_api/inquiries/retriever_spec.rb b/modules/ask_va_api/spec/app/lib/ask_va_api/inquiries/retriever_spec.rb index b848c81cb93..ee1f4e45987 100644 --- a/modules/ask_va_api/spec/app/lib/ask_va_api/inquiries/retriever_spec.rb +++ b/modules/ask_va_api/spec/app/lib/ask_va_api/inquiries/retriever_spec.rb @@ -20,17 +20,23 @@ describe '#call' do context 'when Crm raise an error' do let(:icn) { '123' } - let(:response) do - { Data: nil, - Message: 'Data Validation: No Contact found by ICN', - ExceptionOccurred: true, - ExceptionMessage: 'Data Validation: No Contact found by ICN', - MessageId: '2733ca25-7e64-4fbc-af2c-366f4bd2e3dc' } + let(:body) do + '{"Data":null,"Message":"Data Validation: No Inquiries found by ID A-20240423-30709"' \ + ',"ExceptionOccurred":true,"ExceptionMessage":"Data Validation: No Inquiries found by ' \ + 'ID A-20240423-30709","MessageId":"ca5b990a-63fe-407d-a364-46caffce12c1"}' + end + let(:failure) do + { + status: 400, + body:, + response_headers: nil, + url: nil + } end before do allow_any_instance_of(Crm::CrmToken).to receive(:call).and_return('Token') - allow(service).to receive(:call).and_return(response) + allow(service).to receive(:call).and_return(failure) end it 'raise CorrespondenceRetrieverrError' do diff --git a/modules/ask_va_api/spec/requests/v0/inquiries_spec.rb b/modules/ask_va_api/spec/requests/v0/inquiries_spec.rb index 25ff307fb6f..03eec8510ca 100644 --- a/modules/ask_va_api/spec/requests/v0/inquiries_spec.rb +++ b/modules/ask_va_api/spec/requests/v0/inquiries_spec.rb @@ -207,19 +207,25 @@ end context 'when the id is invalid' do - let(:crm_response) do - { Data: nil, - Message: 'Data Validation: No Inquiries found by ID A-20230305-30617', - ExceptionOccurred: true, - ExceptionMessage: 'Data Validation: No Inquiries found by ID A-20230305-30617', - MessageId: 'e6024ccb-e19b-4bc6-990c-667e7ebab4ec' } + let(:body) do + '{"Data":null,"Message":"Data Validation: No Inquiries found by ID A-20240423-30709"' \ + ',"ExceptionOccurred":true,"ExceptionMessage":"Data Validation: No Inquiries found by ' \ + 'ID A-20240423-30709","MessageId":"ca5b990a-63fe-407d-a364-46caffce12c1"}' + end + let(:failure) do + { + status: 400, + body:, + response_headers: nil, + url: nil + } end let(:service) { instance_double(Crm::Service) } before do allow(Crm::Service).to receive(:new).and_return(service) allow_any_instance_of(Crm::CrmToken).to receive(:call).and_return('Token') - allow(service).to receive(:call).and_return(crm_response) + allow(service).to receive(:call).and_return(failure) sign_in(authorized_user) get "#{inquiry_path}/#{invalid_id}" end @@ -228,17 +234,9 @@ it_behaves_like 'common error handling', :unprocessable_entity, 'service_error', 'AskVAApi::Inquiries::InquiriesRetrieverError: ' \ - 'Data Validation: No Inquiries found by ID A-20230305-30617' + 'Data Validation: No Inquiries found by ID A-20240423-30709' end end - - context 'when user is not signed in' do - before do - get "#{inquiry_path}/#{valid_id}" - end - - it { expect(response).to have_http_status(:unauthorized) } - end end describe 'GET #download_attachment' do From 4f082e5f97b280b50a890b555ea0e9e2c924d340 Mon Sep 17 00:00:00 2001 From: Seth Darr <92405130+sethdarragile6@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:26:20 -0700 Subject: [PATCH 2/3] Toxic Exposure: Add basic toxicExposure node to pre-submission JSON (#16450) * add toxicExposure to pre-submission JSON * remove aborted test attempt * fixed malformed JSON in with_everything * rubocop'd it * add TE flipper flag * remove breakpoints * rubocop * fix the with_everything.json * change toxicExposureConditions to conditions --- .../data_translation_all_claim.rb | 9 +++ .../data_translation_all_claim_spec.rb | 30 +++++++++ ...sability_compensation_form_request_spec.rb | 2 + .../all_claims_fe_submission.json | 1 + .../submissions/with_everything.json | 64 ++++++++++++++++++- 5 files changed, 105 insertions(+), 1 deletion(-) diff --git a/lib/evss/disability_compensation_form/data_translation_all_claim.rb b/lib/evss/disability_compensation_form/data_translation_all_claim.rb index 8eda0195f33..dd7b695d1a0 100644 --- a/lib/evss/disability_compensation_form/data_translation_all_claim.rb +++ b/lib/evss/disability_compensation_form/data_translation_all_claim.rb @@ -62,6 +62,7 @@ def translate output_form.update(translate_veteran) output_form.update(translate_treatments) output_form.update(translate_disabilities) + output_form.update(add_toxic_exposure) if Flipper.enabled?(:disability_526_toxic_exposure, @current_user) @translated_form end @@ -629,6 +630,14 @@ def map_secondary(input_disability, disabilities) end end + ### + # Toxic Exposure + ### + + def add_toxic_exposure + { 'toxicExposure' => input_form['toxicExposure'] } + end + def application_expiration_date 1.year.from_now.iso8601 end diff --git a/spec/lib/evss/disability_compensation_form/data_translation_all_claim_spec.rb b/spec/lib/evss/disability_compensation_form/data_translation_all_claim_spec.rb index 0d000d350b5..88ac3800b51 100644 --- a/spec/lib/evss/disability_compensation_form/data_translation_all_claim_spec.rb +++ b/spec/lib/evss/disability_compensation_form/data_translation_all_claim_spec.rb @@ -1451,6 +1451,36 @@ end end + describe '#add_toxic_exposure' do + let(:form_content) do + { + 'form526' => { + 'toxicExposure' => { + 'gulfWar1990' => { + 'iraq' => true, + 'kuwait' => true, + 'qatar' => true + } + } + } + } + end + + it 'returns toxic exposure' do + expect(subject.send(:add_toxic_exposure)).to eq( + { + 'toxicExposure' => { + 'gulfWar1990' => { + 'iraq' => true, + 'kuwait' => true, + 'qatar' => true + } + } + } + ) + end + end + describe '#application_expiration_date' do it 'returns the application creation date + 365 days' do expect(subject.send(:application_expiration_date)).to eq '2021-11-05T18:19:50Z' diff --git a/spec/requests/disability_compensation_form_request_spec.rb b/spec/requests/disability_compensation_form_request_spec.rb index eb08c9a4385..6825d965218 100644 --- a/spec/requests/disability_compensation_form_request_spec.rb +++ b/spec/requests/disability_compensation_form_request_spec.rb @@ -242,6 +242,8 @@ def test_error(cassette_path, status, headers) post('/v0/disability_compensation_form/submit_all_claim', params: all_claims_form, headers:) expect(response).to have_http_status(:ok) expect(response).to match_response_schema('submit_disability_form') + form = Form526Submission.last.form + expect(form.dig('form526', 'form526', 'toxicExposure')).not_to eq(nil) end it 'matches the rated disabilites schema with camel-inflection' do diff --git a/spec/support/disability_compensation_form/all_claims_fe_submission.json b/spec/support/disability_compensation_form/all_claims_fe_submission.json index 648eff4fd18..200e53e75c2 100644 --- a/spec/support/disability_compensation_form/all_claims_fe_submission.json +++ b/spec/support/disability_compensation_form/all_claims_fe_submission.json @@ -144,6 +144,7 @@ ] } ], + "toxicExposure": {}, "waiveRetirementPay": false, "waiveTrainingPay": true, "hasTrainingPay": true diff --git a/spec/support/disability_compensation_form/submissions/with_everything.json b/spec/support/disability_compensation_form/submissions/with_everything.json index 1fb50701faa..d93f8ff4aa9 100644 --- a/spec/support/disability_compensation_form/submissions/with_everything.json +++ b/spec/support/disability_compensation_form/submissions/with_everything.json @@ -191,7 +191,69 @@ } ] } - ] + ], + "toxicExposure": { + "gulfWar1990": { + "iraq": true, + "kuwait": true, + "qatar": true + }, + "gulfWar1990Details": { + "iraq": { + "startDate": "1991-03-01", + "endDate": "1992-01-01" + }, + "qatar": { + "startDate": "1991-02-12", + "endDate": "1991-06-01" + }, + "kuwait": { + "startDate": "1991-03-15" + } + }, + "herbicide": { + "cambodia": true, + "guam": true, + "laos": true + }, + "herbicideDetails": { + "cambodia": { + "startDate": "1991-03-01", + "endDate": "1992-01-01" + }, + "guam": { + "startDate": "1991-02-12", + "endDate": "1991-06-01" + }, + "laos": { + "startDate": "1991-03-15" + } + }, + "otherHerbicideLocations": "freeform text field.", + "otherExposures": { + "asbestos": true, + "radiation": true, + "mustardgas": false + }, + "otherExposureDetails": { + "asbestos": { + "startDate": "1991-03-01", + "endDate": "1992-01-01" + }, + "radiation": { + "startDate": "1991-03-01", + "endDate": "1992-01-01" + } + }, + "specifyOtherExposures": { + "description": "Lead, burn pits", + "startDate": "1991-03-01", + "endDate": "1992-01-01" + }, + "conditions": { + "deviatedseptum": true + } + } } }, "form526_uploads": [ From 9f01854a9f55ac5d7089fb57dde1a6d4408669ab Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 25 Apr 2024 07:31:19 -0500 Subject: [PATCH 3/3] Bump super_diff from 0.11.0 to 0.12.0 (#16495) Bumps [super_diff](https://github.com/mcmire/super_diff) from 0.11.0 to 0.12.0. - [Release notes](https://github.com/mcmire/super_diff/releases) - [Changelog](https://github.com/mcmire/super_diff/blob/main/CHANGELOG.md) - [Commits](https://github.com/mcmire/super_diff/compare/v0.11.0...v0.12.0) --- updated-dependencies: - dependency-name: super_diff dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index c97180f9bf7..d347bccd1bc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -998,7 +998,7 @@ GEM stringio (3.1.0) strong_migrations (1.8.0) activerecord (>= 5.2) - super_diff (0.11.0) + super_diff (0.12.0) attr_extras (>= 6.2.4) diff-lcs patience_diff