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

Commit

Permalink
feat: create getPreorderInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 10, 2020
1 parent 379b463 commit 0be869d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/sections/fulfillment-inbound-shipment/codec.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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<typeof GetPreorderInfo>

export const GetPreorderInfoResponse = Codec.interface({
GetPreorderInfoResponse: Codec.interface({
GetPreorderInfoResult: GetPreorderInfo,
}),
})
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
GetInboundGuidanceForASINResponse,
GetInboundGuidanceForSKU,
GetInboundGuidanceForSKUResponse,
GetPreorderInfo,
GetPreorderInfoResponse,
UpdateInboundShipment,
UpdateInboundShipmentParameters,
UpdateInboundShipmentResponse,
Expand All @@ -21,13 +23,34 @@ import {
CreateInboundShipmentPlanParameters,
GetInboundGuidanceForASINParameters,
GetInboundGuidanceForSKUParameters,
GetPreorderInfoParameters,
} from './type'

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]> {
Expand Down
4 changes: 4 additions & 0 deletions src/sections/fulfillment-inbound-shipment/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,7 @@ export interface CreateInboundShipmentParameters {
InboundShipmentHeader: InboundShipmentHeader
InboundShipmentItems: InboundShipmentItem[]
}

export interface GetPreorderInfoParameters {
ShipmentId: string
}
18 changes: 18 additions & 0 deletions test/unit/__snapshots__/fulfillment-inbound-shipment.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion test/unit/fulfillment-inbound-shipment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 0be869d

Please sign in to comment.