Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
test: unit test for create shipment
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 2, 2020
1 parent 727a73e commit 709c9d7
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 23 deletions.
94 changes: 94 additions & 0 deletions test/unit/__fixtures__/merchant_fulfillment_create_shipment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<CreateShipmentResponse xmlns="https://mws.amazonservices.com/MerchantFulfillment/2015-06-01">
<CreateShipmentResult>
<Shipment>
<Insurance>
<CurrencyCode>USD</CurrencyCode>
<Amount>10.00</Amount>
</Insurance>
<ShipToAddress>
<City>Seattle</City>
<Phone/>
<CountryCode>US</CountryCode>
<PostalCode>98121-2778</PostalCode>
<Name>Jane Smith</Name>
<AddressLine1>321 Main St</AddressLine1>
<StateOrProvinceCode>WA</StateOrProvinceCode>
<Email/>
</ShipToAddress>
<AmazonOrderId>903-1713775-3598252</AmazonOrderId>
<Weight>
<Value>10</Value>
<Unit>oz</Unit>
</Weight>
<Label>
<CustomTextForLabel>ABC123</CustomTextForLabel>
<LabelFormat>ZPL203</LabelFormat>
<FileContents>
<Checksum>DmsWbJpdMPALN3jV4wHOrg==</Checksum>
<Contents>H4sIAAAAAAAAAK16WbeqyrLmO2Pc/zBVRLG...
...kI0Ycv76w378UfL6O6ev7UsAwmkWBfL6nycD/Bd+Zx3S8LwAA</Contents>
<FileType>application/zpl</FileType>
<LabelFormat>ZPL203</LabelFormat>
</FileContents>
<Dimensions>
<Width>8.50000</Width>
<Length>11.00000</Length>
<Unit>inches</Unit>
</Dimensions>
<StandardIdForLabel>AmazonOrderId</StandardIdForLabel>
</Label>
<ShippingService>
<CarrierName>FEDEX</CarrierName>
<ShippingServiceOptions>
<CarrierWillPickUp>false</CarrierWillPickUp>
<DeclaredValue>
<CurrencyCode>USD</CurrencyCode>
<Amount>10.00</Amount>
</DeclaredValue>
<DeliveryExperience>DELIVERY_CONFIRMATION </DeliveryExperience>
</ShippingServiceOptions>
<ShippingServiceId>FEDEX_PTP_PRIORITY_OVERNIGHT </ShippingServiceId>
<Rate>
<CurrencyCode>USD</CurrencyCode>
<Amount>27.81</Amount>
</Rate>
<LatestEstimatedDeliveryDate>2015-09-24T10:30:00Z </LatestEstimatedDeliveryDate>
<EarliestEstimatedDeliveryDate>2015-09-24T10:30:00Z </EarliestEstimatedDeliveryDate>
<ShippingServiceOfferId>HDDUKqtQVFetpBZAqx5c1yaCZ9vuFfND0kudyw3lLWCa
3mN2+zUOsRCAZS2oYt0ey6fXKdOAucmYVXR9LAkU9O9eys9V3FJCgvQ+vAqm4bSAzHVH04vD8oLy oUPKqxa8Otbek97Z85LFUSsfcUf8frNRMEfNLP8t5RyLXa4ZOjc=</ShippingServiceOfferId>
<ShipDate>2015-09-23T20:10:56.829Z</ShipDate>
<ShippingServiceName>FedEx Priority Overnight®</ShippingServiceName>
</ShippingService>
<PackageDimensions>
<Width>5</Width>
<Length>5</Length>
<Unit>inches</Unit>
<Height>5</Height>
</PackageDimensions>
<CreatedDate>2015-09-23T20:11:12.908Z</CreatedDate>
<ShipFromAddress>
<City>Seattle</City>
<Phone>2061234567</Phone>
<CountryCode>US</CountryCode>
<PostalCode>98121</PostalCode>
<Name>John Doe</Name>
<AddressLine1>1234 Westlake Ave</AddressLine1>
<StateOrProvinceCode>WA</StateOrProvinceCode>
</ShipFromAddress>
<ShipmentId>6f77095e-9f75-47eb-aaab-a42d5428fa1a</ShipmentId>
<ItemList>
<Item>
<OrderItemId>40525960574974</OrderItemId>
<Quantity>1</Quantity>
<ItemWeight>200</ItemWeight>
<ItemDescription>Poster</ItemDescription>
</Item>
</ItemList>
<Status>Purchased</Status>
<TrackingId>794657111237</TrackingId>
</Shipment>
</CreateShipmentResult>
<ResponseMetadata>
<RequestId>adb18f0d-2076-48d4-99ef-fb4b9f892a4e</RequestId>
</ResponseMetadata>
</CreateShipmentResponse>
72 changes: 49 additions & 23 deletions test/unit/merchant-fulfillment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@ const mockAddress = {
CountryCode: '',
Phone: '',
}

const PackageDimensions = {
PredefinePackageDimensions: 'FedEx_Box_10kg',
}

const Weight: WeightInterface = {
Value: 1,
Unit: 'ounces',
}

const ShippingServiceOptions: ShippingServiceOptionsInterface = {
DeliveryExperience: 'DeliveryConfirmationWithAdultSignature',
CarrierWillPickUp: false,
}

const mockShipmentRequestDetails = {
AmazonOrderId: '',
SellerOrderId: '',
ItemList: [],
ShipFromAddress: mockAddress,
PackageDimensions,
Weight,
MustArriveByDate: new Date(),
ShipDate: new Date(),
ShippingServiceOptions,
}

function mockFunctions() {
/**
* Mock everything in purify-ts, restore it back to normal,
Expand Down Expand Up @@ -83,35 +110,34 @@ describe('merchant-fulfillment', () => {
})
})

describe('getEligiblShippingServices', () => {
const PackageDimensions = {
PredefinePackageDimensions: 'FedEx_Box_10kg',
describe('createShipment', () => {
const parameters = {
ShipmentRequestDetails: mockShipmentRequestDetails,
ShippingServiceId: '',
}

const Weight: WeightInterface = {
Value: 1,
Unit: 'ounces',
}
it('returns details of the shipment if succesful', async () => {
expect.assertions(1)

const ShippingServiceOptions: ShippingServiceOptionsInterface = {
DeliveryExperience: 'DeliveryConfirmationWithAdultSignature',
CarrierWillPickUp: false,
}
const mockCreateShipment = createMockHttpClient('merchant_fulfillment_create_shipment')

const ShipmentRequestDetails = {
AmazonOrderId: '',
SellerOrderId: '',
ItemList: [],
ShipFromAddress: mockAddress,
PackageDimensions,
Weight,
MustArriveByDate: new Date(),
ShipDate: new Date(),
ShippingServiceOptions,
}
expect(
await mockCreateShipment.merchantFulfillment.createShipment(parameters),
).toMatchSnapshot()
})

it("throws a parsing error when the status response isn't valid", async () => {
expect.assertions(1)

await expect(() =>
mockMwsFail.merchantFulfillment.createShipment(parameters),
).rejects.toStrictEqual(new ParsingError(parsingError))
})
})

describe('getEligibleShippingServices', () => {
const parameters: GetEligibleShippingServicesParameters = {
ShipmentRequestDetails,
ShipmentRequestDetails: mockShipmentRequestDetails,
}

it('returns lists of shipping services if succesful with test from C# mocks', async () => {
Expand Down

0 comments on commit 709c9d7

Please sign in to comment.