diff --git a/lib/vet360/address_validation/address_suggestions_response.rb b/lib/vet360/address_validation/address_suggestions_response.rb index a7ead273b56..8efe6082a95 100644 --- a/lib/vet360/address_validation/address_suggestions_response.rb +++ b/lib/vet360/address_validation/address_suggestions_response.rb @@ -3,7 +3,9 @@ module Vet360 module AddressValidation class AddressSuggestionsResponse - def initialize(candidate_res, validation_key) + def initialize(candidate_res) + validation_key = candidate_res['candidate_addresses'][0]['address_meta_data']['validation_key'] + @response = { addresses: candidate_res['candidate_addresses'].map do |address_suggestion_hash| { diff --git a/lib/vet360/address_validation/service.rb b/lib/vet360/address_validation/service.rb index 21e8205bbe6..b806c0ab90a 100644 --- a/lib/vet360/address_validation/service.rb +++ b/lib/vet360/address_validation/service.rb @@ -8,11 +8,9 @@ class Service < Vet360::Service def initialize; end def address_suggestions(address) - validate_res = validate(address) - validation_key = validate_res['address_meta_data']['validation_key'] candidate_res = candidate(address) - AddressSuggestionsResponse.new(candidate_res, validation_key) + AddressSuggestionsResponse.new(candidate_res) end %w[validate candidate].each do |endpoint| diff --git a/spec/controllers/v0/profile/address_validation_controller_spec.rb b/spec/controllers/v0/profile/address_validation_controller_spec.rb index 1081a9374c8..53b07bb7b42 100644 --- a/spec/controllers/v0/profile/address_validation_controller_spec.rb +++ b/spec/controllers/v0/profile/address_validation_controller_spec.rb @@ -64,60 +64,55 @@ context 'with a found address' do it 'returns suggested addresses for a given address' do VCR.use_cassette( - 'vet360/address_validation/validate_match', + 'vet360/address_validation/candidate_multiple_matches', VCR::MATCH_EVERYTHING ) do - VCR.use_cassette( - 'vet360/address_validation/candidate_multiple_matches', - VCR::MATCH_EVERYTHING - ) do - post(:create, params: { address: multiple_match_addr.to_h }) - expect(JSON.parse(response.body)).to eq( - 'addresses' => [ - { - 'address' => { - 'address_line1' => '37 N 1st St', - 'address_type' => 'DOMESTIC', - 'city' => 'Brooklyn', - 'country_name' => 'United States', - 'country_code_iso3' => 'USA', - 'county_code' => '36047', - 'county_name' => 'Kings', - 'state_code' => 'NY', - 'zip_code' => '11249', - 'zip_code_suffix' => '3939' - }, - 'address_meta_data' => { - 'confidence_score' => 100.0, - 'address_type' => 'Domestic', - 'delivery_point_validation' => 'UNDELIVERABLE' - } + post(:create, params: { address: multiple_match_addr.to_h }) + expect(JSON.parse(response.body)).to eq( + 'addresses' => [ + { + 'address' => { + 'address_line1' => '37 N 1st St', + 'address_type' => 'DOMESTIC', + 'city' => 'Brooklyn', + 'country_name' => 'United States', + 'country_code_iso3' => 'USA', + 'county_code' => '36047', + 'county_name' => 'Kings', + 'state_code' => 'NY', + 'zip_code' => '11249', + 'zip_code_suffix' => '3939' }, - { - 'address' => { - 'address_line1' => '37 S 1st St', - 'address_type' => 'DOMESTIC', - 'city' => 'Brooklyn', - 'country_name' => 'United States', - 'country_code_iso3' => 'USA', - 'county_code' => '36047', - 'county_name' => 'Kings', - 'state_code' => 'NY', - 'zip_code' => '11249', - 'zip_code_suffix' => '4101' - }, - 'address_meta_data' => { - 'confidence_score' => 100.0, - 'address_type' => 'Domestic', - 'delivery_point_validation' => 'CONFIRMED', - 'residential_delivery_indicator' => 'MIXED' - } + 'address_meta_data' => { + 'confidence_score' => 100.0, + 'address_type' => 'Domestic', + 'delivery_point_validation' => 'UNDELIVERABLE' } - ], - 'validation_key' => -646_932_106 - ) - expect(response.status).to eq(200) - end + }, + { + 'address' => { + 'address_line1' => '37 S 1st St', + 'address_type' => 'DOMESTIC', + 'city' => 'Brooklyn', + 'country_name' => 'United States', + 'country_code_iso3' => 'USA', + 'county_code' => '36047', + 'county_name' => 'Kings', + 'state_code' => 'NY', + 'zip_code' => '11249', + 'zip_code_suffix' => '4101' + }, + 'address_meta_data' => { + 'confidence_score' => 100.0, + 'address_type' => 'Domestic', + 'delivery_point_validation' => 'CONFIRMED', + 'residential_delivery_indicator' => 'MIXED' + } + } + ], + 'validation_key' => -646_932_106 + ) + expect(response.status).to eq(200) end end end diff --git a/spec/lib/vet360/address_validation/service_spec.rb b/spec/lib/vet360/address_validation/service_spec.rb index 671e4f88f15..e0b26349de6 100644 --- a/spec/lib/vet360/address_validation/service_spec.rb +++ b/spec/lib/vet360/address_validation/service_spec.rb @@ -30,59 +30,54 @@ context 'with a found address' do it 'returns suggested addresses' do VCR.use_cassette( - 'vet360/address_validation/validate_match', + 'vet360/address_validation/candidate_multiple_matches', VCR::MATCH_EVERYTHING ) do - VCR.use_cassette( - 'vet360/address_validation/candidate_multiple_matches', - VCR::MATCH_EVERYTHING - ) do - res = described_class.new.address_suggestions(multiple_match_addr) - expect(JSON.parse(res.to_json)).to eq( - 'addresses' => [ - { - 'address' => { - 'address_line1' => '37 N 1st St', - 'address_type' => 'DOMESTIC', - 'city' => 'Brooklyn', - 'country_name' => 'United States', - 'country_code_iso3' => 'USA', - 'county_code' => '36047', - 'county_name' => 'Kings', - 'state_code' => 'NY', - 'zip_code' => '11249', - 'zip_code_suffix' => '3939' - }, - 'address_meta_data' => { - 'confidence_score' => 100.0, - 'address_type' => 'Domestic', - 'delivery_point_validation' => 'UNDELIVERABLE' - } + res = described_class.new.address_suggestions(multiple_match_addr) + expect(JSON.parse(res.to_json)).to eq( + 'addresses' => [ + { + 'address' => { + 'address_line1' => '37 N 1st St', + 'address_type' => 'DOMESTIC', + 'city' => 'Brooklyn', + 'country_name' => 'United States', + 'country_code_iso3' => 'USA', + 'county_code' => '36047', + 'county_name' => 'Kings', + 'state_code' => 'NY', + 'zip_code' => '11249', + 'zip_code_suffix' => '3939' }, - { - 'address' => { - 'address_line1' => '37 S 1st St', - 'address_type' => 'DOMESTIC', - 'city' => 'Brooklyn', - 'country_name' => 'United States', - 'country_code_iso3' => 'USA', - 'county_code' => '36047', - 'county_name' => 'Kings', - 'state_code' => 'NY', - 'zip_code' => '11249', - 'zip_code_suffix' => '4101' - }, - 'address_meta_data' => { - 'confidence_score' => 100.0, - 'address_type' => 'Domestic', - 'delivery_point_validation' => 'CONFIRMED', - 'residential_delivery_indicator' => 'MIXED' - } + 'address_meta_data' => { + 'confidence_score' => 100.0, + 'address_type' => 'Domestic', + 'delivery_point_validation' => 'UNDELIVERABLE' } - ], - 'validation_key' => -646_932_106 - ) - end + }, + { + 'address' => { + 'address_line1' => '37 S 1st St', + 'address_type' => 'DOMESTIC', + 'city' => 'Brooklyn', + 'country_name' => 'United States', + 'country_code_iso3' => 'USA', + 'county_code' => '36047', + 'county_name' => 'Kings', + 'state_code' => 'NY', + 'zip_code' => '11249', + 'zip_code_suffix' => '4101' + }, + 'address_meta_data' => { + 'confidence_score' => 100.0, + 'address_type' => 'Domestic', + 'delivery_point_validation' => 'CONFIRMED', + 'residential_delivery_indicator' => 'MIXED' + } + } + ], + 'validation_key' => -646_932_106 + ) end end end