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

Commit

Permalink
feat: add service status unit and integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed May 29, 2020
1 parent 599197c commit e291f07
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './http'
export * from './mws'
export * from './sections/sellers'
export * from './sections/orders'
export * from './sections/products/products'
export * from './sections/fulfillment-inventory'
export * from './error'
export * from '@scaleleap/amazon-marketplaces'
29 changes: 29 additions & 0 deletions test/integration/products.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { amazonMarketplaces } from '@scaleleap/amazon-marketplaces'

import { HttpClient, Products } from '../../src'
import { Config } from './config'
import { itci } from './it'

const config = new Config()

const httpClient = new HttpClient({
marketplace: amazonMarketplaces.CA,
awsAccessKeyId: config.AWS_ACCESS_KEY_ID,
mwsAuthToken: config.MWS_AUTH_TOKEN,
secretKey: config.SECRET_KEY,
sellerId: config.SELLER_ID,
})

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

const products = new Products(httpClient)

const [response] = await products.getServiceStatus()

expect(response.Status).toMatch(/GREEN|YELLOW|RED/)
})
})
/* eslint-enable jest/no-standalone-expect */
25 changes: 25 additions & 0 deletions test/unit/products.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,34 @@ const mockMwsFail = new MWS(
new HttpClient(httpConfig, () => Promise.resolve({ data: '', headers: {} })),
)

const mockMwsServiceStatus = new MWS(
new HttpClient(httpConfig, () =>
Promise.resolve({
data: getFixture('get_service_status'),
headers,
}),
),
)

const parsingError = 'Expected an object, but received a string with value ""'

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

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

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

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

describe('getLowestPricedOffersForSku', () => {
const parameters = {
MarketplaceId: '',
Expand Down

0 comments on commit e291f07

Please sign in to comment.