From 4399675a5f53b26b69dc1b8d0f2a4b215dc41443 Mon Sep 17 00:00:00 2001 From: s-caso Date: Tue, 7 Jan 2025 12:37:09 -0500 Subject: [PATCH 01/15] handle case where claimant response isn't a hash --- modules/meb_api/lib/dgi/claimant/claimant_response.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/meb_api/lib/dgi/claimant/claimant_response.rb b/modules/meb_api/lib/dgi/claimant/claimant_response.rb index 22aef2e583f..30768725df5 100644 --- a/modules/meb_api/lib/dgi/claimant/claimant_response.rb +++ b/modules/meb_api/lib/dgi/claimant/claimant_response.rb @@ -10,7 +10,7 @@ class ClaimantResponse < MebApi::DGI::Response def initialize(status, response = nil) attributes = { - claimant_id: response&.body&.fetch('claimant_id', nil) + claimant_id: response&.body.is_a? String ? response&.body : response&.body&.fetch('claimant_id', nil) } super(status, attributes) end From 46a2bf2963ba7290c5a5a63de2658176f8e5ee17 Mon Sep 17 00:00:00 2001 From: s-caso Date: Tue, 7 Jan 2025 13:17:35 -0500 Subject: [PATCH 02/15] update syntax for string check --- modules/meb_api/lib/dgi/claimant/claimant_response.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/meb_api/lib/dgi/claimant/claimant_response.rb b/modules/meb_api/lib/dgi/claimant/claimant_response.rb index 30768725df5..d45ed794707 100644 --- a/modules/meb_api/lib/dgi/claimant/claimant_response.rb +++ b/modules/meb_api/lib/dgi/claimant/claimant_response.rb @@ -10,7 +10,7 @@ class ClaimantResponse < MebApi::DGI::Response def initialize(status, response = nil) attributes = { - claimant_id: response&.body.is_a? String ? response&.body : response&.body&.fetch('claimant_id', nil) + claimant_id: response&.body.is_a?(String) ? response&.body : response&.body&.fetch('claimant_id', nil) } super(status, attributes) end From 1dbfbb0f2168bfcdad3276ee9fa0c0947ee4f5b9 Mon Sep 17 00:00:00 2001 From: s-caso Date: Tue, 7 Jan 2025 15:47:48 -0500 Subject: [PATCH 03/15] use respond to to check if fetch is viable --- modules/meb_api/lib/dgi/claimant/claimant_response.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/meb_api/lib/dgi/claimant/claimant_response.rb b/modules/meb_api/lib/dgi/claimant/claimant_response.rb index d45ed794707..d17cf3e1821 100644 --- a/modules/meb_api/lib/dgi/claimant/claimant_response.rb +++ b/modules/meb_api/lib/dgi/claimant/claimant_response.rb @@ -10,7 +10,7 @@ class ClaimantResponse < MebApi::DGI::Response def initialize(status, response = nil) attributes = { - claimant_id: response&.body.is_a?(String) ? response&.body : response&.body&.fetch('claimant_id', nil) + claimant_id: response&.body.respond_to?(:fetch) ? response&.body&.fetch('claimant_id', nil) : response&.body } super(status, attributes) end From c758406a6713c35013e1110f098d9cb83d10b0b7 Mon Sep 17 00:00:00 2001 From: s-caso Date: Tue, 7 Jan 2025 16:30:19 -0500 Subject: [PATCH 04/15] lint fix --- modules/meb_api/lib/dgi/claimant/claimant_response.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/meb_api/lib/dgi/claimant/claimant_response.rb b/modules/meb_api/lib/dgi/claimant/claimant_response.rb index d17cf3e1821..514e4ed0f45 100644 --- a/modules/meb_api/lib/dgi/claimant/claimant_response.rb +++ b/modules/meb_api/lib/dgi/claimant/claimant_response.rb @@ -10,7 +10,7 @@ class ClaimantResponse < MebApi::DGI::Response def initialize(status, response = nil) attributes = { - claimant_id: response&.body.respond_to?(:fetch) ? response&.body&.fetch('claimant_id', nil) : response&.body + claimant_id: response&.body.respond_to?(:fetch) ? response&.body&.fetch('claimant_id', nil) : response&.body } super(status, attributes) end From 6955dd659a54ebf90a967e778648d3f9a38e0dbe Mon Sep 17 00:00:00 2001 From: s-caso Date: Mon, 3 Feb 2025 20:35:46 -0500 Subject: [PATCH 05/15] added specs for claimant service response --- .../meb_api/spec/dgi/claimant/service_spec.rb | 58 +++++++++++++++++++ .../dgi/polling_post_claimant_info.yml | 35 +++++++++++ .../polling_with_id_post_claimant_info.yml | 35 +++++++++++ 3 files changed, 128 insertions(+) create mode 100644 modules/meb_api/spec/dgi/claimant/service_spec.rb create mode 100644 spec/support/vcr_cassettes/dgi/polling_post_claimant_info.yml create mode 100644 spec/support/vcr_cassettes/dgi/polling_with_id_post_claimant_info.yml diff --git a/modules/meb_api/spec/dgi/claimant/service_spec.rb b/modules/meb_api/spec/dgi/claimant/service_spec.rb new file mode 100644 index 00000000000..062d0cdae0c --- /dev/null +++ b/modules/meb_api/spec/dgi/claimant/service_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'rails_helper' +require 'dgi/claimant/service' + +Rspec.describe MebApi::DGI::Claimant::Service do + VCR.configure do |config| + config.filter_sensitive_data('removed') do |interaction| + if interaction.request.headers['Authorization'] + token = interaction.request.headers['Authorization'].first + + if (match = token.match(/^Bearer.+/) || token.match(/^token.+/)) + match[0] + end + end + end + + describe '#post_claimant_info for Chapter33' do + let(:user_details) do + { + first_name: 'Herbert', + last_name: 'Hoover', + middle_name: '', + birth_date: '1970-01-01', + ssn: '796126859' + } + end + + let(:user) { create(:user, :loa3, user_details) } + let(:service) { MebApi::DGI::Claimant::Service.new(user) } + let(:faraday_response) { double('faraday_connection') } + + before do + allow(faraday_response).to receive(:env) + end + + context 'with a successful submission and polling for Chapter33' do + it 'successfully receives an Claimant object' do + VCR.use_cassette('dgi/polling_post_claimant_info') do + response = service.get_claimant_info('Chapter33') + expect(response.status).to eq(201) + expect(response[:claimant_id]).to eq(nil) + end + end + end + + context 'with a successful submission and polling with climant id for Chapter33' do + it 'successfully receives an Claimant object' do + VCR.use_cassette('dgi/polling_with_id_post_claimant_info') do + response = service.get_claimant_info('Chapter33') + expect(response.status).to eq(201) + expect(response[:claimant_id]).to eq("600010259") + end + end + end + end + end +end diff --git a/spec/support/vcr_cassettes/dgi/polling_post_claimant_info.yml b/spec/support/vcr_cassettes/dgi/polling_post_claimant_info.yml new file mode 100644 index 00000000000..8da293da04f --- /dev/null +++ b/spec/support/vcr_cassettes/dgi/polling_post_claimant_info.yml @@ -0,0 +1,35 @@ +--- +http_interactions: +- request: + method: post + uri: https://jenkins.ld.afsp.io:32512/vets-service/v1/claimType/Chapter33/claimants/claimantId + body: + encoding: UTF-8 + string: '{"ssn":"796292881"}' + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - Vets.gov Agent + Authorization: + - removed + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 201 + message: '' + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Date: + - Fri, 11 Mar 2022 21:45:09 GMT + body: + encoding: UTF-8 + string: '' + recorded_at: Fri, 11 Mar 2022 21:45:10 GMT +recorded_with: VCR 6.1.0 diff --git a/spec/support/vcr_cassettes/dgi/polling_with_id_post_claimant_info.yml b/spec/support/vcr_cassettes/dgi/polling_with_id_post_claimant_info.yml new file mode 100644 index 00000000000..ecc33478b92 --- /dev/null +++ b/spec/support/vcr_cassettes/dgi/polling_with_id_post_claimant_info.yml @@ -0,0 +1,35 @@ +--- +http_interactions: +- request: + method: post + uri: https://jenkins.ld.afsp.io:32512/vets-service/v1/claimType/Chapter33/claimants/claimantId + body: + encoding: UTF-8 + string: '{"ssn":"796292881"}' + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - Vets.gov Agent + Authorization: + - removed + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 201 + message: '' + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Date: + - Fri, 11 Mar 2022 21:45:09 GMT + body: + encoding: UTF-8 + string: '{"claimantId":600010259}' + recorded_at: Fri, 11 Mar 2022 21:45:10 GMT +recorded_with: VCR 6.1.0 From 99fb7b063e1924e13081a4a48989fa8728a67bfb Mon Sep 17 00:00:00 2001 From: s-caso Date: Mon, 3 Feb 2025 20:54:19 -0500 Subject: [PATCH 06/15] lint fixes --- modules/meb_api/spec/dgi/claimant/service_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/meb_api/spec/dgi/claimant/service_spec.rb b/modules/meb_api/spec/dgi/claimant/service_spec.rb index 062d0cdae0c..b00b18bf45b 100644 --- a/modules/meb_api/spec/dgi/claimant/service_spec.rb +++ b/modules/meb_api/spec/dgi/claimant/service_spec.rb @@ -33,13 +33,13 @@ before do allow(faraday_response).to receive(:env) end - + context 'with a successful submission and polling for Chapter33' do it 'successfully receives an Claimant object' do VCR.use_cassette('dgi/polling_post_claimant_info') do response = service.get_claimant_info('Chapter33') expect(response.status).to eq(201) - expect(response[:claimant_id]).to eq(nil) + expect(response[:claimant_id]).to be(nil) end end end @@ -49,7 +49,7 @@ VCR.use_cassette('dgi/polling_with_id_post_claimant_info') do response = service.get_claimant_info('Chapter33') expect(response.status).to eq(201) - expect(response[:claimant_id]).to eq("600010259") + expect(response[:claimant_id]).to eq('600010259') end end end From 10895317f878b958346b482460601aaf49914620 Mon Sep 17 00:00:00 2001 From: s-caso Date: Mon, 3 Feb 2025 21:02:23 -0500 Subject: [PATCH 07/15] lint fix --- modules/meb_api/spec/dgi/claimant/service_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/meb_api/spec/dgi/claimant/service_spec.rb b/modules/meb_api/spec/dgi/claimant/service_spec.rb index b00b18bf45b..89c478981b6 100644 --- a/modules/meb_api/spec/dgi/claimant/service_spec.rb +++ b/modules/meb_api/spec/dgi/claimant/service_spec.rb @@ -39,7 +39,7 @@ VCR.use_cassette('dgi/polling_post_claimant_info') do response = service.get_claimant_info('Chapter33') expect(response.status).to eq(201) - expect(response[:claimant_id]).to be(nil) + expect(response[:claimant_id]).to be_nil end end end From 33275b28da8fdba2a0bd13a4b5d79bd2ee6e136c Mon Sep 17 00:00:00 2001 From: AFSMW Date: Wed, 19 Feb 2025 14:38:09 -0500 Subject: [PATCH 08/15] retry claimant id call to avoid race condition --- .../meb_api/v0/forms_controller.rb | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb b/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb index ec27a0f0d64..57b69619d7e 100644 --- a/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb +++ b/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb @@ -36,12 +36,26 @@ def claim_letter def claim_status forms_claimant_response = claimant_service.get_claimant_info(@form_type) claimant_id = forms_claimant_response['claimant_id'] - - claim_status_response = claim_status_service.get_claim_status(params, claimant_id, @form_type) - response = valid_claimant_response?(forms_claimant_response) ? claim_status_response : forms_claimant_response - srlzer = valid_claimant_response?(forms_claimant_response) ? ClaimStatusSerializer : ToeClaimantInfoSerializer - - render json: srlzer.new(response) + max_retries = 5 + retry_count = 0 + base_delay = 0.5 # Start with 500ms delay + begin + if claimant_id.nil? && retry_count < max_retries + retry_count += 1 + delay = base_delay * (2 ** (retry_count - 1)) # Exponential backoff + Rails.logger.info("Claimant ID not found, retry attempt #{retry_count} of #{max_retries} after #{delay}s delay") + sleep(delay) + forms_claimant_response = claimant_service.get_claimant_info(@form_type) + claimant_id = forms_claimant_response['claimant_id'] + end + claim_status_response = claim_status_service.get_claim_status(params, claimant_id, @form_type) + response = valid_claimant_response?(forms_claimant_response) ? claim_status_response : forms_claimant_response + srlzer = valid_claimant_response?(forms_claimant_response) ? ClaimStatusSerializer : ToeClaimantInfoSerializer + render json: srlzer.new(response) + rescue => e + Rails.logger.error("Error in claim_status: #{e.message}") + raise e + end end def claimant_info From 9d25224de63d402dd879b99590030d0dd5134d37 Mon Sep 17 00:00:00 2001 From: AFSMW Date: Wed, 19 Feb 2025 14:54:58 -0500 Subject: [PATCH 09/15] lint fixes --- .../meb_api/app/controllers/meb_api/v0/forms_controller.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb b/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb index 57b69619d7e..11792c11fdc 100644 --- a/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb +++ b/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb @@ -42,8 +42,7 @@ def claim_status begin if claimant_id.nil? && retry_count < max_retries retry_count += 1 - delay = base_delay * (2 ** (retry_count - 1)) # Exponential backoff - Rails.logger.info("Claimant ID not found, retry attempt #{retry_count} of #{max_retries} after #{delay}s delay") + delay = base_delay * (2**(retry_count - 1)) sleep(delay) forms_claimant_response = claimant_service.get_claimant_info(@form_type) claimant_id = forms_claimant_response['claimant_id'] @@ -53,7 +52,6 @@ def claim_status srlzer = valid_claimant_response?(forms_claimant_response) ? ClaimStatusSerializer : ToeClaimantInfoSerializer render json: srlzer.new(response) rescue => e - Rails.logger.error("Error in claim_status: #{e.message}") raise e end end From 64689ed9cbc0e3d53c33c1818158a6d4f2bf9582 Mon Sep 17 00:00:00 2001 From: AFSMW Date: Wed, 19 Feb 2025 15:04:55 -0500 Subject: [PATCH 10/15] remove useless rescue --- modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb b/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb index 11792c11fdc..ee491e00191 100644 --- a/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb +++ b/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb @@ -51,8 +51,6 @@ def claim_status response = valid_claimant_response?(forms_claimant_response) ? claim_status_response : forms_claimant_response srlzer = valid_claimant_response?(forms_claimant_response) ? ClaimStatusSerializer : ToeClaimantInfoSerializer render json: srlzer.new(response) - rescue => e - raise e end end From 5c0b1410862c63b5d035c849e41e0fe880e1c0f1 Mon Sep 17 00:00:00 2001 From: AFSMW Date: Thu, 20 Feb 2025 10:11:27 -0500 Subject: [PATCH 11/15] revert to old code as retry will handle nil case --- modules/meb_api/lib/dgi/claimant/claimant_response.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/meb_api/lib/dgi/claimant/claimant_response.rb b/modules/meb_api/lib/dgi/claimant/claimant_response.rb index 514e4ed0f45..22aef2e583f 100644 --- a/modules/meb_api/lib/dgi/claimant/claimant_response.rb +++ b/modules/meb_api/lib/dgi/claimant/claimant_response.rb @@ -10,7 +10,7 @@ class ClaimantResponse < MebApi::DGI::Response def initialize(status, response = nil) attributes = { - claimant_id: response&.body.respond_to?(:fetch) ? response&.body&.fetch('claimant_id', nil) : response&.body + claimant_id: response&.body&.fetch('claimant_id', nil) } super(status, attributes) end From be7d700da1a56a8f42c3f36c4e300f75fa72b5e7 Mon Sep 17 00:00:00 2001 From: AFSMW Date: Thu, 20 Feb 2025 15:51:31 -0500 Subject: [PATCH 12/15] refactor claim status endpoint and add spec --- .../meb_api/v0/forms_controller.rb | 15 ++--- .../lib/dgi/claimant/claimant_response.rb | 2 +- .../spec/requests/meb_api/v0/forms_spec.rb | 13 ++++ .../dgi/polling_with_race_condition.yml | 67 +++++++++++++++++++ 4 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 spec/support/vcr_cassettes/dgi/polling_with_race_condition.yml diff --git a/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb b/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb index ee491e00191..88358fa7259 100644 --- a/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb +++ b/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb @@ -36,21 +36,14 @@ def claim_letter def claim_status forms_claimant_response = claimant_service.get_claimant_info(@form_type) claimant_id = forms_claimant_response['claimant_id'] - max_retries = 5 - retry_count = 0 - base_delay = 0.5 # Start with 500ms delay - begin - if claimant_id.nil? && retry_count < max_retries - retry_count += 1 - delay = base_delay * (2**(retry_count - 1)) - sleep(delay) - forms_claimant_response = claimant_service.get_claimant_info(@form_type) - claimant_id = forms_claimant_response['claimant_id'] - end + + if claimant_id.present? claim_status_response = claim_status_service.get_claim_status(params, claimant_id, @form_type) response = valid_claimant_response?(forms_claimant_response) ? claim_status_response : forms_claimant_response srlzer = valid_claimant_response?(forms_claimant_response) ? ClaimStatusSerializer : ToeClaimantInfoSerializer render json: srlzer.new(response) + else + render json: { data: { attributes: { claimStatus: "INPROGRESS" } } }, status: :ok end end diff --git a/modules/meb_api/lib/dgi/claimant/claimant_response.rb b/modules/meb_api/lib/dgi/claimant/claimant_response.rb index 22aef2e583f..514e4ed0f45 100644 --- a/modules/meb_api/lib/dgi/claimant/claimant_response.rb +++ b/modules/meb_api/lib/dgi/claimant/claimant_response.rb @@ -10,7 +10,7 @@ class ClaimantResponse < MebApi::DGI::Response def initialize(status, response = nil) attributes = { - claimant_id: response&.body&.fetch('claimant_id', nil) + claimant_id: response&.body.respond_to?(:fetch) ? response&.body&.fetch('claimant_id', nil) : response&.body } super(status, attributes) end diff --git a/modules/meb_api/spec/requests/meb_api/v0/forms_spec.rb b/modules/meb_api/spec/requests/meb_api/v0/forms_spec.rb index 957adcfb11f..3b60626bbc6 100644 --- a/modules/meb_api/spec/requests/meb_api/v0/forms_spec.rb +++ b/modules/meb_api/spec/requests/meb_api/v0/forms_spec.rb @@ -78,6 +78,19 @@ end end + describe 'GET /meb_api/v0/forms_claim_status' do + context 'when polling for a claimant id' do + it 'handles a request when the claimant has not been created yet' do + VCR.use_cassette('dgi/polling_with_race_condition') do + get '/meb_api/v0/forms_claim_status', params: { type: 'ToeSubmission' } + expect(response).to have_http_status(:ok) + expect(JSON.parse(response.body)["data"]["attributes"]["claimStatus"]).to eq("INPROGRESS") + expect(response).to match_response_schema('dgi/toe_claimant_info_response', { strict: false }) + end + end + end + end + describe 'POST /meb_api/v0/forms_send_confirmation_email' do context 'when the feature flag is enabled' do it 'sends the confirmation email with provided name and email params' do diff --git a/spec/support/vcr_cassettes/dgi/polling_with_race_condition.yml b/spec/support/vcr_cassettes/dgi/polling_with_race_condition.yml new file mode 100644 index 00000000000..847c7d22359 --- /dev/null +++ b/spec/support/vcr_cassettes/dgi/polling_with_race_condition.yml @@ -0,0 +1,67 @@ +--- +http_interactions: +- request: + method: post + uri: https://jenkins.ld.afsp.io:32512/vets-service/v1/claimType/Toe/claimants/claimantId + body: + encoding: UTF-8 + string: '{"ssn":"796292881"}' + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - Vets.gov Agent + Authorization: + - removed + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 201 + message: '' + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Date: + - Fri, 11 Mar 2022 21:45:09 GMT + body: + encoding: UTF-8 + string: '{}' + recorded_at: Fri, 11 Mar 2022 21:45:10 GMT +- request: + method: post + uri: https://jenkins.ld.afsp.io:32512/vets-service/v1/claimType/Toe/claimants/claimantId + body: + encoding: UTF-8 + string: '{"ssn":"796292881"}' + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - Vets.gov Agent + Authorization: + - removed + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 201 + message: '' + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Date: + - Fri, 11 Mar 2022 21:45:09 GMT + body: + encoding: UTF-8 + string: '{"claimantId":600010259}' + recorded_at: Fri, 11 Mar 2022 21:45:10 GMT +recorded_with: VCR 6.1.0 From f9061e9c1f7d8eb39cb21e50bfb4af9a4e93641b Mon Sep 17 00:00:00 2001 From: AFSMW Date: Thu, 20 Feb 2025 16:38:02 -0500 Subject: [PATCH 13/15] add spec --- .../meb_api/v0/forms_controller.rb | 4 +- .../spec/requests/meb_api/v0/forms_spec.rb | 9 ++- .../dgi/polling_without_race_condition.yml | 67 +++++++++++++++++++ 3 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 spec/support/vcr_cassettes/dgi/polling_without_race_condition.yml diff --git a/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb b/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb index 88358fa7259..bdd0aef4732 100644 --- a/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb +++ b/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb @@ -40,8 +40,8 @@ def claim_status if claimant_id.present? claim_status_response = claim_status_service.get_claim_status(params, claimant_id, @form_type) response = valid_claimant_response?(forms_claimant_response) ? claim_status_response : forms_claimant_response - srlzer = valid_claimant_response?(forms_claimant_response) ? ClaimStatusSerializer : ToeClaimantInfoSerializer - render json: srlzer.new(response) + serializer = valid_claimant_response?(forms_claimant_response) ? ClaimStatusSerializer : ToeClaimantInfoSerializer + render json: serializer.new(response) else render json: { data: { attributes: { claimStatus: "INPROGRESS" } } }, status: :ok end diff --git a/modules/meb_api/spec/requests/meb_api/v0/forms_spec.rb b/modules/meb_api/spec/requests/meb_api/v0/forms_spec.rb index 3b60626bbc6..029bc438506 100644 --- a/modules/meb_api/spec/requests/meb_api/v0/forms_spec.rb +++ b/modules/meb_api/spec/requests/meb_api/v0/forms_spec.rb @@ -85,7 +85,14 @@ get '/meb_api/v0/forms_claim_status', params: { type: 'ToeSubmission' } expect(response).to have_http_status(:ok) expect(JSON.parse(response.body)["data"]["attributes"]["claimStatus"]).to eq("INPROGRESS") - expect(response).to match_response_schema('dgi/toe_claimant_info_response', { strict: false }) + end + end + + it 'handles a request when the claimant has been created' do + VCR.use_cassette('dgi/polling_without_race_condition') do + get '/meb_api/v0/forms_claim_status', params: { type: 'ToeSubmission' } + expect(response).to have_http_status(:ok) + expect(JSON.parse(response.body)["data"]["attributes"]["claimant_id"]).to eq(600000001) end end end diff --git a/spec/support/vcr_cassettes/dgi/polling_without_race_condition.yml b/spec/support/vcr_cassettes/dgi/polling_without_race_condition.yml new file mode 100644 index 00000000000..ed846c84657 --- /dev/null +++ b/spec/support/vcr_cassettes/dgi/polling_without_race_condition.yml @@ -0,0 +1,67 @@ +--- +http_interactions: +- request: + method: post + uri: https://jenkins.ld.afsp.io:32512/vets-service/v1/claimType/Toe/claimants/claimantId + body: + encoding: UTF-8 + string: '{"ssn":"796121200"}' + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - Vets.gov Agent + Authorization: + - removed + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 201 + message: '' + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Date: + - Wed, 15 Jun 2022 18:42:37 GMT + body: + encoding: UTF-8 + string: '{"claimantId":600000001}' + recorded_at: Wed, 15 Jun 2022 18:42:36 GMT +- request: + method: get + uri: https://jenkins.ld.afsp.io:32512/vets-service/v1/claimant/600000001/claimType/toe/claimstatus?latest=false + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - Vets.gov Agent + Authorization: + - removed + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: '' + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Date: + - Wed, 15 Jun 2022 18:42:37 GMT + body: + encoding: UTF-8 + string: '{"claimantId":600000001,"claimServiceId":99000000113358369,"claimStatus":"IN_PROGRESS","confirmationNumber":null,"receivedDate":"2022-06-13"}' + recorded_at: Thu, 07 Sep 2023 19:36:00 GMT +recorded_with: VCR 6.1.0 From aabf01a43342d8f1b7f18f37a72ac1333581f5cb Mon Sep 17 00:00:00 2001 From: AFSMW Date: Thu, 20 Feb 2025 16:46:28 -0500 Subject: [PATCH 14/15] lint fixes --- .../app/controllers/meb_api/v0/forms_controller.rb | 9 +++++++-- modules/meb_api/spec/requests/meb_api/v0/forms_spec.rb | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb b/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb index bdd0aef4732..5ea39f9e5c2 100644 --- a/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb +++ b/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb @@ -36,11 +36,16 @@ def claim_letter def claim_status forms_claimant_response = claimant_service.get_claimant_info(@form_type) claimant_id = forms_claimant_response['claimant_id'] - + if claimant_id.present? claim_status_response = claim_status_service.get_claim_status(params, claimant_id, @form_type) response = valid_claimant_response?(forms_claimant_response) ? claim_status_response : forms_claimant_response - serializer = valid_claimant_response?(forms_claimant_response) ? ClaimStatusSerializer : ToeClaimantInfoSerializer + serializer = if valid_claimant_response?(forms_claimant_response) + ClaimStatusSerializer + else + ToeClaimantInfoSerializer + end + render json: serializer.new(response) else render json: { data: { attributes: { claimStatus: "INPROGRESS" } } }, status: :ok diff --git a/modules/meb_api/spec/requests/meb_api/v0/forms_spec.rb b/modules/meb_api/spec/requests/meb_api/v0/forms_spec.rb index 029bc438506..376703ed8a8 100644 --- a/modules/meb_api/spec/requests/meb_api/v0/forms_spec.rb +++ b/modules/meb_api/spec/requests/meb_api/v0/forms_spec.rb @@ -51,7 +51,7 @@ # context 'Retrieves sponsors for FryDea' do # it 'returns a 200 status' do # VCR.use_cassette('dgi/forms/sponsor_fry_dea') do - # post '/meb_api/v0/forms_sponsors', params: { "form_type": 'FryDea' } + # post '/meb_api/v0/forms_sponsors', params: { 'form_type': 'FryDea' } # expect(response).to have_http_status(:ok) # end # end @@ -84,7 +84,7 @@ VCR.use_cassette('dgi/polling_with_race_condition') do get '/meb_api/v0/forms_claim_status', params: { type: 'ToeSubmission' } expect(response).to have_http_status(:ok) - expect(JSON.parse(response.body)["data"]["attributes"]["claimStatus"]).to eq("INPROGRESS") + expect(JSON.parse(response.body)['data']['attributes']['claimStatus']).to eq('INPROGRESS') end end @@ -92,7 +92,7 @@ VCR.use_cassette('dgi/polling_without_race_condition') do get '/meb_api/v0/forms_claim_status', params: { type: 'ToeSubmission' } expect(response).to have_http_status(:ok) - expect(JSON.parse(response.body)["data"]["attributes"]["claimant_id"]).to eq(600000001) + expect(JSON.parse(response.body)['data']['attributes']['claimant_id']).to eq(600000001) end end end From e6e8eb9f08a2e2d49b0e95da8970abcd521cd187 Mon Sep 17 00:00:00 2001 From: AFSMW Date: Thu, 20 Feb 2025 17:02:57 -0500 Subject: [PATCH 15/15] lint fixes --- .../app/controllers/meb_api/v0/forms_controller.rb | 10 +++------- modules/meb_api/spec/requests/meb_api/v0/forms_spec.rb | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb b/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb index 5ea39f9e5c2..f3622034ea5 100644 --- a/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb +++ b/modules/meb_api/app/controllers/meb_api/v0/forms_controller.rb @@ -40,15 +40,11 @@ def claim_status if claimant_id.present? claim_status_response = claim_status_service.get_claim_status(params, claimant_id, @form_type) response = valid_claimant_response?(forms_claimant_response) ? claim_status_response : forms_claimant_response - serializer = if valid_claimant_response?(forms_claimant_response) - ClaimStatusSerializer - else - ToeClaimantInfoSerializer - end + srlzr = valid_claimant_response?(forms_claimant_response) ? ClaimStatusSerializer : ToeClaimantInfoSerializer - render json: serializer.new(response) + render json: srlzr.new(response) else - render json: { data: { attributes: { claimStatus: "INPROGRESS" } } }, status: :ok + render json: { data: { attributes: { claimStatus: 'INPROGRESS' } } }, status: :ok end end diff --git a/modules/meb_api/spec/requests/meb_api/v0/forms_spec.rb b/modules/meb_api/spec/requests/meb_api/v0/forms_spec.rb index 376703ed8a8..7a78d1f4307 100644 --- a/modules/meb_api/spec/requests/meb_api/v0/forms_spec.rb +++ b/modules/meb_api/spec/requests/meb_api/v0/forms_spec.rb @@ -92,7 +92,7 @@ VCR.use_cassette('dgi/polling_without_race_condition') do get '/meb_api/v0/forms_claim_status', params: { type: 'ToeSubmission' } expect(response).to have_http_status(:ok) - expect(JSON.parse(response.body)['data']['attributes']['claimant_id']).to eq(600000001) + expect(JSON.parse(response.body)['data']['attributes']['claimant_id']).to eq(600_000_001) end end end