From 18ecc9a6b8a370cd1d5a5810d0a980a1f3b85dea Mon Sep 17 00:00:00 2001 From: Randall Keur Date: Mon, 18 Nov 2024 11:34:45 -0500 Subject: [PATCH] expand testing for addresses --- test/addresses.test.ts | 24 +++++++++++ test/instalabel.test.ts | 81 ++++++++++++++++++++++---------------- test/serviceGroups.test.ts | 2 +- 3 files changed, 73 insertions(+), 34 deletions(-) create mode 100644 test/addresses.test.ts diff --git a/test/addresses.test.ts b/test/addresses.test.ts new file mode 100644 index 00000000..3b411e94 --- /dev/null +++ b/test/addresses.test.ts @@ -0,0 +1,24 @@ +import {expect} from 'chai'; +import {describe, it} from 'mocha'; +import {shippoSdk} from "./helpers"; + +describe('TestAddresses', function() { + it('testCreateAddress', async () => { + const address = await shippoSdk.addresses.create({ + name: 'Rachael', + street1: '1092 Indian Summer Ct', + city: 'San Jose', + state: 'CA', + zip: '95122', + country: 'US', + phone: '4159876543', + email: 'rachael@alltheyarnz.com' + }) + + expect(address).to.not.be.null; + expect(address).to.be.an('object'); + expect(address).to.have.property('objectId').that.is.a('string'); + expect(address).to.have.property('name').that.is.equal('Rachael') + expect(address).to.have.property('country').that.is.equal('US'); + }) +}) \ No newline at end of file diff --git a/test/instalabel.test.ts b/test/instalabel.test.ts index e570550a..61b09da3 100644 --- a/test/instalabel.test.ts +++ b/test/instalabel.test.ts @@ -1,50 +1,65 @@ import {expect} from 'chai'; import {describe, it} from 'mocha'; -import {CarriersEnum, DistanceUnitEnum, WeightUnitEnum} from '../src/models/components'; +import { CarriersEnum, DistanceUnitEnum, WeightUnitEnum} from '../src'; import {shippoSdk, getCarrierAccount} from "./helpers"; describe('TestInstalabel', function() { it('testInstalabel', async () => { const carrierAccount = await getCarrierAccount(CarriersEnum.Usps); - const transaction = await shippoSdk.transactions.create({ - carrierAccount: carrierAccount.objectId, - servicelevelToken: "usps_ground_advantage", - shipment: { - addressFrom: { - name: "Rachael", - street1: "1092 Indian Summer Ct", - city: "San Jose", - state: "CA", - zip: "95122", - country: "US", - phone: "4159876543", - email: "rachael@alltheyarnz.com" - }, - addressTo: { - name: "Mr Hippo", - street1: "965 Mission St #572", - city: "San Francisco", - state: "CA", - zip: "94103", - country: "US", - phone: "4151234567", - email: "mrhippo@shippo.com" - }, + const addressFrom = await shippoSdk.addresses.create({ + name: "Rachael", + street1: "1092 Indian Summer Ct", + city: "San Jose", + state: "CA", + zip: "95122", + country: "US", + phone: "4159876543", + email: "rachael@alltheyarnz.com" + }) + + const addressTo = await shippoSdk.addresses.create({ + name: "Mr Hippo", + street1: "965 Mission St #572", + city: "San Francisco", + state: "CA", + zip: "94103", + country: "US", + phone: "4151234567", + email: "mrhippo@shippo.com" + }) + + const parcel = await shippoSdk.parcels.create( + { + length: "5", + width: "5", + height: "5", + distanceUnit: DistanceUnitEnum.Cm, + weight: "2", + massUnit: WeightUnitEnum.Lb + } + ) + + const shipment = await shippoSdk.shipments.create( + { + addressFrom: addressFrom, + addressTo: addressTo, parcels: [ - { - length: "5", - width: "5", - height: "5", - distanceUnit: DistanceUnitEnum.Cm, - weight: "2", - massUnit: WeightUnitEnum.Lb - } + parcel ] } + ) + + const transaction = await shippoSdk.transactions.create({ + carrierAccount: carrierAccount.objectId, + servicelevelToken: "usps_ground_advantage", + shipment: shipment }); expect(transaction).to.not.be.null; + expect(transaction).to.have.property('parcel').that.is.a("string"); expect(transaction.rate.objectId).to.not.be.null; + expect(transaction.rate.servicelevelToken).to.be.equal("usps_ground_advantage"); + expect(transaction.rate.currency).to.be.equal("USD"); }); }); diff --git a/test/serviceGroups.test.ts b/test/serviceGroups.test.ts index 43be9956..47b513ee 100644 --- a/test/serviceGroups.test.ts +++ b/test/serviceGroups.test.ts @@ -16,7 +16,7 @@ describe('TestListServiceGroups', function() { expect(firstServiceGroup).to.have.property('description').that.is.a('string'); expect(firstServiceGroup).to.have.property('serviceLevels').that.is.an('array'); const firstServiceLevel = firstServiceGroup.serviceLevels[0]; - expect(firstServiceLevel).to.have.property('account_object_id').that.is.an('string'); + expect(firstServiceLevel).to.have.property('account_object_id').that.is.a('string'); expect(firstServiceLevel).to.have.property('service_level_token').that.is.an('string'); console.log(result); console.log(firstServiceLevel);