-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from starsprung/get-shipments
feat: add getShipments
- Loading branch information
Showing
4 changed files
with
169 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,3 +144,74 @@ Array [ | |
}, | ||
] | ||
`; | ||
|
||
exports[`AmazonOrderReportsApi getShipments should return shipment for each row in report 1`] = ` | ||
Array [ | ||
Object { | ||
"buyerName": "Test Man", | ||
"carrierNameTrackingNumber": "USPS(9374889475927355877285)", | ||
"orderDate": 2020-01-10T08:00:00.000Z, | ||
"orderId": "112-1234567-1111111", | ||
"orderStatus": "Shipped", | ||
"orderingCustomerEmail": "[email protected]", | ||
"paymentInstrumentType": "American Express - 1234", | ||
"shipmentDate": 2020-01-11T08:00:00.000Z, | ||
"shippingAddressCity": "Washington", | ||
"shippingAddressName": "Test Man", | ||
"shippingAddressState": "DC", | ||
"shippingAddressStreet1": "1600 Pennsylvania Avenue NW", | ||
"shippingAddressZip": "20500", | ||
"shippingCharge": 0, | ||
"subtotal": 7.8, | ||
"taxBeforePromotions": 0, | ||
"taxCharged": 0, | ||
"totalCharged": 7.8, | ||
"totalPromotions": 0, | ||
"website": "Amazon.com", | ||
}, | ||
Object { | ||
"buyerName": "Test Man", | ||
"carrierNameTrackingNumber": "UPS Mail Innovations(92748931384958372634886196)", | ||
"orderDate": 2020-01-23T08:00:00.000Z, | ||
"orderId": "112-1234568-2222222", | ||
"orderStatus": "Shipped", | ||
"orderingCustomerEmail": "[email protected]", | ||
"paymentInstrumentType": "American Express - 1235", | ||
"shipmentDate": 2020-01-26T08:00:00.000Z, | ||
"shippingAddressCity": "Washington", | ||
"shippingAddressName": "Test Man", | ||
"shippingAddressState": "DC", | ||
"shippingAddressStreet1": "1600 Pennsylvania Avenue NW", | ||
"shippingAddressZip": "20500", | ||
"shippingCharge": 3.4, | ||
"subtotal": 7.84, | ||
"taxBeforePromotions": 0, | ||
"taxCharged": 0, | ||
"totalCharged": 11.24, | ||
"totalPromotions": 0, | ||
"website": "Amazon.com", | ||
}, | ||
Object { | ||
"buyerName": "Test Man", | ||
"carrierNameTrackingNumber": "FEDEX(536485026870)", | ||
"orderDate": 2020-02-22T08:00:00.000Z, | ||
"orderId": "112-1234569-3333333", | ||
"orderStatus": "Shipped", | ||
"orderingCustomerEmail": "[email protected]", | ||
"paymentInstrumentType": "American Express - 1236", | ||
"shipmentDate": 2020-02-23T08:00:00.000Z, | ||
"shippingAddressCity": "Washington", | ||
"shippingAddressName": "Test Man", | ||
"shippingAddressState": "DC", | ||
"shippingAddressStreet1": "1600 Pennsylvania Avenue NW", | ||
"shippingAddressZip": "20500", | ||
"shippingCharge": 17.99, | ||
"subtotal": 489.95, | ||
"taxBeforePromotions": 0, | ||
"taxCharged": 0, | ||
"totalCharged": 507.94, | ||
"totalPromotions": 0, | ||
"website": "Amazon.com", | ||
}, | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import puppeteer from 'puppeteer-extra'; | |
import { Readable } from 'stream'; | ||
import { mocked } from 'ts-jest/utils'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { AmazonOrderReportsApi, OrderItem, Refund } from './index'; | ||
import { AmazonOrderReportsApi, OrderItem, Refund, Shipment } from './index'; | ||
import { mocks } from './__mocks__/puppeteer-extra'; | ||
|
||
jest.mock('delay'); | ||
|
@@ -391,4 +391,29 @@ describe('AmazonOrderReportsApi', () => { | |
expect(items).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('getShipments', () => { | ||
let api: AmazonOrderReportsApi; | ||
|
||
beforeEach(() => { | ||
api = new AmazonOrderReportsApi({ | ||
username: '[email protected]', | ||
password: 'test123', | ||
}); | ||
|
||
mocked(createReadStream).mockImplementation(() => | ||
jest.requireActual('fs').createReadStream(appRootPath.resolve('test-data/shipments.csv')), | ||
); | ||
}); | ||
|
||
it('should return shipment for each row in report', async () => { | ||
const shipments: Array<Shipment> = []; | ||
for await (const shipment of api.getShipments()) { | ||
shipments.push(shipment); | ||
} | ||
|
||
expect(shipments).toHaveLength(3); | ||
expect(shipments).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Order Date,Order ID,Payment Instrument Type,Website,Purchase Order Number,Ordering Customer Email,Shipment Date,Shipping Address Name,Shipping Address Street 1,Shipping Address Street 2,Shipping Address City,Shipping Address State,Shipping Address Zip,Order Status,Carrier Name & Tracking Number,Subtotal,Shipping Charge,Tax Before Promotions,Total Promotions,Tax Charged,Total Charged,Buyer Name,Group Name | ||
01/10/20,112-1234567-1111111,American Express - 1234,Amazon.com,,[email protected],01/11/20,Test Man,1600 Pennsylvania Avenue NW,,Washington,DC,20500,Shipped,USPS(9374889475927355877285),$7.80,$0.00,$0.00,$0.00,$0.00,$7.80,Test Man, | ||
01/23/20,112-1234568-2222222,American Express - 1235,Amazon.com,,[email protected],01/26/20,Test Man,1600 Pennsylvania Avenue NW,,Washington,DC,20500,Shipped,UPS Mail Innovations(92748931384958372634886196),$7.84,$3.40,$0.00,$0.00,$0.00,$11.24,Test Man, | ||
02/22/20,112-1234569-3333333,American Express - 1236,Amazon.com,,[email protected],02/23/20,Test Man,1600 Pennsylvania Avenue NW,,Washington,DC,20500,Shipped,FEDEX(536485026870),$489.95,$17.99,$0.00,$0.00,$0.00,$507.94,Test Man, |