From 13c06443fd5c44f1ea8dc02247c2f0b7b267e7a2 Mon Sep 17 00:00:00 2001 From: Derek Houck <12766168+derekhouck@users.noreply.github.com> Date: Tue, 7 Jan 2025 10:35:14 -0600 Subject: [PATCH] 93461: Add #zip_code_is_us_based to VBA214140 (#20062) Adds #zip_code_is_us_based to the VBA214140 model. --- .../models/simple_forms_api/vba_21_4140.rb | 14 ++-- .../spec/models/vba_20_10207_spec.rb | 45 +------------ .../spec/models/vba_21_0845_spec.rb | 65 +------------------ .../spec/models/vba_21_0966_spec.rb | 47 +------------- .../spec/models/vba_21_4140_spec.rb | 3 + .../spec/models/vba_40_0247_spec.rb | 5 +- .../simple_forms_api/v1/simple_forms_spec.rb | 4 +- .../support/shared_examples_for_base_form.rb | 31 +++++++++ 8 files changed, 56 insertions(+), 158 deletions(-) create mode 100644 modules/simple_forms_api/spec/support/shared_examples_for_base_form.rb diff --git a/modules/simple_forms_api/app/models/simple_forms_api/vba_21_4140.rb b/modules/simple_forms_api/app/models/simple_forms_api/vba_21_4140.rb index b561f722623..e8947a26d73 100644 --- a/modules/simple_forms_api/app/models/simple_forms_api/vba_21_4140.rb +++ b/modules/simple_forms_api/app/models/simple_forms_api/vba_21_4140.rb @@ -8,12 +8,12 @@ def desired_stamps def metadata { - 'veteranFirstName' => @data.dig('full_name', 'first'), - 'veteranLastName' => @data.dig('full_name', 'last'), - 'fileNumber' => @data['va_file_number'].presence || @data['ssn'], - 'zipCode' => @data.dig('address', 'postal_code'), + 'veteranFirstName' => data.dig('full_name', 'first'), + 'veteranLastName' => data.dig('full_name', 'last'), + 'fileNumber' => data['va_file_number'].presence || data['ssn'], + 'zipCode' => data.dig('address', 'postal_code'), 'source' => 'VA Platform Digital Forms', - 'docType' => @data['form_number'], + 'docType' => data['form_number'], 'businessLine' => 'CMP' } end @@ -21,5 +21,9 @@ def metadata def submission_date_stamps(_timestamp) [] end + + def zip_code_is_us_based + data.dig('address', 'country') == 'USA' + end end end diff --git a/modules/simple_forms_api/spec/models/vba_20_10207_spec.rb b/modules/simple_forms_api/spec/models/vba_20_10207_spec.rb index 479e0ab5860..0b5c516af6d 100644 --- a/modules/simple_forms_api/spec/models/vba_20_10207_spec.rb +++ b/modules/simple_forms_api/spec/models/vba_20_10207_spec.rb @@ -1,51 +1,10 @@ # frozen_string_literal: true require 'rails_helper' +require_relative '../support/shared_examples_for_base_form' RSpec.describe SimpleFormsApi::VBA2010207 do - describe 'zip_code_is_us_based' do - subject(:zip_code_is_us_based) { described_class.new(data).zip_code_is_us_based } - - context 'veteran address is present and in US' do - let(:data) { { 'veteran_mailing_address' => { 'country' => 'USA' } } } - - it 'returns true' do - expect(zip_code_is_us_based).to eq(true) - end - end - - context 'veteran address is present and not in US' do - let(:data) { { 'veteran_mailing_address' => { 'country' => 'Canada' } } } - - it 'returns false' do - expect(zip_code_is_us_based).to eq(false) - end - end - - context 'non-veteran address is present and in US' do - let(:data) { { 'non_veteran_mailing_address' => { 'country' => 'USA' } } } - - it 'returns true' do - expect(zip_code_is_us_based).to eq(true) - end - end - - context 'non-veteran address is present and not in US' do - let(:data) { { 'non_veteran_mailing_address' => { 'country' => 'Canada' } } } - - it 'returns false' do - expect(zip_code_is_us_based).to eq(false) - end - end - - context 'no valid address is given' do - let(:data) { {} } - - it 'returns false' do - expect(zip_code_is_us_based).to eq(false) - end - end - end + it_behaves_like 'zip_code_is_us_based', %w[veteran_mailing_address non_veteran_mailing_address] describe 'requester_signature' do statement_of_truth_signature = 'John Veteran' diff --git a/modules/simple_forms_api/spec/models/vba_21_0845_spec.rb b/modules/simple_forms_api/spec/models/vba_21_0845_spec.rb index a722ae6a026..e540f4133ee 100644 --- a/modules/simple_forms_api/spec/models/vba_21_0845_spec.rb +++ b/modules/simple_forms_api/spec/models/vba_21_0845_spec.rb @@ -1,69 +1,8 @@ # frozen_string_literal: true require 'rails_helper' +require_relative '../support/shared_examples_for_base_form' RSpec.describe SimpleFormsApi::VBA210845 do - describe 'zip_code_is_us_based' do - subject(:zip_code_is_us_based) { described_class.new(data).zip_code_is_us_based } - - context 'authorizer address is present and in US' do - let(:data) { { 'authorizer_address' => { 'country' => 'USA' } } } - - it 'returns true' do - expect(zip_code_is_us_based).to eq(true) - end - end - - context 'authorizer address is present and not in US' do - let(:data) { { 'authorizer_address' => { 'country' => 'Canada' } } } - - it 'returns false' do - expect(zip_code_is_us_based).to eq(false) - end - end - - context 'person is present and in US' do - let(:data) { { 'person_address' => { 'country' => 'USA' } } } - - it 'returns true' do - expect(zip_code_is_us_based).to eq(true) - end - end - - context 'person is present and not in US' do - let(:data) { { 'person_address' => { 'country' => 'Canada' } } } - - it 'returns false' do - expect(zip_code_is_us_based).to eq(false) - end - end - - context 'organization is present and in US' do - let(:data) do - { 'organization_address' => { 'country' => 'USA' } } - end - - it 'returns true' do - expect(zip_code_is_us_based).to eq(true) - end - end - - context 'organization is present and not in US' do - let(:data) do - { 'organization_address' => { 'country' => 'Canada' } } - end - - it 'returns false' do - expect(zip_code_is_us_based).to eq(false) - end - end - - context 'no valid address is given' do - let(:data) { {} } - - it 'returns false' do - expect(zip_code_is_us_based).to eq(false) - end - end - end + it_behaves_like 'zip_code_is_us_based', %w[authorizer_address person_address organization_address] end diff --git a/modules/simple_forms_api/spec/models/vba_21_0966_spec.rb b/modules/simple_forms_api/spec/models/vba_21_0966_spec.rb index 50eac06d0f9..f3fff43a0e6 100644 --- a/modules/simple_forms_api/spec/models/vba_21_0966_spec.rb +++ b/modules/simple_forms_api/spec/models/vba_21_0966_spec.rb @@ -1,8 +1,11 @@ # frozen_string_literal: true require 'rails_helper' +require_relative '../support/shared_examples_for_base_form' RSpec.describe SimpleFormsApi::VBA210966 do + it_behaves_like 'zip_code_is_us_based', %w[veteran_mailing_address surviving_dependent_mailing_address] + describe 'populate_veteran_data' do context 'data does not already have what it needs' do let(:expected_first_name) { 'Rory' } @@ -50,48 +53,4 @@ end end end - - describe 'zip_code_is_us_based' do - subject(:zip_code_is_us_based) { described_class.new(data).zip_code_is_us_based } - - context 'veteran address is present and in US' do - let(:data) { { 'veteran_mailing_address' => { 'country' => 'USA' } } } - - it 'returns true' do - expect(zip_code_is_us_based).to eq(true) - end - end - - context 'veteran address is present and not in US' do - let(:data) { { 'veteran_mailing_address' => { 'country' => 'Canada' } } } - - it 'returns false' do - expect(zip_code_is_us_based).to eq(false) - end - end - - context 'surviving dependent is present and in US' do - let(:data) { { 'surviving_dependent_mailing_address' => { 'country' => 'USA' } } } - - it 'returns true' do - expect(zip_code_is_us_based).to eq(true) - end - end - - context 'surviving dependent is present and not in US' do - let(:data) { { 'surviving_dependent_mailing_address' => { 'country' => 'Canada' } } } - - it 'returns false' do - expect(zip_code_is_us_based).to eq(false) - end - end - - context 'no valid address is given' do - let(:data) { {} } - - it 'returns false' do - expect(zip_code_is_us_based).to eq(false) - end - end - end end diff --git a/modules/simple_forms_api/spec/models/vba_21_4140_spec.rb b/modules/simple_forms_api/spec/models/vba_21_4140_spec.rb index fd1ae0dd716..db23f321e95 100644 --- a/modules/simple_forms_api/spec/models/vba_21_4140_spec.rb +++ b/modules/simple_forms_api/spec/models/vba_21_4140_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'rails_helper' +require_relative '../support/shared_examples_for_base_form' RSpec.describe SimpleFormsApi::VBA214140 do subject(:form) { described_class.new(data) } @@ -10,6 +11,8 @@ end let(:data) { JSON.parse(fixture_path.read) } + it_behaves_like 'zip_code_is_us_based', %w[address] + describe '#data' do subject { form.data } diff --git a/modules/simple_forms_api/spec/models/vba_40_0247_spec.rb b/modules/simple_forms_api/spec/models/vba_40_0247_spec.rb index 4d1707420c0..003f87c52d5 100644 --- a/modules/simple_forms_api/spec/models/vba_40_0247_spec.rb +++ b/modules/simple_forms_api/spec/models/vba_40_0247_spec.rb @@ -1,8 +1,11 @@ # frozen_string_literal: true require 'rails_helper' +require_relative '../support/shared_examples_for_base_form' + +RSpec.describe SimpleFormsApi::VBA400247 do + it_behaves_like 'zip_code_is_us_based', %w[applicant_address] -RSpec.describe 'SimpleFormsApi::VBA400247' do describe 'handle_attachments' do it 'saves the combined pdf' do original_pdf = double('HexaPDF::Document') diff --git a/modules/simple_forms_api/spec/requests/simple_forms_api/v1/simple_forms_spec.rb b/modules/simple_forms_api/spec/requests/simple_forms_api/v1/simple_forms_spec.rb index d84d1e08c6c..a7aae4ed345 100644 --- a/modules/simple_forms_api/spec/requests/simple_forms_api/v1/simple_forms_spec.rb +++ b/modules/simple_forms_api/spec/requests/simple_forms_api/v1/simple_forms_spec.rb @@ -117,13 +117,13 @@ describe 'unauthenticated forms' do unauthenticated_forms.each do |form| - include_examples 'form submission', form, false + it_behaves_like 'form submission', form, false end end describe 'authenticated forms' do authenticated_forms.each do |form| - include_examples 'form submission', form, true + it_behaves_like 'form submission', form, true end end diff --git a/modules/simple_forms_api/spec/support/shared_examples_for_base_form.rb b/modules/simple_forms_api/spec/support/shared_examples_for_base_form.rb new file mode 100644 index 00000000000..a85f3c5680e --- /dev/null +++ b/modules/simple_forms_api/spec/support/shared_examples_for_base_form.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'zip_code_is_us_based' do |address_keys| + subject(:zip_code_is_us_based) { described_class.new(data).zip_code_is_us_based } + + address_keys.each do |address_key| + context 'address is present and in US' do + let(:data) { { address_key => { 'country' => 'USA' } } } + + it 'returns true' do + expect(zip_code_is_us_based).to eq(true) + end + end + + context 'address is present and not in US' do + let(:data) { { address_key => { 'country' => 'Canada' } } } + + it 'returns false' do + expect(zip_code_is_us_based).to eq(false) + end + end + end + + context 'no valid address is given' do + let(:data) { {} } + + it 'returns false' do + expect(zip_code_is_us_based).to eq(false) + end + end +end