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 schedule count
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jun 12, 2020
1 parent 41ac296 commit a1c07f7
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 74 deletions.
38 changes: 36 additions & 2 deletions src/sections/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ const GetReportRequestListResult = Codec.interface({
NextToken: optional(nextTokenCodec('GetReportRequestList')),
HasNext: optional(boolean),
ReportRequestInfo: optional(oneOf([array(ReportRequestInfo), ReportRequestInfo, exactly('')])),
// This does not work for some reason
// ReportRequestInfo: ensureArray('ReportRequestInfo', ReportRequestInfo),
})

type GetReportRequestListResult = GetInterface<typeof GetReportRequestListResult>
Expand Down Expand Up @@ -294,9 +292,45 @@ const GetReportScheduleListResponse = Codec.interface({
}),
})

interface GetReportScheduleCountParameters {
ReportTypeList?: ReportType
}

const GetReportScheduleCount = Codec.interface({
Count: number,
})

type GetReportScheduleCount = GetInterface<typeof GetReportScheduleCount>

const GetReportScheduleCountResponse = Codec.interface({
GetReportScheduleCountResponse: Codec.interface({
GetReportScheduleCountResult: GetReportScheduleCount,
}),
})

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

async getReportScheduleCount(
parameters: GetReportScheduleCountParameters,
): Promise<[GetReportScheduleCount, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Reports,
version: REPORTS_API_VERSION,
action: 'GetReportScheduleList',
parameters: {
'ReportTypeList.Type': parameters.ReportTypeList,
},
})

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

/**
* getReportScheduleListByNextToken cannot be called
* http://docs.developer.amazonservices.com/en_CA/reports/Reports_GetReportScheduleListByNextToken.html
Expand Down
135 changes: 63 additions & 72 deletions test/unit/__snapshots__/reports.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ Array [
Object {
"Count": 1,
"ReportRequestInfo": Object {
"CompletedDate": undefined,
"EndDate": 2009-02-13T02:10:39.000Z,
"GeneratedReportId": undefined,
"ReportProcessingStatus": "_CANCELLED_",
"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,
},
},
Expand Down Expand Up @@ -78,7 +75,6 @@ Array [
},
"ReportInfo": Object {
"Acknowledged": false,
"AcknowledgedDate": undefined,
"AvailableDate": 2009-02-10T09:22:33.000Z,
"ReportId": "898899473",
"ReportRequestId": "2278662938",
Expand All @@ -99,43 +95,37 @@ exports[`reports getReportList should properly return report list for multiple r
Array [
Object {
"HasNext": false,
"NextToken": undefined,
"ReportInfo": Array [
Object {
"Acknowledged": false,
"AcknowledgedDate": undefined,
"AvailableDate": 2020-06-11T07:44:32.000Z,
"ReportId": "21175694446018424",
"ReportRequestId": "51781018424",
"ReportType": "_GET_MERCHANT_LISTINGS_DATA_",
},
Object {
"Acknowledged": false,
"AcknowledgedDate": undefined,
"AvailableDate": 2020-06-11T07:41:56.000Z,
"ReportId": "21178489344018424",
"ReportRequestId": "51780018424",
"ReportType": "_GET_FLAT_FILE_OPEN_LISTINGS_DATA_",
},
Object {
"Acknowledged": false,
"AcknowledgedDate": undefined,
"AvailableDate": 2020-05-22T08:16:14.000Z,
"ReportId": "20812705939018404",
"ReportRequestId": "51778018404",
"ReportType": "_GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_",
},
Object {
"Acknowledged": false,
"AcknowledgedDate": undefined,
"AvailableDate": 2020-04-24T08:10:54.000Z,
"ReportId": "20303555135018376",
"ReportRequestId": "51777018376",
"ReportType": "_GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_",
},
Object {
"Acknowledged": false,
"AcknowledgedDate": undefined,
"AvailableDate": 2020-03-13T08:21:03.000Z,
"ReportId": "19571121666018336",
"ReportRequestId": "51776018334",
Expand Down Expand Up @@ -163,7 +153,6 @@ Array [
},
"ReportInfo": Object {
"Acknowledged": false,
"AcknowledgedDate": undefined,
"AvailableDate": 2009-02-10T09:22:33.000Z,
"ReportId": "898899473",
"ReportRequestId": "2278662938",
Expand Down Expand Up @@ -229,83 +218,78 @@ Array [
exports[`reports getReportRequestList returns report request info succesfully for responses with multiple reports 1`] = `
Array [
Object {
"HasNext": true,
"NextToken": NextToken {
"action": "GetReportRequestList",
"token": "2YgYW55IPQhcm5hbCBwbGVhc3VyZS4=",
},
"HasNext": false,
"ReportRequestInfo": Array [
Object {
"CompletedDate": 2011-02-17T23:44:48.000Z,
"EndDate": 2011-02-13T02:10:39.000Z,
"GeneratedReportId": "3538561173",
"CompletedDate": 2020-06-11T07:44:32.000Z,
"EndDate": 2020-06-11T07:44:22.000Z,
"GeneratedReportId": "21175694446018424",
"ReportProcessingStatus": "_DONE_",
"ReportRequestId": "2291326454",
"ReportRequestId": "51781018424",
"ReportType": "_GET_MERCHANT_LISTINGS_DATA_",
"Scheduled": false,
"StartDate": 2011-01-21T02:10:39.000Z,
"StartedProcessingDate": 2011-02-17T23:44:43.000Z,
"SubmittedDate": 2011-02-17T23:44:09.000Z,
"StartDate": 2020-06-11T07:44:22.000Z,
"StartedProcessingDate": 2020-06-11T07:44:25.000Z,
"SubmittedDate": 2020-06-11T07:44:22.000Z,
},
Object {
"CompletedDate": 2011-02-17T23:44:48.000Z,
"EndDate": 2011-02-13T02:10:39.000Z,
"GeneratedReportId": "3538561173",
"CompletedDate": 2020-06-11T07:41:56.000Z,
"EndDate": 2020-06-11T07:41:44.000Z,
"GeneratedReportId": "21178489344018424",
"ReportProcessingStatus": "_DONE_",
"ReportRequestId": "2291326454",
"ReportType": "_GET_MERCHANT_LISTINGS_DATA_",
"ReportRequestId": "51780018424",
"ReportType": "_GET_FLAT_FILE_OPEN_LISTINGS_DATA_",
"Scheduled": false,
"StartDate": 2011-01-21T02:10:39.000Z,
"StartedProcessingDate": 2011-02-17T23:44:43.000Z,
"SubmittedDate": 2011-02-17T23:44:09.000Z,
"StartDate": 2020-06-11T07:41:44.000Z,
"StartedProcessingDate": 2020-06-11T07:41:48.000Z,
"SubmittedDate": 2020-06-11T07:41:44.000Z,
},
Object {
"CompletedDate": 2011-02-17T23:44:48.000Z,
"EndDate": 2011-02-13T02:10:39.000Z,
"GeneratedReportId": "3538561173",
"ReportProcessingStatus": "_DONE_",
"ReportRequestId": "2291326454",
"ReportType": "_GET_MERCHANT_LISTINGS_DATA_",
"CompletedDate": 2020-06-11T07:40:59.000Z,
"EndDate": 2020-06-11T07:40:49.000Z,
"ReportProcessingStatus": "_DONE_NO_DATA_",
"ReportRequestId": "51779018424",
"ReportType": "_GET_FLAT_FILE_ORDERS_DATA_",
"Scheduled": false,
"StartDate": 2011-01-21T02:10:39.000Z,
"StartedProcessingDate": 2011-02-17T23:44:43.000Z,
"SubmittedDate": 2011-02-17T23:44:09.000Z,
"StartDate": 2020-06-10T07:40:49.000Z,
"StartedProcessingDate": 2020-06-11T07:40:52.000Z,
"SubmittedDate": 2020-06-11T07:40:49.000Z,
},
Object {
"CompletedDate": 2011-02-17T23:44:48.000Z,
"EndDate": 2011-02-13T02:10:39.000Z,
"GeneratedReportId": "3538561173",
"CompletedDate": 2020-05-22T08:16:14.000Z,
"EndDate": 2020-05-22T07:52:49.000Z,
"GeneratedReportId": "20812705939018404",
"ReportProcessingStatus": "_DONE_",
"ReportRequestId": "2291326454",
"ReportType": "_GET_MERCHANT_LISTINGS_DATA_",
"ReportRequestId": "51778018404",
"ReportType": "_GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_",
"Scheduled": false,
"StartDate": 2011-01-21T02:10:39.000Z,
"StartedProcessingDate": 2011-02-17T23:44:43.000Z,
"SubmittedDate": 2011-02-17T23:44:09.000Z,
"StartDate": 2020-04-24T07:52:49.000Z,
"StartedProcessingDate": 2020-05-22T08:16:14.000Z,
"SubmittedDate": 2020-05-22T08:16:14.000Z,
},
Object {
"CompletedDate": 2011-02-17T23:44:48.000Z,
"EndDate": 2011-02-13T02:10:39.000Z,
"GeneratedReportId": "3538561173",
"CompletedDate": 2020-04-24T08:10:53.000Z,
"EndDate": 2020-04-24T07:52:49.000Z,
"GeneratedReportId": "20303555135018376",
"ReportProcessingStatus": "_DONE_",
"ReportRequestId": "2291326454",
"ReportType": "_GET_MERCHANT_LISTINGS_DATA_",
"ReportRequestId": "51777018376",
"ReportType": "_GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_",
"Scheduled": false,
"StartDate": 2011-01-21T02:10:39.000Z,
"StartedProcessingDate": 2011-02-17T23:44:43.000Z,
"SubmittedDate": 2011-02-17T23:44:09.000Z,
"StartDate": 2020-03-13T07:52:49.000Z,
"StartedProcessingDate": 2020-04-24T08:10:53.000Z,
"SubmittedDate": 2020-04-24T08:10:53.000Z,
},
Object {
"CompletedDate": 2011-02-17T23:44:48.000Z,
"EndDate": 2011-02-13T02:10:39.000Z,
"GeneratedReportId": "3538561173",
"CompletedDate": 2020-03-13T08:21:03.000Z,
"EndDate": 2020-03-13T07:52:49.000Z,
"GeneratedReportId": "19571121666018336",
"ReportProcessingStatus": "_DONE_",
"ReportRequestId": "2291326454",
"ReportType": "_GET_MERCHANT_LISTINGS_DATA_",
"ReportRequestId": "51776018334",
"ReportType": "_GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_",
"Scheduled": false,
"StartDate": 2011-01-21T02:10:39.000Z,
"StartedProcessingDate": 2011-02-17T23:44:43.000Z,
"SubmittedDate": 2011-02-17T23:44:09.000Z,
"StartDate": 2020-02-14T07:52:49.000Z,
"StartedProcessingDate": 2020-03-13T08:21:03.000Z,
"SubmittedDate": 2020-03-13T08:21:03.000Z,
},
],
},
Expand All @@ -328,15 +312,12 @@ Array [
"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,
},
},
Expand All @@ -350,6 +331,21 @@ Array [
]
`;

exports[`reports getReportScheduleCount returns a count of schedule reports if succesful 1`] = `
Array [
Object {
"Count": 18,
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;

exports[`reports getReportScheduleList returns detailed information about a report schedule if succesful 1`] = `
Array [
Object {
Expand All @@ -361,7 +357,6 @@ Array [
"ReportSchedule": Object {
"ReportType": "_GET_ORDERS_DATA_",
"Schedule": "_30_DAYS_",
"ScheduleDate": undefined,
},
},
Object {
Expand All @@ -381,7 +376,6 @@ Array [
"ReportSchedule": Object {
"ReportType": "_GET_ORDERS_DATA_",
"Schedule": "_30_DAYS_",
"ScheduleDate": undefined,
},
},
Object {
Expand All @@ -397,15 +391,12 @@ Array [
exports[`reports requestReport returns a parsed model when the response is valid 1`] = `
Array [
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 {
Expand Down

0 comments on commit a1c07f7

Please sign in to comment.