Skip to content

Commit d45a961

Browse files
authored
Merge pull request #495 from EasyPost/error_alternative_format
test: alternative error format
2 parents 8382393 + 9e22121 commit d45a961

File tree

3 files changed

+193
-2
lines changed

3 files changed

+193
-2
lines changed

test/cassettes/Error-Service_386538342/pulls-out-error-properties-of-an-API-error-when-using-the-alternative-format_650479431/recording.har

Lines changed: 163 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/services/address.test.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,34 @@ describe('Address Service', function () {
3333
it('creates an address with verify param', async function () {
3434
const addressData = Fixture.incorrectAddress();
3535

36-
// Creating normally (without specifying "verify") will make the address, perform no verifications
36+
// Creating normally (without specifying "verify") will make the address and perform no verifications
3737
let address = await client.Address.create(addressData);
3838

3939
expect(address).to.be.an.instanceOf(Address);
4040
expect(address.verifications.delivery).to.be.undefined;
4141

42-
// Creating with verify = true will make the address, perform verifications
42+
// Creating with verify = true will make the address and perform verifications
4343
addressData.verify = true;
4444
address = await client.Address.create(addressData);
4545

4646
expect(address).to.be.an.instanceOf(Address);
47+
48+
// Delivery verification assertions
4749
expect(address.verifications.delivery.success).to.be.false;
50+
// TODO: details is not deserializing correctly, related to the larger "double EasyPostObject" wrapping issue
51+
// expect(address.verifications.delivery.details).to.equal({});
52+
expect(address.verifications.delivery.errors[0].code).to.equal('E.ADDRESS.NOT_FOUND');
53+
expect(address.verifications.delivery.errors[0].field).to.equal('address');
54+
expect(address.verifications.delivery.errors[0].suggestion).to.be.null;
55+
expect(address.verifications.delivery.errors[0].message).to.equal('Address not found');
56+
57+
// Zip4 verification assertions
58+
expect(address.verifications.zip4.success).to.be.false;
59+
expect(address.verifications.zip4.details).to.be.null;
60+
expect(address.verifications.zip4.errors[0].code).to.equal('E.ADDRESS.NOT_FOUND');
61+
expect(address.verifications.zip4.errors[0].field).to.equal('address');
62+
expect(address.verifications.zip4.errors[0].suggestion).to.be.null;
63+
expect(address.verifications.zip4.errors[0].message).to.equal('Address not found');
4864
});
4965

5066
it('creates an address with verify_strict param', async function () {

test/services/error.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import TimeoutError from '../../src/errors/api/timeout_error';
1515
import UnauthorizedError from '../../src/errors/api/unauthorized_error';
1616
import UnknownApiError from '../../src/errors/api/unknown_api_error';
1717
import ErrorHandler from '../../src/errors/error_handler';
18+
import Fixture from '../helpers/fixture';
1819
import * as setupPolly from '../helpers/setup_polly';
1920

2021
describe('Error Service', function () {
@@ -39,6 +40,17 @@ describe('Error Service', function () {
3940
});
4041
});
4142

43+
it('pulls out error properties of an API error when using the alternative format', async function () {
44+
const claimData = Fixture.basicClaim();
45+
claimData.tracking_code = '123'; // Intentionally pass a bad tracking code
46+
await client.Claim.create(claimData).catch((error) => {
47+
expect(error.statusCode).to.equal(404);
48+
expect(error.code).to.equal('NOT_FOUND');
49+
expect(error.message).to.equal('The requested resource could not be found.');
50+
assert.deepEqual(error.errors[0], 'No eligible insurance found with provided tracking code.');
51+
});
52+
});
53+
4254
it('test error array parsing', () => {
4355
const fakeErrorResponse = {
4456
statusCode: 404,

0 commit comments

Comments
 (0)