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

Commit

Permalink
feat: init get additional seller inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 1, 2020
1 parent e8bc28f commit 2223441
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 11 deletions.
29 changes: 28 additions & 1 deletion src/sections/merchant-fulfillment/merchant-fulfillment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { boolean, Codec, enumeration, GetInterface, optional, string } from 'purify-ts'
import { boolean, Codec, enumeration, GetInterface, optional, string, unknown } from 'purify-ts'

import { ParsingError } from '../../error'
import { HttpClient, RequestMeta, Resource } from '../../http'
Expand Down Expand Up @@ -74,10 +74,37 @@ const GetEligibleShippingServicesResponse = Codec.interface({
GetEligibleShippingServicesResult: GetEligibleShippingServices,
}),
})
// interface GetAdditionalSellerInputsParameters {}

const GetAdditionalSellerInputs = unknown
type GetAdditionalSellerInputs = GetInterface<typeof GetAdditionalSellerInputs>

const GetAdditionalSellerInputsResponse = Codec.interface({
GetAdditionalSellerInputsResponse: Codec.interface({
GetAdditionalSellerInputsResult: GetAdditionalSellerInputs,
}),
})
export class MerchantFulfillment {
constructor(private httpClient: HttpClient) {}

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

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

async getEligibleShippingServices(
parameters: GetEligibleShippingServicesParameters,
): Promise<[GetEligibleShippingServices, RequestMeta]> {
Expand Down
50 changes: 40 additions & 10 deletions test/unit/merchant-fulfillment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,48 @@ import {
} from '../../src/sections/merchant-fulfillment/type'
import { createMockHttpClient, mockMwsFail, mockMwsServiceStatus, parsingError } from '../utils'

const mockAddress = {
Name: '',
AddressLine1: '',
Email: '',
City: '',
PostalCode: '',
CountryCode: '',
Phone: '',
}

describe('merchant-fulfillment', () => {
describe('getEligiblShippingServices', () => {
const Address = {
Name: '',
AddressLine1: '',
Email: '',
City: '',
PostalCode: '',
CountryCode: '',
Phone: '',
describe('getAdditionalSellerInputs', () => {
const parameters = {
OrderId: '',
ShippingServiceId: '',
ShipFromAddress: mockAddress,
}

it('returns shipment level fields and item level fields if succesful', async () => {
expect.assertions(1)

const mockGetAdditionalSellerInputs = createMockHttpClient(
'merchant_get_additional_seller_inputs',
)

expect(
await mockGetAdditionalSellerInputs.merchantFulfillment.getAddtionalSellerInputs(
parameters,
),
).toMatchSnapshot()
})

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

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

describe('getEligiblShippingServices', () => {
const PackageDimensions = {
PredefinePackageDimensions: 'FedEx_Box_10kg',
}
Expand All @@ -36,7 +66,7 @@ describe('merchant-fulfillment', () => {
AmazonOrderId: '',
SellerOrderId: '',
ItemList: [],
ShipFromAddress: Address,
ShipFromAddress: mockAddress,
PackageDimensions,
Weight,
MustArriveByDate: new Date(),
Expand Down

0 comments on commit 2223441

Please sign in to comment.