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

Commit

Permalink
test: get report list nt, fix var init to be closer to usage
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jun 9, 2020
1 parent 7ff06e8 commit 0aae222
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 11 deletions.
16 changes: 16 additions & 0 deletions test/unit/__fixtures__/reports_get_report_list_nt.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<GetReportListByNextTokenResponse xmlns="http://mws.amazonservices.com/doc/2009-01-01/">
<GetReportListByNextTokenResult>
<NextToken>none</NextToken>
<HasNext>false</HasNext>
<ReportInfo>
<ReportId>898899473</ReportId>
<ReportType>_GET_MERCHANT_LISTINGS_DATA_</ReportType>
<ReportRequestId>2278662938</ReportRequestId>
<AvailableDate>2009-02-10T09:22:33+00:00</AvailableDate>
<Acknowledged>false</Acknowledged>
</ReportInfo>
</GetReportListByNextTokenResult>
<ResponseMetadata>
<RequestId>fbf677c1-dcee-4110-bc88-2ba3702e331b</RequestId>
</ResponseMetadata>
</GetReportListByNextTokenResponse>
52 changes: 41 additions & 11 deletions test/unit/reports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,44 @@ const createMockHttpClient = (fixture: string) =>
),
)

const mockMwsServiceStatus = createMockHttpClient('get_service_status')

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

const mockRequestReport = createMockHttpClient('reports_request_report')
const mockGetReportRequestList = createMockHttpClient('reports_get_report_request_list')
const mockGetReportRequestListByNextToken = createMockHttpClient(
'reports_get_report_request_list_by_next_token',
)
const mockGetReportRequestCount = createMockHttpClient('reports_get_report_request_count')
const mockCancelReportRequests = createMockHttpClient('reports_cancel_report_requests')
const mockGetReportList = createMockHttpClient('reports_get_report_list')

describe('reports', () => {
describe('getReportListByNextToken', () => {
const mockNextToken = new NextToken('GetReportList', '123')
const parameters = {
NextToken: mockNextToken,
}

it('returns report info and next token if succesful', async () => {
expect.assertions(1)

const mockGetReportListByNextToken = createMockHttpClient('reports_get_report_list_nt')

expect(
await mockGetReportListByNextToken.reports.getReportListByNextToken(parameters),
).toMatchSnapshot()
})

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

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

describe('getReportList', () => {
const parameters = {}

it('returns report info and next token if succesful', async () => {
expect.assertions(1)

const mockGetReportList = createMockHttpClient('reports_get_report_list')

expect(await mockGetReportList.reports.getReportList(parameters)).toMatchSnapshot()
})

Expand All @@ -71,6 +87,8 @@ describe('reports', () => {
it('returns count and detailed info of cancelled requests if succesful', async () => {
expect.assertions(1)

const mockCancelReportRequests = createMockHttpClient('reports_cancel_report_requests')

expect(
await mockCancelReportRequests.reports.cancelReportRequests(parameters),
).toMatchSnapshot()
Expand All @@ -91,6 +109,8 @@ describe('reports', () => {
it('returns report request count if succesful', async () => {
expect.assertions(1)

const mockGetReportRequestCount = createMockHttpClient('reports_get_report_request_count')

expect(
await mockGetReportRequestCount.reports.getReportRequestCount(parameters),
).toMatchSnapshot()
Expand All @@ -114,6 +134,10 @@ describe('reports', () => {
it('returns report request info if succesful', async () => {
expect.assertions(1)

const mockGetReportRequestListByNextToken = createMockHttpClient(
'reports_get_report_request_list_nt',
)

expect(
await mockGetReportRequestListByNextToken.reports.getReportRequestListByNextToken(
parameters,
Expand All @@ -136,6 +160,8 @@ describe('reports', () => {
it('returns report request info if succesful', async () => {
expect.assertions(1)

const mockGetReportRequestList = createMockHttpClient('reports_get_report_request_list')

expect(
await mockGetReportRequestList.reports.getReportRequestList(parameters),
).toMatchSnapshot()
Expand All @@ -158,6 +184,8 @@ describe('reports', () => {
it('returns a parsed model when the response is valid', async () => {
expect.assertions(1)

const mockRequestReport = createMockHttpClient('reports_request_report')

expect(await mockRequestReport.reports.requestReport(parameters)).toMatchSnapshot()
})

Expand All @@ -174,6 +202,8 @@ describe('reports', () => {
it('returns a parsed model when the status response is valid', async () => {
expect.assertions(1)

const mockMwsServiceStatus = createMockHttpClient('get_service_status')

expect(await mockMwsServiceStatus.reports.getServiceStatus()).toMatchSnapshot()
})

Expand Down

0 comments on commit 0aae222

Please sign in to comment.