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

Commit

Permalink
feat: init shipmentInvoicing
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 7, 2020
1 parent 5143ac4 commit c7f36ab
Show file tree
Hide file tree
Showing 6 changed files with 73 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 @@ -79,6 +79,7 @@ export enum Resource {
Sellers = 'Sellers',
Subscriptions = 'Subscriptions',
Feeds = 'Feeds',
ShipmentInvoicing = 'ShipmentInvoicing',
}

export interface ResourceActions {
Expand Down Expand Up @@ -151,6 +152,11 @@ export interface ResourceActions {
| 'GetFeedSubmissionCount'
| 'CancelFeedSubmissions'
| 'GetFeedSubmissionResult'
[Resource.ShipmentInvoicing]:
| 'GetFBAOutboundShipmentDetail'
| 'SubmitFBAOutboundShipmentInvoice'
| 'GetFBAOutboundShipmentInvoiceStatus'
| '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 @@ -6,6 +6,7 @@ export * from './sections/finances/finances'
export * from './sections/finances/codec'
export * from './sections/fulfillment-inventory'
export * from './sections/subscriptions'
export * from './sections/shipment-invoicing'
export * from './sections/orders'
export * from './sections/products/products'
export * from './sections/products/codec'
Expand Down
11 changes: 11 additions & 0 deletions src/mws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Orders } from './sections/orders'
import { Products } from './sections/products/products'
import { Reports } from './sections/reports'
import { Sellers } from './sections/sellers'
import { ShipmentInvoicing } from './sections/shipment-invoicing'
import { Subscriptions } from './sections/subscriptions'

export class MWS {
Expand All @@ -25,6 +26,8 @@ export class MWS {

private _subscriptions!: Subscriptions

private _shipmentInvoicing!: ShipmentInvoicing

constructor(private httpClient: HttpClient) {}

get sellers() {
Expand Down Expand Up @@ -83,6 +86,14 @@ export class MWS {
return this._reports
}

get shipmentInvoicing() {
if (!this._shipmentInvoicing) {
this._shipmentInvoicing = new ShipmentInvoicing(this.httpClient)
}

return this._shipmentInvoicing
}

get subscriptions() {
if (!this._subscriptions) {
this._subscriptions = new Subscriptions(this.httpClient)
Expand Down
16 changes: 16 additions & 0 deletions src/sections/shipment-invoicing.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 SELLERS_API_VERSION = '2018-11-01'

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

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

const httpClient = new Config().createHttpClient()

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

const shipmentInvoicing = new ShipmentInvoicing(httpClient)

const [response] = await shipmentInvoicing.getServiceStatus()

expect(response.Status).toMatch(/GREEN|YELLOW|RED/)
})
})
/* eslint-enable jest/no-standalone-expect */
20 changes: 20 additions & 0 deletions test/unit/shipment-invoicing.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('shipmentInvoicing', () => {
describe('getServiceStatus', () => {
it('returns a parsed model when the status response is valid', async () => {
expect.assertions(1)

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

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

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

0 comments on commit c7f36ab

Please sign in to comment.