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

Commit

Permalink
feat: add get matching product api
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed May 26, 2020
1 parent 733fa12 commit c8a8941
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 6 deletions.
36 changes: 36 additions & 0 deletions src/sections/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,24 @@ const ListMatchingProductsResponse = Codec.interface({

type ListMatchingProducts = GetInterface<typeof ListMatchingProducts>

interface GetMatchingProductParameters {
ASINList: string[]
MarketplaceId: string
[key: string]: string[] | string
}

const MatchingProduct = Codec.interface({
Product,
})

const GetMatchingProductResponse = Codec.interface({
GetMatchingProductResponse: Codec.interface({
GetMatchingProductResult: MatchingProduct,
}),
})

type MatchingProduct = GetInterface<typeof MatchingProduct>

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

Expand Down Expand Up @@ -206,4 +224,22 @@ export class Products {
},
})
}

async getMatchingProduct(
parameters: GetMatchingProductParameters,
): Promise<[MatchingProduct, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Products,
version: PRODUCTS_API_VERSION,
action: 'GetMatchingProduct',
parameters,
})

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

exports[`products getMatchingProduct returns a matching product when the response is valid 1`] = `
Array [
Object {
"Product": Object {
"AttributeSets": Object {
"ns2:ItemAttributes": Object {
"ns2:Binding": "Apparel",
"ns2:Brand": "Pearl iZUMi",
"ns2:Department": "mens",
"ns2:Feature": Array [
"Select transfer fabric sets the benchmark for moisture transfer and
four-way performance stretch",
"6-Panel anatomic design for superior, chafe-free comfort, UPF 50+ sun
protection",
"Comfortable silicone leg grippers keep shorts in place,
moisture-wicking, antimicrobial properties",
"Tour 3D Chamois is male-specific and non-chafing with padding in
key areas",
"86 percent nylon, 14% spandex, 9-Inch inseam",
],
"ns2:ItemDimensions": Object {
"ns2:Height": 2,
"ns2:Length": 9,
"ns2:Width": 9,
},
"ns2:Label": "Pearl iZUMi",
"ns2:ListPrice": Object {
"ns2:Amount": 50,
"ns2:CurrencyCode": "USD",
},
"ns2:Manufacturer": "Pearl iZUMi",
"ns2:Model": 275,
"ns2:PackageDimensions": Object {
"ns2:Height": 2.8,
"ns2:Length": 9.75,
"ns2:Weight": 0.4,
"ns2:Width": 8.4,
},
"ns2:PackageQuantity": 1,
"ns2:PartNumber": 275,
"ns2:ProductGroup": "Apparel",
"ns2:ProductTypeName": "SHORTS",
"ns2:Publisher": "Pearl iZUMi",
"ns2:SmallImage": Object {
"ns2:Height": 75,
"ns2:URL": "http://ecx.images-amazon.com/images/I/41ty3Sn%2BU8L._SL75_.jpg",
"ns2:Width": 58,
},
"ns2:Studio": "Pearl iZUMi",
"ns2:Title": "Pearl iZUMi Men's Quest Cycling Short",
},
},
"Identifiers": Object {
"MarketplaceASIN": Object {
"ASIN": "B002KT3XRQ",
"MarketplaceId": "ATVPDKIKX0DER",
},
},
"Relationships": Object {
"ns2:VariationChild": Array [
Object {
"Identifiers": Object {
"MarketplaceASIN": Object {
"ASIN": "B002KT3XQC",
"MarketplaceId": "ATVPDKIKX0DER",
},
},
"ns2:Color": "Black",
"ns2:Size": "Small",
},
Object {
"Identifiers": Object {
"MarketplaceASIN": Object {
"ASIN": "B002KT3XQW",
"MarketplaceId": "ATVPDKIKX0DER",
},
},
"ns2:Color": "Black",
"ns2:Size": "Medium",
},
Object {
"Identifiers": Object {
"MarketplaceASIN": Object {
"ASIN": "B002KT3XQM",
"MarketplaceId": "ATVPDKIKX0DER",
},
},
"ns2:Color": "Black",
"ns2:Size": "Large",
},
Object {
"Identifiers": Object {
"MarketplaceASIN": Object {
"ASIN": "B002KT3XR6",
"MarketplaceId": "ATVPDKIKX0DER",
},
},
"ns2:Color": "Black",
"ns2:Size": "X-Large",
},
Object {
"Identifiers": Object {
"MarketplaceASIN": Object {
"ASIN": "B002KT3XRG",
"MarketplaceId": "ATVPDKIKX0DER",
},
},
"ns2:Color": "Black",
"ns2:Size": "XX-Large",
},
],
},
"SalesRankings": Object {
"SalesRank": Array [
Object {
"ProductCategoryId": "apparel_display_on_website",
"Rank": 159,
},
Object {
"ProductCategoryId": 2420095011,
"Rank": 1,
},
Object {
"ProductCategoryId": 2611189011,
"Rank": 4,
},
],
},
},
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": "2020-04-06T10:22:23.582Z",
"requestId": "0",
"timestamp": "2020-05-06T09:22:23.582Z",
},
]
`;

exports[`products getMyFeesEstimate returns a list fee estimates when the response is valid 1`] = `
Array [
Object {
Expand Down
12 changes: 6 additions & 6 deletions test/unit/products.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ describe('products', () => {
ASINList: [],
}),
).toMatchSnapshot()
})

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

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

Expand Down

0 comments on commit c8a8941

Please sign in to comment.