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

Commit

Permalink
feat: create updateInboundShipment
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 10, 2020
1 parent f694391 commit 8719bf3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
40 changes: 36 additions & 4 deletions src/sections/fulfillment-inbound-shipment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ const canonicalizeInboundShipmentPlanRequestItems = (
}
}

const canonicalizeParametersCreateInboundShipmentPlan = (
const canonicalizeParametersCreateInboUpdateundShipmentPlan = (
parameters: CreateInboundShipmentPlanParameters,
) => {
const fixedInboundShipmentPlanRequestItems = parameters.InboundShipmentPlanRequestItems.map(
Expand Down Expand Up @@ -294,7 +294,7 @@ const canonicalizeInboundShipmentItem = (item: InboundShipmentItem) => {
}
}

const canonicalizeParametersCreateInboundShipment = (
const canonicalizeParametersCreateUpdateInboundShipment = (
parameters: CreateInboundShipmentParameters,
) => {
const shipmentItemsCanonicalized = parameters.InboundShipmentItems.map((item) =>
Expand All @@ -319,17 +319,49 @@ const CreateInboundShipmentResponse = Codec.interface({
}),
})

type UpdateInboundShipmentParameters = CreateInboundShipmentParameters

const UpdateInboundShipment = Codec.interface({
ShipmentId: string,
})

type UpdateInboundShipment = GetInterface<typeof UpdateInboundShipment>

const UpdateInboundShipmentResponse = Codec.interface({
UpdateInboundShipmentResponse: Codec.interface({
UpdateInboundShipmentResult: UpdateInboundShipment,
}),
})

export class FulfillmentInboundShipment {
constructor(private httpClient: HttpClient) {}

async updateInboundShipment(
parameters: UpdateInboundShipmentParameters,
): Promise<[UpdateInboundShipment, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.FulfillmentInboundShipment,
version: FULFILLMENT_INBOUND_SHIPMENT_API_VERSION,
action: 'UpdateInboundShipment',
parameters: canonicalizeParametersCreateUpdateInboundShipment(parameters),
})

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

async createInboundShipment(
parameters: CreateInboundShipmentParameters,
): Promise<[CreateInboundShipment, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.FulfillmentInboundShipment,
version: FULFILLMENT_INBOUND_SHIPMENT_API_VERSION,
action: 'CreateInboundShipment',
parameters: canonicalizeParametersCreateInboundShipment(parameters),
parameters: canonicalizeParametersCreateUpdateInboundShipment(parameters),
})

return CreateInboundShipmentResponse.decode(response).caseOf({
Expand All @@ -347,7 +379,7 @@ export class FulfillmentInboundShipment {
resource: Resource.FulfillmentInboundShipment,
version: FULFILLMENT_INBOUND_SHIPMENT_API_VERSION,
action: 'CreateInboundShipmentPlan',
parameters: canonicalizeParametersCreateInboundShipmentPlan(parameters),
parameters: canonicalizeParametersCreateInboUpdateundShipmentPlan(parameters),
})

return CreateInboundShipmentPlanResponse.decode(response).caseOf({
Expand Down
15 changes: 15 additions & 0 deletions test/unit/__snapshots__/fulfillment-inbound-shipment.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,18 @@ Array [
},
]
`;

exports[`fulfillmentInboundShipment updateInboundShipment return the shipment id if succesful 1`] = `
Array [
Object {
"ShipmentId": "FBA2F50GYX",
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;
2 changes: 1 addition & 1 deletion test/unit/fulfillment-inbound-shipment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('fulfillmentInboundShipment', () => {
expect.assertions(1)

const mockUpdateInboundShipment = createMockHttpClient(
'fulfillment-inbound-shipment-update-inbound-shipment',
'fulfillment_inbound_shipment_update_inbound_shipment',
)

expect(
Expand Down

0 comments on commit 8719bf3

Please sign in to comment.