Skip to content

Commit

Permalink
- Fix address verification unit test (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwithan8 authored Jan 8, 2024
1 parent 82f1d92 commit 64612d4
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 42 deletions.
1 change: 1 addition & 0 deletions address.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type Address struct {
// CreateAddressOptions is used to specify verification options for address
// creation.
type CreateAddressOptions struct {
// TODO: These should be booleans, not strings, like the other libs
Verify []string `json:"verify,omitempty"`
VerifyStrict []string `json:"verify_strict,omitempty"`
}
Expand Down
2 changes: 1 addition & 1 deletion examples
Submodule examples updated 743 files
26 changes: 18 additions & 8 deletions tests/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,28 +112,38 @@ func (c *ClientTests) TestAddressCreateVerify() {
Verify: []string{"delivery"},
},
)
require.NoError(err)

// Does return an address from CreateAddress even if requested verification fails
require.NoError(err)
assert.Equal(reflect.TypeOf(&easypost.Address{}), reflect.TypeOf(address))
assert.True(strings.HasPrefix(address.ID, "adr_"))
assert.Equal("417 MONTGOMERY ST FL 5", address.Street1)
assert.NotNil(address.Verifications.Delivery)
}

func (c *ClientTests) TestAddressCreateAndVerify() {
client := c.TestClient()
assert, require := c.Assert(), c.Require()

address, err := client.CreateAndVerifyAddress(
// Creating normally (without specifying "verify") will make the address, perform no verifications
address, err := client.CreateAddress(
c.fixture.IncorrectAddress(),
&easypost.CreateAddressOptions{},
)
require.NoError(err)

assert.Equal(reflect.TypeOf(&easypost.Address{}), reflect.TypeOf(address))
assert.Nil(address.Verifications.Delivery)

// Creating with verify would attempt to make the address and perform verifications
address, err = client.CreateAndVerifyAddress(
c.fixture.IncorrectAddress(),
&easypost.CreateAddressOptions{
Verify: []string{"delivery"},
},
)
require.NoError(err)

assert.Equal(reflect.TypeOf(&easypost.Address{}), reflect.TypeOf(address))
assert.True(strings.HasPrefix(address.ID, "adr_"))
assert.Equal("417 MONTGOMERY ST FL 5", address.Street1)
// Does not return an address from CreateAndVerifyAddress if requested verification fails
require.Error(err)
assert.Nil(address)
}

func (c *ClientTests) TestAddressVerify() {
Expand Down
81 changes: 68 additions & 13 deletions tests/cassettes/TestAddressCreateAndVerify.yaml

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

23 changes: 11 additions & 12 deletions tests/cassettes/TestAddressCreateVerify.yaml

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

16 changes: 8 additions & 8 deletions tests/cassettes/TestAddressCreateVerifyStrict.yaml

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

0 comments on commit 64612d4

Please sign in to comment.