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

Commit

Permalink
fix: apply to fulfillment inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jun 5, 2020
1 parent bf57f3f commit af7a57c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/sections/fulfillment-inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/sections/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* For use with parameters that require one of two values
* Source: https://stackoverflow.com/a/49725198/5808843
*/

type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> &
export type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> &
{
[K in Keys]-?: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, undefined>>
}[Keys]
8 changes: 6 additions & 2 deletions test/unit/fulfillment-inventory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,22 @@ 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()
})

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

await expect(() =>
mockMwsFail.fulfillmentInventory.listInventorySupply({}),
mockMwsFail.fulfillmentInventory.listInventorySupply(parameters),
).rejects.toStrictEqual(new ParsingError(parsingError))
})
})
Expand Down

0 comments on commit af7a57c

Please sign in to comment.