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

Commit

Permalink
feat: made getLastUpdatedTimeForRecommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 8, 2020
1 parent 40dfc26 commit c33b71c
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
51 changes: 50 additions & 1 deletion src/sections/recommendations.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,60 @@
import { HttpClient, Resource } from '../http'
import { Codec, GetInterface } from 'purify-ts'

import { ParsingError } from '../error'
import { HttpClient, RequestMeta, Resource } from '../http'
import { mwsDate } from '../parsing'
import { getServiceStatusByResource } from './shared'

const RECOMMENDATIONS_API_VERSION = '2013-04-01'

interface GetLastUpdatedTimeForRecommendationsParameters {
MarketplaceId: string
}

const GetLastUpdatedTimeForRecommendations = Codec.interface({
InventoryRecommendationsLastUpdated: mwsDate,
PricingRecommendationsLastUpdated: mwsDate,
FulfillmentRecommendationsLastUpdated: mwsDate,
GlobalSellingRecommendationsLastUpdated: mwsDate,
AdvertisingRecommendationsLastUpdated: mwsDate,
})

type GetLastUpdatedTimeForRecommendations = GetInterface<
typeof GetLastUpdatedTimeForRecommendations
>

const GetLastUpdatedTimeForRecommendationsResponse = Codec.interface({
GetLastUpdatedTimeForRecommendationsResponse: Codec.interface({
GetLastUpdatedTimeForRecommendationsResult: GetLastUpdatedTimeForRecommendations,
}),
})

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

async getLastUpdatedTimeForRecommendations(
parameters: GetLastUpdatedTimeForRecommendationsParameters,
): Promise<[GetLastUpdatedTimeForRecommendations, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Recommendations,
version: RECOMMENDATIONS_API_VERSION,
action: 'GetLastUpdatedTimeForRecommendations',
parameters: {
MarketplaceId: parameters.MarketplaceId,
},
})

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

async getServiceStatus() {
return getServiceStatusByResource(
this.httpClient,
Expand Down
19 changes: 19 additions & 0 deletions test/unit/__snapshots__/recommendations.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`recommendations getLastUpdatedTimeForRecommendations returns last updated time for recommendations if succesful 1`] = `
Array [
Object {
"AdvertisingRecommendationsLastUpdated": 1969-07-21T02:56:03.000Z,
"FulfillmentRecommendationsLastUpdated": 1969-07-21T02:56:03.000Z,
"GlobalSellingRecommendationsLastUpdated": 1969-07-21T02:56:03.000Z,
"InventoryRecommendationsLastUpdated": 1969-07-21T02:56:03.000Z,
"PricingRecommendationsLastUpdated": 1969-07-21T02:56:03.000Z,
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;

exports[`recommendations getServiceStatus returns a parsed model when the status response is valid 1`] = `
Array [
Object {
Expand Down

0 comments on commit c33b71c

Please sign in to comment.