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

Commit

Permalink
feat: init recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 8, 2020
1 parent 105415e commit 00cdc9a
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export enum Resource {
Feeds = 'Feeds',
ShipmentInvoicing = 'ShipmentInvoicing',
MerchantFulfillment = 'MerchantFulfillment',
Recommendations = 'Recommendations',
}

export interface ResourceActions {
Expand Down Expand Up @@ -164,6 +165,11 @@ export interface ResourceActions {
| 'GetShipment'
| 'CancelShipment'
| 'GetServiceStatus'
[Resource.Recommendations]:
| 'GetLastUpdatedTimeForRecommendations'
| 'ListRecommendations'
| 'ListRecommendationsByNextToken'
| 'GetServiceStatus'
}

export interface Request {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export * from './sections/products/products'
export * from './sections/products/codec'
export * from './sections/products/type'
export * from './sections/reports'
export * from './sections/recommendations'
export * from './sections/sellers'
export * from './sections/types'
export * from '@scaleleap/amazon-marketplaces'
Expand Down
11 changes: 11 additions & 0 deletions src/mws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FulfillmentInventory } from './sections/fulfillment-inventory'
import { MerchantFulfillment } from './sections/merchant-fulfillment/merchant-fulfillment'
import { Orders } from './sections/orders'
import { Products } from './sections/products/products'
import { Recommendations } from './sections/recommendations'
import { Reports } from './sections/reports'
import { Sellers } from './sections/sellers'
import { ShipmentInvoicing } from './sections/shipment-invoicing'
Expand All @@ -25,6 +26,8 @@ export class MWS {

private _reports!: Reports

private _recommendations!: Recommendations

private _sellers!: Sellers

private _subscriptions!: Subscriptions
Expand Down Expand Up @@ -89,6 +92,14 @@ export class MWS {
return this._products
}

get recommendations() {
if (!this._recommendations) {
this._recommendations = new Recommendations(this.httpClient)
}

return this._recommendations
}

get reports() {
if (!this._reports) {
this._reports = new Reports(this.httpClient)
Expand Down
16 changes: 16 additions & 0 deletions src/sections/recommendations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { HttpClient, Resource } from '../http'
import { getServiceStatusByResource } from './shared'

const RECOMMENDATIONS_API_VERSION = '2013-04-01'

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

async getServiceStatus() {
return getServiceStatusByResource(
this.httpClient,
Resource.Recommendations,
RECOMMENDATIONS_API_VERSION,
)
}
}
19 changes: 19 additions & 0 deletions test/integration/recommendations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Recommendations } from '../../src'
import { Config } from './config'
import { itci } from './it'

const httpClient = new Config().createHttpClient()

/* eslint-disable jest/no-standalone-expect */
describe(`${Recommendations.name}`, () => {
itci('should be able to query service status', async () => {
expect.assertions(1)

const recommendations = new Recommendations(httpClient)

const [response] = await recommendations.getServiceStatus()

expect(response.Status).toMatch(/GREEN|YELLOW|RED/)
})
})
/* eslint-enable jest/no-standalone-expect */
17 changes: 17 additions & 0 deletions test/unit/__snapshots__/recommendations.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`recommendations getServiceStatus returns a parsed model when the status response is valid 1`] = `
Array [
Object {
"Status": "GREEN",
"Timestamp": "2020-05-06T08:22:23.582Z",
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;
20 changes: 20 additions & 0 deletions test/unit/recommendations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ParsingError } from '../../src'
import { mockMwsFail, mockMwsServiceStatus, parsingError } from '../utils'

describe('recommendations', () => {
describe('getServiceStatus', () => {
it('returns a parsed model when the status response is valid', async () => {
expect.assertions(1)

expect(await mockMwsServiceStatus.recommendations.getServiceStatus()).toMatchSnapshot()
})

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

await expect(() => mockMwsFail.recommendations.getServiceStatus()).rejects.toStrictEqual(
new ParsingError(parsingError),
)
})
})
})

0 comments on commit 00cdc9a

Please sign in to comment.