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

Commit

Permalink
feat: made cancelShipment and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 6, 2020
1 parent a0c0942 commit 18a1d97
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/sections/merchant-fulfillment/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,15 @@ export const GetShipmentResponse = Codec.interface({
GetShipmentResult: GetShipment,
}),
})

const CancelShipment = Codec.interface({
Shipment,
})

export type CancelShipment = GetInterface<typeof CancelShipment>

export const CancelShipmentResponse = Codec.interface({
CancelShipmentResponse: Codec.interface({
CancelShipmentResult: CancelShipment,
}),
})
23 changes: 23 additions & 0 deletions src/sections/merchant-fulfillment/merchant-fulfillment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { ParsingError } from '../../error'
import { HttpClient, RequestMeta, Resource } from '../../http'
import { getServiceStatusByResource } from '../shared'
import {
CancelShipment,
CancelShipmentResponse,
CreateShipment,
CreateShipmentResponse,
GetAdditionalSellerInputs,
Expand All @@ -12,6 +14,7 @@ import {
GetShipmentResponse,
} from './codec'
import {
CancelShipmentParameters,
canonicalizeCreateShipmentParameters,
canonicalizeParametersGetEligibleShippingServiceParameters,
CreateShipmentParameters,
Expand All @@ -25,6 +28,26 @@ const MERCHANT_FULFILLMENT_API_VERSION = '2015-06-01'
export class MerchantFulfillment {
constructor(private httpClient: HttpClient) {}

async cancelShipment(
parameters: CancelShipmentParameters,
): Promise<[CancelShipment, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.MerchantFulfillment,
version: MERCHANT_FULFILLMENT_API_VERSION,
action: 'CancelShipment',
parameters: {
ShipmentId: parameters.ShipmentId,
},
})

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

async getShipment(parameters: GetShipmentParameters): Promise<[GetShipment, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.MerchantFulfillment,
Expand Down
7 changes: 4 additions & 3 deletions src/sections/merchant-fulfillment/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,10 @@ export const canonicalizeCreateShipmentParameters = (
* END CreateShipmentParameters
*/

/**
* START GetShipmentParameters
*/
export interface GetShipmentParameters {
ShipmentId: string
}

export interface CancelShipmentParameters {
ShipmentId: string
}
22 changes: 22 additions & 0 deletions test/unit/merchant-fulfillment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ function mockFunctions() {
jest.mock('purify-ts', () => mockFunctions())

describe('merchant-fulfillment', () => {
describe('cancelShipment', () => {
const parameters = { ShipmentId: '' }

it('should return shipment info if succesful', async () => {
expect.assertions(1)

const mockCancelShipment = createMockHttpClient('merchant_fulfillment_cancel_shipment')

expect(
await mockCancelShipment.merchantFulfillment.cancelShipment(parameters),
).toMatchSnapshot()
})

it('throws a parsing error when the status response isnt valid', async () => {
expect.assertions(1)

await expect(() =>
mockMwsFail.merchantFulfillment.cancelShipment(parameters),
).rejects.toStrictEqual(new ParsingError(parsingError))
})
})

describe('getShipment', () => {
const parameters = { ShipmentId: '' }

Expand Down

0 comments on commit 18a1d97

Please sign in to comment.