Skip to content

Commit

Permalink
use only candidate api for address validation api (#3642)
Browse files Browse the repository at this point in the history
* add validation address model

* add validation addres factory

* update cassettes

* lint

* lint

* dry base address validations

* update address valid swagger

* require address pou only in address request

* just use candidate in address_suggestions method

* remove validate vcr from av controller spec

* format hash

* fix hashes
  • Loading branch information
lihanli authored Dec 16, 2019
1 parent 47a42ee commit e5443c4
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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|
{
Expand Down
4 changes: 1 addition & 3 deletions lib/vet360/address_validation/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
95 changes: 45 additions & 50 deletions spec/controllers/v0/profile/address_validation_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
93 changes: 44 additions & 49 deletions spec/lib/vet360/address_validation/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e5443c4

Please sign in to comment.