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

Commit

Permalink
fix: add types to orders api
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jun 5, 2020
1 parent af7a57c commit c569bee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/sections/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
nextToken as nextTokenCodec,
} from '../parsing'
import { getServiceStatusByResource } from './shared'
import { RequireOnlyOne } from './types'

const ORDERS_API_VERSION = '2013-09-01'

Expand Down Expand Up @@ -322,7 +323,15 @@ const canonicalizeParameters = (parameters: ListOrderParameters) => {
export class Orders {
constructor(private httpClient: HttpClient) {}

async listOrders(parameters: ListOrderParameters): Promise<[ListOrders, RequestMeta]> {
/**
* If BuyerEmail is specified, then FulfillmentChannel,
* OrderStatus, PaymentMethod,
* LastUpdatedAfter, LastUpdatedBefore,
* and SellerOrderId cannot be specified.
*/
async listOrders(
parameters: RequireOnlyOne<ListOrderParameters, 'CreatedAfter' | 'LastUpdatedAfter'>,
): Promise<[ListOrders, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Orders,
version: ORDERS_API_VERSION,
Expand Down
11 changes: 6 additions & 5 deletions test/unit/orders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,19 @@ const parsingError = 'Expected an object, but received a string with value ""'

describe('orders', () => {
describe('listOrders', () => {
const parameters = { CreatedAfter: new Date(), MarketplaceId: [] }

it('returns a parsed model when the response is valid', async () => {
expect.assertions(1)

expect(await mockMwsListOrders.orders.listOrders({ MarketplaceId: [] })).toMatchSnapshot()
expect(await mockMwsListOrders.orders.listOrders(parameters)).toMatchSnapshot()
})

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

await expect(() =>
mockMwsFail.orders.listOrders({ MarketplaceId: [] }),
).rejects.toStrictEqual(new ParsingError(parsingError))
await expect(() => mockMwsFail.orders.listOrders(parameters)).rejects.toStrictEqual(
new ParsingError(parsingError),
)
})
})

Expand Down

0 comments on commit c569bee

Please sign in to comment.