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

Commit

Permalink
feat: made getFeedSubmissionCount
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado authored and moltar committed Jun 28, 2020
1 parent 213225a commit d5bb2ec
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 2 deletions.
88 changes: 87 additions & 1 deletion src/sections/feeds.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { boolean, Codec, GetInterface, optional, string } from 'purify-ts'
import { boolean, Codec, GetInterface, number, optional, string } from 'purify-ts'

import { ParsingError } from '../error'
import { HttpClient, RequestMeta, Resource } from '../http'
Expand Down Expand Up @@ -43,9 +43,95 @@ const GetFeedSubmissionListByNextTokenResponse = Codec.interface({
}),
})

export type FeedType =
| '_POST_PRODUCT_DATA_'
| '_POST_INVENTORY_AVAILABILITY_DATA_'
| '_POST_PRODUCT_OVERRIDES_DATA_'
| '_POST_PRODUCT_PRICING_DATA_'
| '_POST_PRODUCT_IMAGE_DATA_'
| '_POST_PRODUCT_RELATIONSHIP_DATA_'
| '_POST_FLAT_FILE_INVLOADER_DATA_'
| '_POST_FLAT_FILE_LISTINGS_DATA_'
| '_POST_FLAT_FILE_BOOKLOADER_DATA_'
| '_POST_FLAT_FILE_CONVERGENCE_LISTINGS_DATA_'
| '_POST_FLAT_FILE_LISTINGS_DATA_'
| '_POST_FLAT_FILE_PRICEANDQUANTITYONLY_UPDATE_DATA_'
| '_POST_UIEE_BOOKLOADER_DATA_'
| '_POST_STD_ACES_DATA_'
| '_POST_ORDER_ACKNOWLEDGEMENT_DATA_'
| '_POST_PAYMENT_ADJUSTMENT_DATA_'
| '_POST_ORDER_FULFILLMENT_DATA_'
| '_POST_INVOICE_CONFIRMATION_DATA_'
| '_POST_EXPECTED_SHIP_DATE_SOD_'
| '_POST_FLAT_FILE_ORDER_ACKNOWLEDGEMENT_DATA_'
| '_POST_FLAT_FILE_PAYMENT_ADJUSTMENT_DATA_'
| '_POST_FLAT_FILE_FULFILLMENT_DATA_'
| '_POST_EXPECTED_SHIP_DATE_SOD_FLAT_FILE_'
| '_POST_FULFILLMENT_ORDER_REQUEST_DATA_'
| '_POST_FULFILLMENT_ORDER_CANCELLATION_REQUEST_DATA_'
| '_POST_FBA_INBOUND_CARTON_CONTENTS_'
| '_POST_FLAT_FILE_FULFILLMENT_ORDER_REQUEST_DATA_'
| '_POST_FLAT_FILE_FULFILLMENT_ORDER_CANCELLATION_REQUEST_DATA_'
| '_POST_FLAT_FILE_FBA_CREATE_INBOUND_PLAN_'
| '_POST_FLAT_FILE_FBA_UPDATE_INBOUND_PLAN_'
| '_POST_FLAT_FILE_FBA_CREATE_REMOVAL_'
| '_RFQ_UPLOAD_FEED_'
| ' _POST_EASYSHIP_DOCUMENTS_'

export type FeedProcessingStatus =
| '_AWAITING_ASYNCHRONOUS_REPLY_'
| '_CANCELLED_'
| '_DONE_'
| '_IN_PROGRESS_'
| '_IN_SAFETY_NET_'
| '_SUBMITTED_'
| '_UNCONFIRMED_'

export interface GetFeedSubmissionCountParameters {
FeedTypeList?: FeedType[]
FeedProcessingStatusList?: FeedProcessingStatus[]
SubmittedFromDate?: Date
SubmittedToDate?: Date
}

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

export type GetFeedSubmissionCount = GetInterface<typeof GetFeedSubmissionCount>

const GetFeedSubmissionCountResponse = Codec.interface({
GetFeedSubmissionCountResponse: Codec.interface({
GetFeedSubmissionCountResult: GetFeedSubmissionCount,
}),
})

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

async getFeedSubmissionCount(
parameters: GetFeedSubmissionCountParameters = {},
): Promise<[GetFeedSubmissionCount, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Feeds,
version: FEEDS_API_VERSION,
action: 'GetFeedSubmissionListByNextToken',
parameters: {
'FeedTypeList.Type': parameters.FeedTypeList,
'FeedProcessingStatusList.Status': parameters.FeedProcessingStatusList,
SubmittedFromDate: parameters.SubmittedFromDate?.toISOString(),
SubmittedToDate: parameters.SubmittedToDate?.toISOString(),
},
})

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

async getFeedSubmissionListByNextToken(
nextToken: NextToken<'GetFeedSubmissionList'>,
): Promise<[GetFeedSubmissionList, RequestMeta]> {
Expand Down
15 changes: 15 additions & 0 deletions test/unit/__snapshots__/feeds.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`feeds getFeedSubmissionCount returns count of total number of feed submissions if succesful 1`] = `
Array [
Object {
"Count": 463,
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;

exports[`feeds getFeedSubmissionList returns a next token and feed submission info if succesful 1`] = `
Array [
Object {
Expand Down
20 changes: 19 additions & 1 deletion test/unit/feeds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('feeds', () => {
expect(await mockGetFeedSubmissionList.feeds.getFeedSubmissionList()).toMatchSnapshot()
})

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

await expect(() => mockMwsFail.feeds.getFeedSubmissionList()).rejects.toStrictEqual(
Expand Down Expand Up @@ -42,4 +42,22 @@ describe('feeds', () => {
).rejects.toStrictEqual(new ParsingError(parsingError))
})
})

describe('getFeedSubmissionCount', () => {
it('returns count of total number of feed submissions if succesful', async () => {
expect.assertions(1)

const mockGetFeedSubmissionCount = createMockHttpClient('feeds_get_feed_submission_count')

expect(await mockGetFeedSubmissionCount.feeds.getFeedSubmissionCount()).toMatchSnapshot()
})

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

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

0 comments on commit d5bb2ec

Please sign in to comment.