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

Commit

Permalink
fix: tests for products, reports, sellers, subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado authored and moltar committed Jun 28, 2020
1 parent d1b37a7 commit 09be2da
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 424 deletions.
8 changes: 4 additions & 4 deletions test/unit/__snapshots__/sellers.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Array [
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-05-06T10:22:23.582Z,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T08:22:23.582Z,
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;
Expand Down Expand Up @@ -97,9 +97,9 @@ Array [
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-05-06T10:22:23.582Z,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T08:22:23.582Z,
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;
99 changes: 17 additions & 82 deletions test/unit/orders.test.ts
Original file line number Diff line number Diff line change
@@ -1,93 +1,16 @@
import { amazonMarketplaces, HttpClient, ParsingError } from '../../src'
import { MWS } from '../../src/mws'
import { ParsingError } from '../../src'
import { NextToken } from '../../src/parsing'
import { getFixture } from '../utils'

const httpConfig = {
awsAccessKeyId: '',
marketplace: amazonMarketplaces.CA,
mwsAuthToken: '',
secretKey: '',
sellerId: '',
}

const headers = {
'x-mws-request-id': '0',
'x-mws-timestamp': '2020-05-06T09:22:23.582Z',
'x-mws-quota-max': '1000',
'x-mws-quota-remaining': '999',
'x-mws-quota-resetson': '2020-04-06T10:22:23.582Z',
}

const mockMwsListOrders = new MWS(
new HttpClient(httpConfig, () =>
Promise.resolve({
data: getFixture('orders_list_orders'),
headers,
}),
),
)

const mockMwsListOrdersNT = new MWS(
new HttpClient(httpConfig, () =>
Promise.resolve({
data: getFixture('orders_list_orders_nt'),
headers,
}),
),
)

const mockMwsGetOrder = new MWS(
new HttpClient(httpConfig, () =>
Promise.resolve({
data: getFixture('orders_get_order'),
headers,
}),
),
)

const mockMwsListOrderItems = new MWS(
new HttpClient(httpConfig, () =>
Promise.resolve({
data: getFixture('orders_list_order_items'),
headers,
}),
),
)

const mockMwsListOrderItemsNT = new MWS(
new HttpClient(httpConfig, () =>
Promise.resolve({
data: getFixture('orders_list_order_items_nt'),
headers,
}),
),
)

const mockMwsServiceStatus = new MWS(
new HttpClient(httpConfig, () =>
Promise.resolve({
data: getFixture('get_service_status'),
headers,
}),
),
)

const mockMwsFail = new MWS(
new HttpClient(httpConfig, () => Promise.resolve({ data: '', headers: {} })),
)

const mockNextTokenOrders = new NextToken('ListOrders', '123')
const mockNextTokenOrderItems = new NextToken('ListOrderItems', '123')

const parsingError = 'Expected an object, but received a string with value ""'
import { createMockHttpClient, mockMwsFail, mockMwsServiceStatus, parsingError } from '../utils'

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

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

const mockMwsListOrders = createMockHttpClient('orders_list_orders')

expect(await mockMwsListOrders.orders.listOrders(parameters)).toMatchSnapshot()
})

Expand All @@ -101,9 +24,13 @@ describe('orders', () => {
})

describe('listOrdersByNextToken', () => {
const mockNextTokenOrders = new NextToken('ListOrders', '123')

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

const mockMwsListOrdersNT = createMockHttpClient('orders_list_orders_nt')

expect(
await mockMwsListOrdersNT.orders.listOrdersByNextToken(mockNextTokenOrders),
).toMatchSnapshot()
Expand All @@ -122,6 +49,8 @@ describe('orders', () => {
it('returns an array of orders when the response is valid', async () => {
expect.assertions(1)

const mockMwsGetOrder = createMockHttpClient('orders_get_order')

expect(await mockMwsGetOrder.orders.getOrder({ AmazonOrderId: [] })).toMatchSnapshot()
})

Expand All @@ -138,6 +67,8 @@ describe('orders', () => {
it('returns an array of order items when the response is valid', async () => {
expect.assertions(1)

const mockMwsListOrderItems = createMockHttpClient('orders_list_order_items')

expect(
await mockMwsListOrderItems.orders.listOrderItems({ AmazonOrderId: '' }),
).toMatchSnapshot()
Expand All @@ -153,9 +84,13 @@ describe('orders', () => {
})

describe('listOrderItemsByNextToken', () => {
const mockNextTokenOrderItems = new NextToken('ListOrderItems', '123')

it('returns an array of order items when the response is valid', async () => {
expect.assertions(1)

const mockMwsListOrderItemsNT = createMockHttpClient('orders_list_order_items_nt')

expect(
await mockMwsListOrderItemsNT.orders.listOrderItemsByNextToken(mockNextTokenOrderItems),
).toMatchSnapshot()
Expand Down

0 comments on commit 09be2da

Please sign in to comment.