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

Commit

Permalink
feat: get competitive pricing for sku response api
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed May 26, 2020
1 parent 1642b40 commit ec31452
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/sections/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,25 @@ const GetMatchingProductForIdResponseCodec = Codec.interface({

type GetMatchingProductForIdResponse = GetInterface<typeof GetMatchingProductForIdResponse>

interface GetCompetitivePricingForSkuParameters {
MarketplaceId: string
SellerSKUList: string[]
[key: string]: string | string[]
}

const GetCompetitivePricingForSKUResult = ensureArray(
'GetCompetitivePricingForSKUResult',
Codec.interface({
Product,
}),
)

type GetCompetitivePricingForSKUResult = GetInterface<typeof GetCompetitivePricingForSKUResult>

const GetCompetitivePricingForSKUResponse = Codec.interface({
GetCompetitivePricingForSKUResponse: GetCompetitivePricingForSKUResult,
})

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

Expand Down Expand Up @@ -290,4 +309,25 @@ export class Products {
},
})
}

async getCompetitivePricingForSku(
parameters: GetCompetitivePricingForSkuParameters,
): Promise<[GetCompetitivePricingForSKUResult, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Products,
version: PRODUCTS_API_VERSION,
action: 'GetCompetitivePricingForSKU',
parameters: {
'SellerSKUList.SellerSKU': parameters.SellerSKUList,
MarketplaceId: parameters.MarketplaceId,
},
})

return GetCompetitivePricingForSKUResponse.decode(response).caseOf({
Right: (x) => [x.GetCompetitivePricingForSKUResponse, meta],
Left: (error) => {
throw new ParsingError(error)
},
})
}
}
100 changes: 100 additions & 0 deletions test/unit/__snapshots__/products.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,105 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`products getCompetitivePricingForSku returns product and competitive prices when response is valid 1`] = `
Array [
Array [
Object {
"Product": Object {
"CompetitivePricing": Object {
"CompetitivePrices": Object {
"CompetitivePrice": Array [
Object {
"CompetitivePriceId": 1,
"Price": Object {
"LandedPrice": Object {
"Amount": 40.03,
"CurrencyCode": "USD",
},
"ListingPrice": Object {
"Amount": 40.03,
"CurrencyCode": "USD",
},
"Shipping": Object {
"Amount": 0,
"CurrencyCode": "USD",
},
},
},
Object {
"CompetitivePriceId": 2,
"Price": Object {
"LandedPrice": Object {
"Amount": 30.5,
"CurrencyCode": "USD",
},
"ListingPrice": Object {
"Amount": 30.5,
"CurrencyCode": "USD",
},
"Shipping": Object {
"Amount": 0,
"CurrencyCode": "USD",
},
},
},
],
},
"NumberOfOfferListings": Object {
"OfferListingCount": Array [
296,
145,
151,
],
},
"TradeInValue": Object {
"Amount": 17.05,
"CurrencyCode": "USD",
},
},
"Identifiers": Object {
"MarketplaceASIN": Object {
"ASIN": 1933890517,
"MarketplaceId": "ATVPDKIKX0DER",
},
"SKUIdentifier": Object {
"MarketplaceId": "ATVPDKIKX0DER",
"SellerId": "A1IMEXAMPLEWRC",
"SellerSKU": "SKU2468",
},
},
"SalesRankings": Object {
"SalesRank": Array [
Object {
"ProductCategoryId": "book_display_on_website",
"Rank": 900,
},
Object {
"ProductCategoryId": 271578011,
"Rank": 1,
},
Object {
"ProductCategoryId": 355562011,
"Rank": 8,
},
Object {
"ProductCategoryId": 173516,
"Rank": 25,
},
],
},
},
},
],
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": "2020-04-06T10:22:23.582Z",
"requestId": "0",
"timestamp": "2020-05-06T09:22:23.582Z",
},
]
`;

exports[`products getMatchingProduct returns a matching product when the response is valid 1`] = `
Array [
Object {
Expand Down

0 comments on commit ec31452

Please sign in to comment.