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

Commit

Permalink
feat: get lowest offer listings for asin
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed May 28, 2020
1 parent b0095e3 commit 8981198
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 7 deletions.
50 changes: 46 additions & 4 deletions src/sections/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ interface ListMatchingProductsRequestParameters {

const Product = record(string, unknown)

const SingleProductCodec = Codec.interface({
const SingleProductInterface = Codec.interface({
Product,
})

Expand All @@ -178,7 +178,7 @@ interface GetMatchingProductParameters {
[key: string]: string[] | string
}

const GetMatchingProductResult = ensureArray('GetMatchingProductResult', SingleProductCodec)
const GetMatchingProductResult = ensureArray('GetMatchingProductResult', SingleProductInterface)

const GetMatchingProductResponse = Codec.interface({
GetMatchingProductResponse: GetMatchingProductResult,
Expand Down Expand Up @@ -216,7 +216,7 @@ interface GetCompetitivePricingForSkuParameters {

const GetCompetitivePricingForSKUResult = ensureArray(
'GetCompetitivePricingForSKUResult',
SingleProductCodec,
SingleProductInterface,
)

type GetCompetitivePricingForSKUResult = GetInterface<typeof GetCompetitivePricingForSKUResult>
Expand All @@ -227,7 +227,7 @@ const GetCompetitivePricingForSKUResponse = Codec.interface({

const GetCompetitivePricingForASINResult = ensureArray(
'GetCompetitivePricingForASINResult',
SingleProductCodec,
SingleProductInterface,
)

type GetCompetitivePricingForASINResult = GetInterface<typeof GetCompetitivePricingForASINResult>
Expand Down Expand Up @@ -264,6 +264,26 @@ const GetLowestOfferListingsForSKUResponse = Codec.interface({

type GetLowestOfferListingsForSKUResult = GetInterface<typeof GetLowestOfferListingsForSKUResult>

interface GetLowestOfferListingsForAsinParameters {
ASINList: string[]
MarketplaceId: string
ItemCondition?: ItemCondition
}

const GetLowestOfferListingsForASINResult = ensureArray(
'GetLowestOfferListingsForASINResult',
Codec.interface({
AllOfferListingsConsidered: boolean,
Product,
}),
)

type GetLowestOfferListingsForASINResult = GetInterface<typeof GetLowestOfferListingsForASINResult>

const GetLowestOfferListingsForASINResponse = Codec.interface({
GetLowestOfferListingsForASINResponse: GetLowestOfferListingsForASINResult,
})

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

Expand Down Expand Up @@ -409,4 +429,26 @@ export class Products {
},
})
}

async getLowestOfferListingsForAsin(
parameters: GetLowestOfferListingsForAsinParameters,
): Promise<[GetLowestOfferListingsForASINResult, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Products,
version: PRODUCTS_API_VERSION,
action: 'GetLowestOfferListingsForASIN',
parameters: {
'ASINList.ASIN': parameters.ASINList,
MarketplaceId: parameters.MarketplaceId,
ItemCondition: parameters.ItemCondition,
},
})

return GetLowestOfferListingsForASINResponse.decode(response).caseOf({
Right: (x) => [x.GetLowestOfferListingsForASINResponse, meta],
Left: (error) => {
throw new ParsingError(error)
},
})
}
}
116 changes: 116 additions & 0 deletions test/unit/__snapshots__/products.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,122 @@ Array [
]
`;

exports[`products getLowestOfferListingsForAsin returns product and lowest offer listings when response is valid 1`] = `
Array [
Array [
Object {
"AllOfferListingsConsidered": true,
"Product": Object {
"Identifiers": Object {
"MarketplaceASIN": Object {
"ASIN": "B002KT3XQM",
"MarketplaceId": "ATVPDKIKX0DER",
},
},
"LowestOfferListings": Object {
"LowestOfferListing": Array [
Object {
"MultipleOffersAtLowestPrice": "False",
"NumberOfOfferListingsConsidered": 1,
"Price": Object {
"LandedPrice": Object {
"Amount": 32.99,
"CurrencyCode": "USD",
},
"ListingPrice": Object {
"Amount": 28,
"CurrencyCode": "USD",
},
"Shipping": Object {
"Amount": 4.99,
"CurrencyCode": "USD",
},
},
"Qualifiers": Object {
"FulfillmentChannel": "Merchant",
"ItemCondition": "Used",
"ItemSubcondition": "VeryGood",
"SellerPositiveFeedbackRating": "90-94%",
"ShippingTime": Object {
"Max": "0-2 days",
},
"ShipsDomestically": "True",
},
"SellerFeedbackCount": 762,
},
Object {
"MultipleOffersAtLowestPrice": "False",
"NumberOfOfferListingsConsidered": 1,
"Price": Object {
"LandedPrice": Object {
"Amount": 34.27,
"CurrencyCode": "USD",
},
"ListingPrice": Object {
"Amount": 34.27,
"CurrencyCode": "USD",
},
"Shipping": Object {
"Amount": 0,
"CurrencyCode": "USD",
},
},
"Qualifiers": Object {
"FulfillmentChannel": "Amazon",
"ItemCondition": "New",
"ItemSubcondition": "New",
"SellerPositiveFeedbackRating": "98-100%",
"ShippingTime": Object {
"Max": "0-2 days",
},
"ShipsDomestically": "True",
},
"SellerFeedbackCount": 181744,
},
Object {
"MultipleOffersAtLowestPrice": "False",
"NumberOfOfferListingsConsidered": 1,
"Price": Object {
"LandedPrice": Object {
"Amount": 41.18,
"CurrencyCode": "USD",
},
"ListingPrice": Object {
"Amount": 41.18,
"CurrencyCode": "USD",
},
"Shipping": Object {
"Amount": 0,
"CurrencyCode": "USD",
},
},
"Qualifiers": Object {
"FulfillmentChannel": "Amazon",
"ItemCondition": "New",
"ItemSubcondition": "New",
"SellerPositiveFeedbackRating": "95-97%",
"ShippingTime": Object {
"Max": "0-2 days",
},
"ShipsDomestically": "True",
},
"SellerFeedbackCount": 13213,
},
],
},
},
},
],
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": "2020-04-06T10:22:23.582Z",
"requestId": "0",
"timestamp": "2020-05-06T09:22:23.582Z",
},
]
`;

exports[`products getLowestOfferListingsForSku returns product and lowest offer listings when response is valid 1`] = `
Array [
Array [
Expand Down
6 changes: 3 additions & 3 deletions test/unit/products.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ describe('products', () => {
it("throws an error when the response isn't valid", async () => {
expect.assertions(1)

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

Expand Down

0 comments on commit 8981198

Please sign in to comment.