Skip to content

Commit

Permalink
- Fix address verification unit tests (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwithan8 authored Jan 8, 2024
1 parent 99d65fb commit 9346186
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 111 deletions.
2 changes: 1 addition & 1 deletion examples
Submodule examples updated 742 files
47 changes: 32 additions & 15 deletions spec/address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@
end

it 'creates an address with verify param' do
# We purposefully pass in slightly incorrect data to get the corrected address back once verified.
address_data = Fixture.incorrect_address
address_data[:verify] = true

# Creating normally (without specifying "verify") will make the address, perform no verifications
address = client.address.create(address_data)

expect(address).to be_an_instance_of(EasyPost::Models::Address)
expect(address.id).to match('adr_')
expect(address.street1).to eq('417 MONTGOMERY ST FL 5')
expect(address.verifications.zip4.errors[0].message).to eq('Invalid secondary information(Apt/Suite#)')
expect(address.verifications.instance_variable_defined?(:@delivery)).to be false

# Creating with verify = true will make the address, perform verifications
address_data[:verify] = true
address = client.address.create(address_data)

expect(address).to be_an_instance_of(EasyPost::Models::Address)
expect(address.verifications.delivery.success).to be false
end

it 'creates an address with verify_strict param' do
Expand All @@ -39,16 +43,20 @@
end

it 'creates an address with an array verify param' do
# We purposefully pass in slightly incorrect data to get the corrected address back once verified.
address_data = Fixture.incorrect_address
address_data[:verify] = [true]

# Creating normally (without specifying "verify") will make the address, perform no verifications
address = client.address.create(address_data)

expect(address).to be_an_instance_of(EasyPost::Models::Address)
expect(address.id).to match('adr_')
expect(address.street1).to eq('417 MONTGOMERY ST FL 5')
expect(address.verifications.zip4.errors[0].message).to eq('Invalid secondary information(Apt/Suite#)')
expect(address.verifications.instance_variable_defined?(:@delivery)).to be false

# Creating with verify = true will make the address, perform verifications
address_data[:verify] = [true]
address = client.address.create(address_data)

expect(address).to be_an_instance_of(EasyPost::Models::Address)
expect(address.verifications.delivery.success).to be false
end
end

Expand Down Expand Up @@ -104,24 +112,33 @@

describe '.create_and_verify' do
it 'creates a verified address' do
# We purposefully pass in slightly incorrect data to get the corrected address back once verified.
address = client.address.create_and_verify(Fixture.incorrect_address)
address = client.address.create_and_verify(Fixture.ca_address1)

expect(address).to be_an_instance_of(EasyPost::Models::Address)
expect(address.id).to match('adr_')
expect(address.street1).to eq('417 MONTGOMERY ST FL 5')
expect(address.street1).to eq('388 TOWNSEND ST APT 20')
end

it 'throws an error for invalid address verification' do
address_data = Fixture.incorrect_address

# Creates with verify = true behind the scenes, will make the address, perform verifications
# Will throw an error if the address is invalid
client.address.create_and_verify(address_data)
rescue EasyPost::Errors::InvalidRequestError => e
expect(e.message).to eq('Unable to verify address.')
end
end

describe '.verify' do
it 'verifies an already created address' do
# We purposefully pass in slightly incorrect data to get the corrected address back once verified.
address = client.address.create(Fixture.incorrect_address)
address = client.address.create(Fixture.ca_address1)
verified_address = client.address.verify(address.id)

expect(verified_address).to be_an_instance_of(EasyPost::Models::Address)
expect(verified_address.id).to match('adr_')
expect(verified_address.street1).to eq('417 MONTGOMERY ST FL 5')
expect(verified_address.street1).to eq('388 TOWNSEND ST APT 20')
end

it 'throws an error for invalid address verification' do
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9346186

Please sign in to comment.