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

Commit

Permalink
fix: fix issue with get matching product for id
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jun 4, 2020
1 parent c3e1665 commit 6d6bbe6
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 212 deletions.
98 changes: 50 additions & 48 deletions src/error-codec.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,57 @@
import { Codec, exactly, oneOf, optional, string } from 'purify-ts/Codec'

export const Error = Codec.interface({
Type: string,
Code: oneOf(
([
'InputStreamDisconnected',
'InvalidParameterValue',
'AccessDenied',
'InvalidAccessKeyId',
'SignatureDoesNotMatch',
'InvalidAddress',
'InternalError',
'Internal Error',
'QuotaExceeded',
'RequestThrottled',
'ResourceNotFound',
'ScheduledPackageAlreadyExists',
'RegionNotSupported',
'ScheduleWindowExpired',
'InvalidOrderState',
'PickupSlotNotAvailable',
'AccessToFeedProcessingResultDenied',
'ContentMD5Missing',
'ContentMD5DoesNotMatch',
'FeedCanceled',
'FeedProcessingResultNoLongerAvailable',
'FeedProcessingResultNotReady',
'InputDataError',
'InvalidFeedSubmissionId',
'InvalidFeedType',
'InvalidRequest',
'NonRetriableInternalError',
'RetriableInternalError',
'AccessToReportDenied',
'InvalidReportId',
'InvalidReportType',
'InvalidScheduleFrequency',
'ReportNoLongerAvailable',
'ReportNotReady',
'DependencyFatalException',
'DependencyRetriableException',
'DependencyUnauthorizedException',
'InternalErrorFatalException',
'InvalidInputFatalException',
] as const).map((element) => exactly(element)),
),
Message: string,
Detail: optional(string),
})

export const MWSApiError = Codec.interface({
ErrorResponse: Codec.interface({
Error: Codec.interface({
Type: string,
Code: oneOf(
([
'InputStreamDisconnected',
'InvalidParameterValue',
'AccessDenied',
'InvalidAccessKeyId',
'SignatureDoesNotMatch',
'InvalidAddress',
'InternalError',
'Internal Error',
'QuotaExceeded',
'RequestThrottled',
'ResourceNotFound',
'ScheduledPackageAlreadyExists',
'RegionNotSupported',
'ScheduleWindowExpired',
'InvalidOrderState',
'PickupSlotNotAvailable',
'AccessToFeedProcessingResultDenied',
'ContentMD5Missing',
'ContentMD5DoesNotMatch',
'FeedCanceled',
'FeedProcessingResultNoLongerAvailable',
'FeedProcessingResultNotReady',
'InputDataError',
'InvalidFeedSubmissionId',
'InvalidFeedType',
'InvalidRequest',
'NonRetriableInternalError',
'RetriableInternalError',
'AccessToReportDenied',
'InvalidReportId',
'InvalidReportType',
'InvalidScheduleFrequency',
'ReportNoLongerAvailable',
'ReportNotReady',
'DependencyFatalException',
'DependencyRetriableException',
'DependencyUnauthorizedException',
'InternalErrorFatalException',
'InvalidInputFatalException',
] as const).map((element) => exactly(element)),
),
Message: string,
Detail: optional(string),
}),
Error,
RequestID: optional(string),
RequestId: optional(string),
}),
Expand Down
10 changes: 9 additions & 1 deletion src/sections/products/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import {
GetInterface,
lazy,
number,
oneOf,
optional,
record,
string,
unknown,
} from 'purify-ts'

import { Error } from '../../error-codec'
import { ensureArray, ensureString, mwsDate, oneOfEnum } from '../../parsing'
import {
FeeDetail as FeeDetailInterface,
Expand Down Expand Up @@ -152,10 +154,16 @@ export const GetMatchingProductResponse = Codec.interface({
GetMatchingProductResponse: GetMatchingProductResult,
})

const MatchingProductForId = Codec.interface({
const ProductsCodec = Codec.interface({
Products: ensureArray('Product', Product),
})

const ErrorCodec = Codec.interface({
Error,
})

const MatchingProductForId = oneOf([ProductsCodec, ErrorCodec])

export const GetMatchingProductForIdResponse = ensureArray(
'GetMatchingProductForIdResult',
MatchingProductForId,
Expand Down
187 changes: 24 additions & 163 deletions test/unit/__snapshots__/products.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,14 @@ Array [
exports[`products getMatchingProductForId returns a matching product when the response is valid 1`] = `
Array [
Array [
Object {
"Error": Object {
"Code": "InvalidParameterValue",
"Detail": undefined,
"Message": "Invalid ISBN identifier 0439708623 for marketplace ATVPDKIKX0DER",
"Type": "Sender",
},
},
Object {
"Products": Array [
Object {
Expand All @@ -736,28 +744,28 @@ Array [
"Babenko, Dmitry",
],
"ns2:Binding": "Paperback",
"ns2:Brand": "Marmanis, Haralambos/ Babenko, Dmitry",
"ns2:Edition": 1,
"ns2:IsEligibleForTradeIn": true,
"ns2:ItemDimensions": Object {
"ns2:Height": 9.17,
"ns2:Length": 7.36,
"ns2:Weight": 1.4,
"ns2:Width": 0.75,
"ns2:Height": 9.25,
"ns2:Length": 7.38,
"ns2:Weight": 1.38,
"ns2:Width": 0.73,
},
"ns2:Label": "Manning Publications",
"ns2:Languages": Object {
"ns2:Language": Array [
Object {
"ns2:Name": "english",
"ns2:Type": "Unknown",
"ns2:Type": "Published",
},
Object {
"ns2:Name": "english",
"ns2:Type": "Original Language",
},
Object {
"ns2:Name": "english",
"ns2:Type": "Published",
"ns2:Type": "Unknown",
},
],
},
Expand All @@ -774,9 +782,11 @@ Array [
"ns2:Weight": 1.35,
"ns2:Width": 7.3,
},
"ns2:PackageQuantity": 1,
"ns2:PartNumber": 9781933988665,
"ns2:ProductGroup": "Book",
"ns2:ProductTypeName": "ABIS_BOOK",
"ns2:PublicationDate": "2009-07-05",
"ns2:PublicationDate": "2009-07-08",
"ns2:Publisher": "Manning Publications",
"ns2:SmallImage": Object {
"ns2:Height": 75,
Expand All @@ -798,172 +808,23 @@ Array [
"SalesRank": Array [
Object {
"ProductCategoryId": "book_display_on_website",
"Rank": 59485,
},
Object {
"ProductCategoryId": 377886011,
"Rank": 32,
"Rank": 689405,
},
Object {
"ProductCategoryId": 3887,
"Rank": 66,
"ProductCategoryId": 491298,
"Rank": 150,
},
Object {
"ProductCategoryId": 3870,
"Rank": 82,
},
],
},
},
],
},
Object {
"Products": Array [
Object {
"AttributeSets": Object {
"ns2:ItemAttributes": Object {
"ns2:Author": "Rowling, J.K.",
"ns2:Binding": "Paperback",
"ns2:Brand": "Scholastic Press",
"ns2:Creator": "GrandPré, Mary",
"ns2:Edition": "1st",
"ns2:Feature": "Recommended Age: 9 years and up",
"ns2:IsAutographed": false,
"ns2:IsMemorabilia": false,
"ns2:ItemDimensions": Object {
"ns2:Height": 0.8,
"ns2:Length": 7.5,
"ns2:Weight": 0.5,
"ns2:Width": 5.2,
},
"ns2:Label": "Scholastic Paperbacks",
"ns2:Languages": Object {
"ns2:Language": Array [
Object {
"ns2:Name": "english",
"ns2:Type": "Unknown",
},
Object {
"ns2:Name": "english",
"ns2:Type": "Original Language",
},
Object {
"ns2:Name": "english",
"ns2:Type": "Published",
},
],
},
"ns2:ListPrice": Object {
"ns2:Amount": 10.99,
"ns2:CurrencyCode": "USD",
},
"ns2:Manufacturer": "Scholastic Paperbacks",
"ns2:NumberOfItems": 1,
"ns2:NumberOfPages": 320,
"ns2:PackageDimensions": Object {
"ns2:Height": 1,
"ns2:Length": 7.5,
"ns2:Weight": 0.5,
"ns2:Width": 5.2,
},
"ns2:PackageQuantity": 1,
"ns2:PartNumber": 9780590353427,
"ns2:ProductGroup": "Book",
"ns2:ProductTypeName": "ABIS_BOOK",
"ns2:PublicationDate": "1999-10-01",
"ns2:Publisher": "Scholastic Paperbacks",
"ns2:ReleaseDate": "1999-09-08",
"ns2:SmallImage": Object {
"ns2:Height": 75,
"ns2:URL": "http://ecx.images-amazon.com/images/I/51MU5VilKpL._SL75_.jpg",
"ns2:Width": 51,
},
"ns2:Studio": "Scholastic Paperbacks",
"ns2:Title": "Harry Potter and the Sorcerer's Stone (Book 1)",
},
},
"Identifiers": Object {
"MarketplaceASIN": Object {
"ASIN": "059035342X",
"MarketplaceId": "ATVPDKIKX0DER",
},
},
"Relationships": "",
"SalesRankings": Object {
"SalesRank": Array [
Object {
"ProductCategoryId": "book_display_on_website",
"Rank": 362,
},
Object {
"ProductCategoryId": 15356791,
"Rank": 6,
"Rank": 375,
},
Object {
"ProductCategoryId": 3153,
"Rank": 9,
},
Object {
"ProductCategoryId": 3045,
"Rank": 14,
"ProductCategoryId": 3887,
"Rank": 836,
},
],
},
},
Object {
"AttributeSets": Object {
"ns2:ItemAttributes": Object {
"ns2:Author": "J.K. Rowling, Mary GrandPré",
"ns2:Binding": "Paperback",
"ns2:Label": "Scholastic Paperbacks",
"ns2:Languages": Object {
"ns2:Language": Array [
Object {
"ns2:Name": "english",
"ns2:Type": "Unknown",
},
Object {
"ns2:Name": "english",
"ns2:Type": "Published",
},
],
},
"ns2:Manufacturer": "Scholastic Paperbacks",
"ns2:NumberOfItems": 1,
"ns2:NumberOfPages": 784,
"ns2:PackageDimensions": Object {
"ns2:Height": 0.73,
"ns2:Length": 8.43,
"ns2:Weight": 0.79,
"ns2:Width": 5.85,
},
"ns2:ProductGroup": "Book",
"ns2:ProductTypeName": "BOOKS_1973_AND_LATER",
"ns2:PublicationDate": "1999-09-08",
"ns2:Publisher": "Scholastic Paperbacks",
"ns2:SmallImage": Object {
"ns2:Height": 75,
"ns2:URL": "http://ecx.images-amazon.com/images/I/51STfI7UiCL._SL75_.jpg",
"ns2:Width": 52,
},
"ns2:Studio": "Scholastic Paperbacks",
"ns2:Title": "Harry Potter and the Sorcerer's Stone",
},
},
"Identifiers": Object {
"MarketplaceASIN": Object {
"ASIN": 439708184,
"MarketplaceId": "ATVPDKIKX0DER",
},
},
"Relationships": "",
"SalesRankings": Object {
"SalesRank": Object {
"ProductCategoryId": "book_display_on_website",
"Rank": 2091024,
},
},
},
],
},
],
Expand Down

0 comments on commit 6d6bbe6

Please sign in to comment.