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

Commit

Permalink
feat: create getFeedSubmissionList
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado authored and moltar committed Jun 28, 2020
1 parent a03d3ad commit 61ce9a3
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 4 deletions.
40 changes: 40 additions & 0 deletions src/sections/feeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Codec,
exactly,
GetInterface,
Left,
number,
oneOf,
optional,
Expand Down Expand Up @@ -136,9 +137,48 @@ const CancelFeedSubmissionsResponse = Codec.interface({
}),
})

const FeedSubmission = string

export type FeedSubmission = GetInterface<typeof FeedSubmission>

const GetFeedSubmissionResultResponse = Codec.custom<string>({
decode: (feed) => {
if (typeof feed === 'string' && feed.length > 0) {
return string.decode(feed)
}

return Left('Expected feed to have length of more than 0')
},
encode: (feed) => feed,
})

interface GetFeedSubmissionResultParameters {
FeedSubmissionId: string
}

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

async getFeedSubmissionResult(
parameters: GetFeedSubmissionResultParameters,
): Promise<[FeedSubmission, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Feeds,
version: FEEDS_API_VERSION,
action: 'GetFeedSubmissionResult',
parameters: {
FeedSubmissionId: parameters.FeedSubmissionId,
},
})

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

async cancelFeedSubmissions(
parameters: CancelFeedSubmissionsParameters = {},
): Promise<[CancelFeedSubmissions, RequestMeta]> {
Expand Down
13 changes: 13 additions & 0 deletions test/unit/__fixtures__/feeds_get_feed_submission_result.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.02</DocumentVersion>
<MerchantIdentifier>T_M_GOOD_83835495</MerchantIdentifier>
</Header>
<MessageType>ProcessingReport</MessageType>
<Message>
<MessageID>1</MessageID>
<ProcessingReport>
<DocumentTransactionID>4319742521</DocumentTransactionID>
</ProcessingReport>
</Message>
</AmazonEnvelope>
25 changes: 25 additions & 0 deletions test/unit/__snapshots__/feeds.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,28 @@ Array [
},
]
`;

exports[`feeds getFeedSubmissionResult returns an XML file when succesful 1`] = `
Array [
"<AmazonEnvelope xmlns:xsi=\\"http://www.w3.org/2001/XMLSchema-instance\\" xsi:noNamespaceSchemaLocation=\\"amzn-envelope.xsd\\">
<Header>
<DocumentVersion>1.02</DocumentVersion>
<MerchantIdentifier>T_M_GOOD_83835495</MerchantIdentifier>
</Header>
<MessageType>ProcessingReport</MessageType>
<Message>
<MessageID>1</MessageID>
<ProcessingReport>
<DocumentTransactionID>4319742521</DocumentTransactionID>
</ProcessingReport>
</Message>
</AmazonEnvelope>",
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;
12 changes: 8 additions & 4 deletions test/unit/feeds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ import { createMockHttpClient, mockMwsFail, parsingError } from '../utils'

describe('feeds', () => {
describe('getFeedSubmissionResult', () => {
const parameters = { FeedSubmissionId: '' }

it('returns an XML file when succesful', async () => {
expect.assertions(1)

const mockGetFeedSubmissionResult = createMockHttpClient('feeds_get_feed_submission_result')

expect(await mockGetFeedSubmissionResult.feeds.getFeedSubmissionResult()).toMatchSnapshot()
expect(
await mockGetFeedSubmissionResult.feeds.getFeedSubmissionResult(parameters),
).toMatchSnapshot()
})

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

await expect(() => mockMwsFail.feeds.getFeedSubmissionResult()).rejects.toStrictEqual(
new ParsingError(parsingError),
)
await expect(() =>
mockMwsFail.feeds.getFeedSubmissionResult(parameters),
).rejects.toStrictEqual(new ParsingError('Expected feed to have length of more than 0'))
})
})

Expand Down

0 comments on commit 61ce9a3

Please sign in to comment.