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

Commit

Permalink
feat: create getPrepInstructionsForAsin
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 13, 2020
1 parent 6845e8d commit 6eafbe4
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/sections/fulfillment-inbound-shipment/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,23 @@ export const GetPrepInstructionsForSKUResponse = Codec.interface({
GetPrepInstructionsForSKUResult: GetPrepInstructionsForSKU,
}),
})

const ASINPrepInstructions = Codec.interface({
ASIN: string,
BarcodeInstruction,
PrepGuidance,
PrepInstructionList: ensureArray('PrepInstruction', PrepInstruction),
})

const GetPrepInstructionsForASIN = Codec.interface({
ASINPrepInstructionsList: ensureArray('ASINPrepInstructions', ASINPrepInstructions),
InvalidASINList: ensureArray('InvalidASIN', InvalidASIN),
})

export type GetPrepInstructionsForASIN = GetInterface<typeof GetPrepInstructionsForASIN>

export const GetPrepInstructionsForASINResponse = Codec.interface({
GetPrepInstructionsForASINResponse: Codec.interface({
GetPrepInstructionsForASINResult: GetPrepInstructionsForASIN,
}),
})
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
GetInboundGuidanceForSKUResponse,
GetPreorderInfo,
GetPreorderInfoResponse,
GetPrepInstructionsForASIN,
GetPrepInstructionsForASINResponse,
GetPrepInstructionsForSKU,
GetPrepInstructionsForSKUResponse,
UpdateInboundShipment,
Expand All @@ -29,6 +31,7 @@ import {
GetInboundGuidanceForASINParameters,
GetInboundGuidanceForSKUParameters,
GetPreorderInfoParameters,
GetPrepInstructionsForASINParameters,
GetPrepInstructionsForSKUParameters,
} from './type'

Expand All @@ -37,6 +40,27 @@ const FULFILLMENT_INBOUND_SHIPMENT_API_VERSION = '2010-10-01'
export class FulfillmentInboundShipment {
constructor(private httpClient: HttpClient) {}

async getPrepInstructionsForAsin(
parameters: GetPrepInstructionsForASINParameters,
): Promise<[GetPrepInstructionsForASIN, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.FulfillmentInboundShipment,
version: FULFILLMENT_INBOUND_SHIPMENT_API_VERSION,
action: 'GetPrepInstructionsForASIN',
parameters: {
'ASINList.Id': parameters.ASINList,
ShipToCountryCode: parameters.ShipToCountryCode,
},
})

return GetPrepInstructionsForASINResponse.decode(response).caseOf({
Right: (x) => [x.GetPrepInstructionsForASINResponse.GetPrepInstructionsForASINResult, meta],
Left: (error) => {
throw new ParsingError(error)
},
})
}

async getPrepInstructionsForSku(
parameters: GetPrepInstructionsForSKUParameters,
): Promise<[GetPrepInstructionsForSKU, RequestMeta]> {
Expand Down
5 changes: 5 additions & 0 deletions src/sections/fulfillment-inbound-shipment/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,8 @@ export interface GetPrepInstructionsForSKUParameters {
SellerSKUList: string[]
ShipToCountryCode: string
}

export interface GetPrepInstructionsForASINParameters {
ASINList: string[]
ShipToCountryCode: string
}
31 changes: 31 additions & 0 deletions test/unit/__snapshots__/fulfillment-inbound-shipment.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,37 @@ Array [
]
`;

exports[`fulfillmentInboundShipment getPrepInstructionsForAsin returns list of prep instructions if succesful 1`] = `
Array [
Object {
"ASINPrepInstructionsList": Array [
Object {
"ASIN": "B00005N5PF",
"BarcodeInstruction": "RequiresFNSKULabel",
"PrepGuidance": "SeePrepInstructionsList",
"PrepInstructionList": Array [
"Polybagging",
"Taping",
],
},
],
"InvalidASINList": Array [
Object {
"ASIN": "B0INVALIDF",
"ErrorReason": "InvalidASIN",
},
],
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;

exports[`fulfillmentInboundShipment getPrepInstructionsForSku returns prep instructions list if succesful 1`] = `
Array [
Object {
Expand Down
6 changes: 4 additions & 2 deletions test/unit/fulfillment-inbound-shipment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ describe('fulfillmentInboundShipment', () => {
expect.assertions(1)

const mockGetPrepInstructionsForAsin = createMockHttpClient(
'fulfillment_inbound_shipmnt_get_prep_instructions_for_asin',
'fulfillment_inbound_shipment_get_prep_instructions_for_asin',
)

expect(
await mockGetPrepInstructionsForAsin.getPrepInstructionsForAsin(parameters),
await mockGetPrepInstructionsForAsin.fulfillmentInboundShipment.getPrepInstructionsForAsin(
parameters,
),
).toMatchSnapshot()
})

Expand Down

0 comments on commit 6eafbe4

Please sign in to comment.