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

Commit

Permalink
test: unit test for competitive pricing for ASIN
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed May 26, 2020
1 parent b5346c5 commit 18d4b83
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<GetCompetitivePricingForASINResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<GetCompetitivePricingForASINResult ASIN="B002KT3XQM" status="Success">
<Product xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>ATVPDKIKX0DER</MarketplaceId>
<ASIN>B002KT3XQM</ASIN>
</MarketplaceASIN>
</Identifiers>
<CompetitivePricing>
<CompetitivePrices>
<CompetitivePrice belongsToRequester="false"
condition="New"
subcondition="New">
<CompetitivePriceId>1</CompetitivePriceId>
<Price>
<LandedPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>34.27</Amount>
</LandedPrice>
<ListingPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>34.27</Amount>
</ListingPrice>
<Shipping>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</Shipping>
</Price>
</CompetitivePrice>
</CompetitivePrices>
<NumberOfOfferListings>
<OfferListingCount condition="Any">11</OfferListingCount>
<OfferListingCount condition="Used">1</OfferListingCount>
<OfferListingCount condition="New">10</OfferListingCount>
</NumberOfOfferListings>
</CompetitivePricing>
<SalesRankings/>
</Product>
</GetCompetitivePricingForASINResult>
<ResponseMetadata>
<RequestId>a8ec20c3-fc88-46e3-a128-EXAMPLE3fcdf</RequestId>
</ResponseMetadata>
</GetCompetitivePricingForASINResponse>
33 changes: 33 additions & 0 deletions test/unit/products.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,46 @@ const mockGetCompetitivePricingForSku = new MWS(
),
)

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

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

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

describe('products', () => {
describe('getCompetitivePricingForASIN', () => {
it('returns product and competitive prices when response is valid', async () => {
expect.assertions(1)

expect(
await mockGetCompetitivePricingForAsin.products.getCompetitivePricingForAsin({
MarketplaceId: '',
ASINList: [],
}),
).toMatchSnapshot()
})

it('throws an error when the response is invalid', async () => {
expect.assertions(1)

await expect(() =>
mockMwsFail.products.getCompetitivePricingForAsin({
MarketplaceId: '',
ASINList: [],
}),
).rejects.toStrictEqual(new ParsingError(parsingError))
})
})

describe('getCompetitivePricingForSku', () => {
it('returns product and competitive prices when response is valid', async () => {
expect.assertions(1)
Expand Down

0 comments on commit 18d4b83

Please sign in to comment.