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

Commit

Permalink
fix: prob with incorrect type from codec, add sample args for test
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jun 26, 2020
1 parent 13c4086 commit dcffdec
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/sections/products/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export enum ItemConditionEnum {

const ItemCondition = enumeration(ItemConditionEnum)

const CurrencyCode = enumeration(CurrencyCodeEnum)
const CurrencyCode = enumeration(CurrencyCodeEnum) as Codec<keyof typeof CurrencyCodeEnum>

export enum StatusEnum {
Success = 'Success',
Expand All @@ -54,7 +54,7 @@ const IdType = enumeration(IdTypeEnum)

const MoneyType = Codec.interface({
Amount: optional(number),
CurrencyCode,
CurrencyCode: optional(CurrencyCode),
})

export const PointsCodec = Codec.interface({
Expand Down
2 changes: 1 addition & 1 deletion src/sections/products/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export enum CurrencyCodeEnum {

export interface MoneyType {
Amount: number | undefined
CurrencyCode: CurrencyCodeEnum
CurrencyCode: keyof typeof CurrencyCodeEnum | undefined
}

export interface FeeDetail {
Expand Down
27 changes: 25 additions & 2 deletions test/unit/products.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { ParsingError } from '../../src'
import { GetMatchingProductIdType, ItemCondition } from '../../src/sections/products/type'
import {
FeesEstimateRequest,
GetMatchingProductIdType,
ItemCondition,
MoneyType,
} from '../../src/sections/products/type'
import { createMockHttpClient, mockMwsFail, mockMwsServiceStatus, parsingError } from '../utils'

describe('products', () => {
Expand Down Expand Up @@ -364,13 +369,31 @@ describe('products', () => {
})

describe('getMyFeesEstimate', () => {
const moneyType: MoneyType = {
CurrencyCode: 'USD',
Amount: 1000,
}

const sampleFee: FeesEstimateRequest = {
MarketplaceId: '',
IdType: 'ASIN',
IdValue: 'ASD',
PriceToEstimateFees: {
ListingPrice: moneyType,
},
Identifier: 'request1',
IsAmazonFulfilled: false,
}

it('returns a list fee estimates when the response is valid', async () => {
expect.assertions(1)

const mockGetMyFeesEstimate = createMockHttpClient('products_get_my_fees_estimate')

expect(
await mockGetMyFeesEstimate.products.getMyFeesEstimate({ FeesEstimateRequestList: [] }),
await mockGetMyFeesEstimate.products.getMyFeesEstimate({
FeesEstimateRequestList: [sampleFee],
}),
).toMatchSnapshot()
})

Expand Down

0 comments on commit dcffdec

Please sign in to comment.