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

Commit

Permalink
fix: report ID parsing
Browse files Browse the repository at this point in the history
Fixes report ID parsing, where they were automatically parsed as
numbers, but the numbers were too large and caused an overlow and were
getting rounded.

Closes #327
  • Loading branch information
moltar committed Mar 19, 2021
1 parent 2fc8727 commit 21965bc
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ export const parseResponse = <T>(
parseAttributeValue: true,
attrNodeName: 'attr',
textNodeName: 'text',
parseTrueNumberOnly: true,
tagValueProcessor: (value) => decode(value),
},
true,
Expand Down
4 changes: 2 additions & 2 deletions test/unit/__snapshots__/products.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ Array [
"ns2:CurrencyCode": "USD",
},
"ns2:Manufacturer": "Pearl iZUMi",
"ns2:Model": 275,
"ns2:Model": "0275",
"ns2:PackageDimensions": Object {
"ns2:Height": Object {
"attr": Object {
Expand Down Expand Up @@ -765,7 +765,7 @@ Array [
},
},
"ns2:PackageQuantity": 1,
"ns2:PartNumber": 275,
"ns2:PartNumber": "0275",
"ns2:ProductGroup": "Apparel",
"ns2:ProductTypeName": "SHORTS",
"ns2:Publisher": "Pearl iZUMi",
Expand Down
4 changes: 2 additions & 2 deletions test/unit/__snapshots__/reports.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Array [
Object {
"Acknowledged": false,
"AvailableDate": 2020-03-13T08:21:03.000Z,
"ReportId": "19571121666018336",
"ReportId": "19571121666018334",
"ReportRequestId": "51776018334",
"ReportType": "_GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_",
},
Expand Down Expand Up @@ -321,7 +321,7 @@ Array [
Object {
"CompletedDate": 2020-03-13T08:21:03.000Z,
"EndDate": 2020-03-13T07:52:49.000Z,
"GeneratedReportId": "19571121666018336",
"GeneratedReportId": "19571121666018334",
"ReportProcessingStatus": "_DONE_",
"ReportRequestId": "51776018334",
"ReportType": "_GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_",
Expand Down
18 changes: 18 additions & 0 deletions test/unit/issue/327/327.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { promises as fs } from 'fs'

import { parseResponse } from '../../../../src/http'

describe('issue #327', () => {
it('should parse report response correctly', async () => {
expect.assertions(1)

const response = await fs.readFile(`${__dirname}/response.xml`, { encoding: 'utf8' })

const [data] = parseResponse({
data: response,
headers: {},
})

expect(data).toMatchSnapshot()
})
})
90 changes: 90 additions & 0 deletions test/unit/issue/327/__snapshots__/327.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`issue #327 should parse report response correctly 1`] = `
Object {
"GetReportListResponse": Object {
"GetReportListResult": Object {
"HasNext": true,
"NextToken": "2YgYW55IPQhvu5hbCBwbGVhc3VyZS4=",
"ReportInfo": Array [
Object {
"Acknowledged": false,
"AvailableDate": "2021-03-17T09:43:46+00:00",
"ReportId": "28136451747018703",
"ReportRequestId": 505364018703,
"ReportType": "_RFQD_BULK_DOWNLOAD_",
},
Object {
"Acknowledged": false,
"AvailableDate": "2021-03-17T09:42:21+00:00",
"ReportId": "28146215237018703",
"ReportRequestId": 505360018703,
"ReportType": "_RFQD_BULK_DOWNLOAD_",
},
Object {
"Acknowledged": false,
"AvailableDate": "2021-03-17T08:27:14+00:00",
"ReportId": "28139198851018703",
"ReportRequestId": 505332018703,
"ReportType": "_RFQD_BULK_DOWNLOAD_",
},
Object {
"Acknowledged": false,
"AvailableDate": "2021-03-17T04:26:54+00:00",
"ReportId": "28141052303018703",
"ReportRequestId": 505237018703,
"ReportType": "_RFQD_BULK_DOWNLOAD_",
},
Object {
"Acknowledged": false,
"AvailableDate": "2021-03-16T14:12:45+00:00",
"ReportId": "28119289673018702",
"ReportRequestId": 504882018702,
"ReportType": "_RFQD_BULK_DOWNLOAD_",
},
Object {
"Acknowledged": false,
"AvailableDate": "2021-03-15T18:07:48+00:00",
"ReportId": "28085787288018701",
"ReportRequestId": 504400018701,
"ReportType": "_RFQD_BULK_DOWNLOAD_",
},
Object {
"Acknowledged": false,
"AvailableDate": "2021-03-08T18:03:33+00:00",
"ReportId": "27873864943018694",
"ReportRequestId": 500801018694,
"ReportType": "_RFQD_BULK_DOWNLOAD_",
},
Object {
"Acknowledged": false,
"AvailableDate": "2021-03-08T18:01:57+00:00",
"ReportId": "27875410347018694",
"ReportRequestId": 500800018694,
"ReportType": "_RFQD_BULK_DOWNLOAD_",
},
Object {
"Acknowledged": false,
"AvailableDate": "2021-03-08T17:54:27+00:00",
"ReportId": "27886303516018694",
"ReportRequestId": 500796018694,
"ReportType": "_RFQD_BULK_DOWNLOAD_",
},
Object {
"Acknowledged": false,
"AvailableDate": "2021-03-08T05:31:26+00:00",
"ReportId": "27864140748018694",
"ReportRequestId": 500483018694,
"ReportType": "_RFQD_BULK_DOWNLOAD_",
},
],
},
"ResponseMetadata": Object {
"RequestId": "fbf677c1-dcee-4110-bc88-2ba3702e331b",
},
"attr": Object {
"xmlns": "http://mws.amazonservices.com/doc/2009-01-01/",
},
},
}
`;
83 changes: 83 additions & 0 deletions test/unit/issue/327/response.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<GetReportListResponse xmlns="http://mws.amazonservices.com/doc/2009-01-01/">
<GetReportListResult>
<NextToken>2YgYW55IPQhvu5hbCBwbGVhc3VyZS4=</NextToken>
<HasNext>true</HasNext>

<!-- From: https://github.com/ScaleLeap/amazon-mws-api-sdk/issues/327#issuecomment-801718189 -->
<ReportInfo>
<ReportType>_RFQD_BULK_DOWNLOAD_</ReportType>
<Acknowledged>false</Acknowledged>
<ReportId>28136451747018703</ReportId>
<ReportRequestId>505364018703</ReportRequestId>
<AvailableDate>2021-03-17T09:43:46+00:00</AvailableDate>
</ReportInfo>
<ReportInfo>
<ReportType>_RFQD_BULK_DOWNLOAD_</ReportType>
<Acknowledged>false</Acknowledged>
<ReportId>28146215237018703</ReportId>
<ReportRequestId>505360018703</ReportRequestId>
<AvailableDate>2021-03-17T09:42:21+00:00</AvailableDate>
</ReportInfo>
<ReportInfo>
<ReportType>_RFQD_BULK_DOWNLOAD_</ReportType>
<Acknowledged>false</Acknowledged>
<ReportId>28139198851018703</ReportId>
<ReportRequestId>505332018703</ReportRequestId>
<AvailableDate>2021-03-17T08:27:14+00:00</AvailableDate>
</ReportInfo>
<ReportInfo>
<ReportType>_RFQD_BULK_DOWNLOAD_</ReportType>
<Acknowledged>false</Acknowledged>
<ReportId>28141052303018703</ReportId>
<ReportRequestId>505237018703</ReportRequestId>
<AvailableDate>2021-03-17T04:26:54+00:00</AvailableDate>
</ReportInfo>
<ReportInfo>
<ReportType>_RFQD_BULK_DOWNLOAD_</ReportType>
<Acknowledged>false</Acknowledged>
<ReportId>28119289673018702</ReportId>
<ReportRequestId>504882018702</ReportRequestId>
<AvailableDate>2021-03-16T14:12:45+00:00</AvailableDate>
</ReportInfo>
<ReportInfo>
<ReportType>_RFQD_BULK_DOWNLOAD_</ReportType>
<Acknowledged>false</Acknowledged>
<ReportId>28085787288018701</ReportId>
<ReportRequestId>504400018701</ReportRequestId>
<AvailableDate>2021-03-15T18:07:48+00:00</AvailableDate>
</ReportInfo>
<ReportInfo>
<ReportType>_RFQD_BULK_DOWNLOAD_</ReportType>
<Acknowledged>false</Acknowledged>
<ReportId>27873864943018694</ReportId>
<ReportRequestId>500801018694</ReportRequestId>
<AvailableDate>2021-03-08T18:03:33+00:00</AvailableDate>
</ReportInfo>
<ReportInfo>
<ReportType>_RFQD_BULK_DOWNLOAD_</ReportType>
<Acknowledged>false</Acknowledged>
<ReportId>27875410347018694</ReportId>
<ReportRequestId>500800018694</ReportRequestId>
<AvailableDate>2021-03-08T18:01:57+00:00</AvailableDate>
</ReportInfo>
<ReportInfo>
<ReportType>_RFQD_BULK_DOWNLOAD_</ReportType>
<Acknowledged>false</Acknowledged>
<ReportId>27886303516018694</ReportId>
<ReportRequestId>500796018694</ReportRequestId>
<AvailableDate>2021-03-08T17:54:27+00:00</AvailableDate>
</ReportInfo>
<ReportInfo>
<ReportType>_RFQD_BULK_DOWNLOAD_</ReportType>
<Acknowledged>false</Acknowledged>
<ReportId>27864140748018694</ReportId>
<ReportRequestId>500483018694</ReportRequestId>
<AvailableDate>2021-03-08T05:31:26+00:00</AvailableDate>
</ReportInfo>


</GetReportListResult>
<ResponseMetadata>
<RequestId>fbf677c1-dcee-4110-bc88-2ba3702e331b</RequestId>
</ResponseMetadata>
</GetReportListResponse>

0 comments on commit 21965bc

Please sign in to comment.