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

Commit

Permalink
feat: made getFeedSubmissionsList and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado authored and moltar committed Jun 28, 2020
1 parent 1c143e8 commit cf2c0f2
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
55 changes: 54 additions & 1 deletion src/sections/feeds.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,58 @@
import { HttpClient } from '../http'
import { boolean, Codec, GetInterface, optional, unknown } from 'purify-ts'

import { ParsingError } from '../error'
import { HttpClient, RequestMeta, Resource } from '../http'
import { nextToken as nextTokenCodec } from '../parsing'

const FEEDS_API_VERSION = '2009-01-01'
interface GetFeedSubmissionListParameters {
FeedSubmissionIdList?: string[]
MaxCount?: number
FeedTypeList?: string[]
FeedProcessingStatusList?: string[]
SubmittedFromDate?: Date
SubmittedToDate?: Date
}

const GetFeedSubmissionList = Codec.interface({
HasToken: optional(boolean),
NextToken: optional(nextTokenCodec('GetFeedSubmissionList')),
FeedSubmissionInfo: optional(unknown),
})

type GetFeedSubmissionList = GetInterface<typeof GetFeedSubmissionList>

const GetFeedSubmissionListResponse = Codec.interface({
GetFeedSubmissionListResponse: Codec.interface({
GetFeedSubmissionListResult: GetFeedSubmissionList,
}),
})

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

async getFeedSubmissionList(
parameters: GetFeedSubmissionListParameters = {},
): Promise<[GetFeedSubmissionList, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Feeds,
version: FEEDS_API_VERSION,
action: 'GetFeedSubmissionList',
parameters: {
'FeedSubmissionIdList.Id': parameters.FeedSubmissionIdList,
MaxCount: parameters.MaxCount,
'FeedTypeList.Type': parameters.FeedTypeList,
'FeedProcessingStatusList.Status': parameters.FeedProcessingStatusList,
SubmittedFromDate: parameters.SubmittedFromDate?.toISOString(),
SubmittedToDate: parameters.SubmittedToDate?.toISOString(),
},
})

return GetFeedSubmissionListResponse.decode(response).caseOf({
Right: (x) => [x.GetFeedSubmissionListResponse.GetFeedSubmissionListResult, meta],
Left: (error) => {
throw new ParsingError(error)
},
})
}
}
25 changes: 25 additions & 0 deletions test/unit/__snapshots__/feeds.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`feeds getFeedSubmissionList returns a next token and feed submission info if succesful 1`] = `
Array [
Object {
"FeedSubmissionInfo": Object {
"FeedProcessingStatus": "_SUBMITTED_",
"FeedSubmissionId": 2291326430,
"FeedType": "_POST_PRODUCT_DATA_",
"SubmittedDate": "2009-02-20T02:10:35+00:00",
},
"NextToken": NextToken {
"action": "GetFeedSubmissionList",
"token": "2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=",
},
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;
2 changes: 1 addition & 1 deletion test/unit/feeds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('feeds', () => {
it('throws a parsing error when the response is not valid', async () => {
expect.assertions(1)

await expect(() => mockMwsFail.feeds.getFeedSubmissionList()()).rejects.toStrictEqual(
await expect(() => mockMwsFail.feeds.getFeedSubmissionList()).rejects.toStrictEqual(
new ParsingError(parsingError),
)
})
Expand Down

0 comments on commit cf2c0f2

Please sign in to comment.