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

Commit

Permalink
feat: get report request list by NT
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jun 8, 2020
1 parent aab2b2b commit a0851e5
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
35 changes: 34 additions & 1 deletion src/sections/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { boolean, Codec, GetInterface, optional, string } from 'purify-ts'

import { ParsingError } from '../error'
import { HttpClient, RequestMeta, Resource } from '../http'
import { ensureString, mwsDate, nextToken as nextTokenCodec } from '../parsing'
import { ensureString, mwsDate, NextToken, nextToken as nextTokenCodec } from '../parsing'
import { getServiceStatusByResource } from './shared'

const REPORTS_API_VERSION = '2009-01-01'
Expand Down Expand Up @@ -76,9 +76,42 @@ const GetReportRequestListResponse = Codec.interface({
}),
})

const GetReportRequestListByNextTokenResponse = Codec.interface({
GetReportRequestListByNextTokenResponse: Codec.interface({
GetReportRequestListByNextTokenResult: GetReportRequestListResult,
}),
})

interface GetReportRequestListByNextTokenParameters {
NextToken: NextToken<'GetReportRequestList'>
}

export class Reports {
constructor(private httpClient: HttpClient) {}

async getReportRequestListByNextToken(
parameters: GetReportRequestListByNextTokenParameters,
): Promise<[GetReportRequestListResult, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Report,
version: REPORTS_API_VERSION,
action: 'GetReportRequestListByNextToken',
parameters: {
NextToken: parameters.NextToken.token,
},
})

return GetReportRequestListByNextTokenResponse.decode(response).caseOf({
Right: (x) => [
x.GetReportRequestListByNextTokenResponse.GetReportRequestListByNextTokenResult,
meta,
],
Left: (error) => {
throw new ParsingError(error)
},
})
}

async getReportRequestList(
parameters: GetReportRequestListParameters,
): Promise<[GetReportRequestListResult, RequestMeta]> {
Expand Down
33 changes: 32 additions & 1 deletion test/unit/__snapshots__/reports.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`reports getReportRequestList returns a parsed model when the response is valid 1`] = `
exports[`reports getReportRequestList returns report request info if succesful 1`] = `
Array [
Object {
"HasNext": true,
Expand Down Expand Up @@ -31,6 +31,37 @@ Array [
]
`;

exports[`reports getReportRequestListByNextToken returns report request info if succesful 1`] = `
Array [
Object {
"HasNext": false,
"NextToken": NextToken {
"action": "GetReportRequestList",
"token": "none",
},
"ReportRequestInfo": Object {
"CompletedDate": undefined,
"EndDate": 2009-02-13T02:10:39.000Z,
"GeneratedReportId": undefined,
"ReportProcessingStatus": "_SUBMITTED_",
"ReportRequestId": "2291326454",
"ReportType": "_GET_MERCHANT_LISTINGS_DATA_",
"Scheduled": false,
"StartDate": 2009-01-21T02:10:39.000Z,
"StartedProcessingDate": undefined,
"SubmittedDate": 2009-02-20T02:10:39.000Z,
},
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;

exports[`reports getServiceStatus returns a parsed model when the status response is valid 1`] = `
Array [
Object {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/reports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const mockGetReportRequestListByNextToken = createMockHttpClient(

describe('reports', () => {
describe('getReportRequestListByNextToken', () => {
const mockNextToken = new NextToken('GetReportRequestListByNextToken', '123')
const mockNextToken = new NextToken('GetReportRequestList', '123')
const parameters = {
NextToken: mockNextToken,
}
Expand Down

0 comments on commit a0851e5

Please sign in to comment.