From af7a57c20dabfc675c1c599f83a70387430533b4 Mon Sep 17 00:00:00 2001 From: EJ Mercado Date: Fri, 5 Jun 2020 16:03:42 +0800 Subject: [PATCH] fix: apply to fulfillment inventory --- src/sections/fulfillment-inventory.ts | 6 +++++- src/sections/types.ts | 3 ++- test/unit/fulfillment-inventory.test.ts | 8 ++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/sections/fulfillment-inventory.ts b/src/sections/fulfillment-inventory.ts index d29f56bb..38868c6f 100644 --- a/src/sections/fulfillment-inventory.ts +++ b/src/sections/fulfillment-inventory.ts @@ -4,6 +4,7 @@ import { ParsingError } from '../error' import { HttpClient, RequestMeta, Resource } from '../http' import { ensureArray, mwsDate, NextToken, nextToken as nextTokenCodec } from '../parsing' import { getServiceStatusByResource } from './shared' +import { RequireOnlyOne } from './types' const FULFILLMENT_INVENTORY_API_VERSION = '2010-10-01' @@ -112,7 +113,10 @@ export class FulfillmentInventory { constructor(private httpClient: HttpClient) {} async listInventorySupply( - parameters: ListInventorySupplyRequestParameters, + parameters: RequireOnlyOne< + ListInventorySupplyRequestParameters, + 'MarketplaceId' | 'QueryStartDateTime' + >, ): Promise<[InventorySupplyList, RequestMeta]> { const [response, meta] = await this.httpClient.request('POST', { resource: Resource.FulfilmentInventory, diff --git a/src/sections/types.ts b/src/sections/types.ts index fe2b8f49..1c28ffd9 100644 --- a/src/sections/types.ts +++ b/src/sections/types.ts @@ -1,8 +1,9 @@ /** * For use with parameters that require one of two values + * Source: https://stackoverflow.com/a/49725198/5808843 */ -type RequireOnlyOne = Pick> & +export type RequireOnlyOne = Pick> & { [K in Keys]-?: Required> & Partial, undefined>> }[Keys] diff --git a/test/unit/fulfillment-inventory.test.ts b/test/unit/fulfillment-inventory.test.ts index 980a4647..81f4c212 100644 --- a/test/unit/fulfillment-inventory.test.ts +++ b/test/unit/fulfillment-inventory.test.ts @@ -55,10 +55,14 @@ const parsingError = 'Expected an object, but received a string with value ""' describe('fulfillment-inventory', () => { describe('listInventorySupply', () => { + const parameters = { + MarketplaceId: '', + } + it('returns a parsed model when the response is valid', async () => { expect.assertions(1) expect( - await mockMwsInventorySupply.fulfillmentInventory.listInventorySupply({}), + await mockMwsInventorySupply.fulfillmentInventory.listInventorySupply(parameters), ).toMatchSnapshot() }) @@ -66,7 +70,7 @@ describe('fulfillment-inventory', () => { expect.assertions(1) await expect(() => - mockMwsFail.fulfillmentInventory.listInventorySupply({}), + mockMwsFail.fulfillmentInventory.listInventorySupply(parameters), ).rejects.toStrictEqual(new ParsingError(parsingError)) }) })