From 0be869d80afa4a36f62e6202f46205dc9b5ba3c5 Mon Sep 17 00:00:00 2001 From: EJ Mercado Date: Fri, 10 Jul 2020 13:03:57 +0800 Subject: [PATCH] feat: create getPreorderInfo --- .../fulfillment-inbound-shipment/codec.ts | 17 +++++++++++++- .../fulfillment-inbound-shipment.ts | 23 +++++++++++++++++++ .../fulfillment-inbound-shipment/type.ts | 4 ++++ .../fulfillment-inbound-shipment.test.ts.snap | 18 +++++++++++++++ .../unit/fulfillment-inbound-shipment.test.ts | 4 +++- 5 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/sections/fulfillment-inbound-shipment/codec.ts b/src/sections/fulfillment-inbound-shipment/codec.ts index 76facc37..77bb9494 100644 --- a/src/sections/fulfillment-inbound-shipment/codec.ts +++ b/src/sections/fulfillment-inbound-shipment/codec.ts @@ -1,4 +1,4 @@ -import { Codec, enumeration, GetInterface, number, optional, string } from 'purify-ts' +import { boolean, Codec, enumeration, GetInterface, number, optional, string } from 'purify-ts' import { ensureArray, ensureString } from '../../parsing' import { CreateInboundShipmentParameters, PrepInstructionEnum, PrepOwnerEnum } from './type' @@ -145,3 +145,18 @@ export const CreateInboundShipmentPlanResponse = Codec.interface({ CreateInboundShipmentPlanResult: CreateInboundShipmentPlan, }), }) + +export const GetPreorderInfo = Codec.interface({ + ShipmentContainsPreorderableItems: boolean, + NeedByDate: string, + ConfirmedFulfillableDate: string, + ShipmentConfirmedForPreorder: boolean, +}) + +export type GetPreorderInfo = GetInterface + +export const GetPreorderInfoResponse = Codec.interface({ + GetPreorderInfoResponse: Codec.interface({ + GetPreorderInfoResult: GetPreorderInfo, + }), +}) diff --git a/src/sections/fulfillment-inbound-shipment/fulfillment-inbound-shipment.ts b/src/sections/fulfillment-inbound-shipment/fulfillment-inbound-shipment.ts index 8bb70e31..39e199f5 100644 --- a/src/sections/fulfillment-inbound-shipment/fulfillment-inbound-shipment.ts +++ b/src/sections/fulfillment-inbound-shipment/fulfillment-inbound-shipment.ts @@ -10,6 +10,8 @@ import { GetInboundGuidanceForASINResponse, GetInboundGuidanceForSKU, GetInboundGuidanceForSKUResponse, + GetPreorderInfo, + GetPreorderInfoResponse, UpdateInboundShipment, UpdateInboundShipmentParameters, UpdateInboundShipmentResponse, @@ -21,6 +23,7 @@ import { CreateInboundShipmentPlanParameters, GetInboundGuidanceForASINParameters, GetInboundGuidanceForSKUParameters, + GetPreorderInfoParameters, } from './type' const FULFILLMENT_INBOUND_SHIPMENT_API_VERSION = '2010-10-01' @@ -28,6 +31,26 @@ const FULFILLMENT_INBOUND_SHIPMENT_API_VERSION = '2010-10-01' export class FulfillmentInboundShipment { constructor(private httpClient: HttpClient) {} + async getPreorderInfo( + parameters: GetPreorderInfoParameters, + ): Promise<[GetPreorderInfo, RequestMeta]> { + const [response, meta] = await this.httpClient.request('POST', { + resource: Resource.FulfillmentInboundShipment, + version: FULFILLMENT_INBOUND_SHIPMENT_API_VERSION, + action: 'GetPreorderInfo', + parameters: { + ShipmentId: parameters.ShipmentId, + }, + }) + + return GetPreorderInfoResponse.decode(response).caseOf({ + Right: (x) => [x.GetPreorderInfoResponse.GetPreorderInfoResult, meta], + Left: (error) => { + throw new ParsingError(error) + }, + }) + } + async updateInboundShipment( parameters: UpdateInboundShipmentParameters, ): Promise<[UpdateInboundShipment, RequestMeta]> { diff --git a/src/sections/fulfillment-inbound-shipment/type.ts b/src/sections/fulfillment-inbound-shipment/type.ts index 8e0163e6..a4e601a9 100644 --- a/src/sections/fulfillment-inbound-shipment/type.ts +++ b/src/sections/fulfillment-inbound-shipment/type.ts @@ -180,3 +180,7 @@ export interface CreateInboundShipmentParameters { InboundShipmentHeader: InboundShipmentHeader InboundShipmentItems: InboundShipmentItem[] } + +export interface GetPreorderInfoParameters { + ShipmentId: string +} diff --git a/test/unit/__snapshots__/fulfillment-inbound-shipment.test.ts.snap b/test/unit/__snapshots__/fulfillment-inbound-shipment.test.ts.snap index d6e30eca..60a73179 100644 --- a/test/unit/__snapshots__/fulfillment-inbound-shipment.test.ts.snap +++ b/test/unit/__snapshots__/fulfillment-inbound-shipment.test.ts.snap @@ -119,6 +119,24 @@ Array [ ] `; +exports[`fulfillmentInboundShipment getPreorderInfo returns preorderinfo if succesful 1`] = ` +Array [ + Object { + "ConfirmedFulfillableDate": "2015-12-31", + "NeedByDate": "2015-12-27", + "ShipmentConfirmedForPreorder": true, + "ShipmentContainsPreorderableItems": true, + }, + Object { + "quotaMax": 1000, + "quotaRemaining": 999, + "quotaResetOn": 2020-04-06T10:22:23.582Z, + "requestId": "0", + "timestamp": 2020-05-06T09:22:23.582Z, + }, +] +`; + exports[`fulfillmentInboundShipment getServiceStatus returns a parsed model when the status response is valid 1`] = ` Array [ Object { diff --git a/test/unit/fulfillment-inbound-shipment.test.ts b/test/unit/fulfillment-inbound-shipment.test.ts index aa1dc06f..c697cb0e 100644 --- a/test/unit/fulfillment-inbound-shipment.test.ts +++ b/test/unit/fulfillment-inbound-shipment.test.ts @@ -68,7 +68,9 @@ describe('fulfillmentInboundShipment', () => { 'fulfillment_inbound_shipment_get_preorder_info', ) - expect(await mockGetPreorderInfo.getPreorderInfo(parameters)).toMatchSnapshot() + expect( + await mockGetPreorderInfo.fulfillmentInboundShipment.getPreorderInfo(parameters), + ).toMatchSnapshot() }) it('throws a parsing error when the status response isn t valid', async () => {