From d4c1d338ef4ce54b50c180b1b3a26e5a39961f4e Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Wed, 3 Feb 2021 15:28:26 +0700 Subject: [PATCH 1/7] test: try to get query metric in sb keyword report --- .../sponsored-brands-report-operation.test.ts | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/test/operations/reports/sponsored-brands/sponsored-brands-report-operation.test.ts b/test/operations/reports/sponsored-brands/sponsored-brands-report-operation.test.ts index 54b838436..d9383a0b0 100644 --- a/test/operations/reports/sponsored-brands/sponsored-brands-report-operation.test.ts +++ b/test/operations/reports/sponsored-brands/sponsored-brands-report-operation.test.ts @@ -1,7 +1,11 @@ import { OperationProvider } from '../../../../src/operations/operation-provider' import { httpClientFactory } from '../../../http-client-factory' -import { SponsoredBrandsReportOperation } from '../../../../src/operations/reports/sponsored-brands/sponsored-brands-report-operation' +import { + SponsoredBrandsReportOperation, + SponsoredBrandsReportParams, +} from '../../../../src/operations/reports/sponsored-brands/sponsored-brands-report-operation' import { ReportResponseStatus } from '../../../../src' +import { delay } from '../../../test-utils' jest.setTimeout(15000) @@ -172,5 +176,34 @@ describe('SponsoredBrandsReportOperation', () => { expect(res.length).toBeGreaterThanOrEqual(0) }) + + it('should return query metric if specific query segment in sb keyword report', async () => { + const params: SponsoredBrandsReportParams = { + recordType: 'keywords', + segment: 'query', + reportDate: '20210126', + metrics: [ + 'campaignId', + 'campaignName', + 'adGroupId', + 'adGroupName', + 'campaignBudgetType', + 'campaignStatus', + 'keywordId', + 'keywordStatus', + 'keywordBid', + 'keywordText', + ], + } + + const requestReportResult = await reportOperation.requestReport(params) + + await delay(3000) + + const res = await reportOperation.downloadReport(requestReportResult.reportId) + const { query } = res[0] + expect(res.length).toBeGreaterThanOrEqual(0) + expect(query).toBeDefined() + }) }) }) From ac10dff0127ec0f85b44d17b04e39db1aff16566 Mon Sep 17 00:00:00 2001 From: Scale Bot Date: Wed, 3 Feb 2021 08:29:51 +0000 Subject: [PATCH 2/7] test: adds Polly recordings [skip ci] --- .../recording.har | 337 ++++++++++++++++++ 1 file changed, 337 insertions(+) create mode 100644 test/__recordings__/SponsoredBrandsReportOperation_783097385/downloadReport_1412087767/should-return-query-metric-if-specific-query-segment-in-sb-keyword-report_725775083/recording.har diff --git a/test/__recordings__/SponsoredBrandsReportOperation_783097385/downloadReport_1412087767/should-return-query-metric-if-specific-query-segment-in-sb-keyword-report_725775083/recording.har b/test/__recordings__/SponsoredBrandsReportOperation_783097385/downloadReport_1412087767/should-return-query-metric-if-specific-query-segment-in-sb-keyword-report_725775083/recording.har new file mode 100644 index 000000000..d19f79157 --- /dev/null +++ b/test/__recordings__/SponsoredBrandsReportOperation_783097385/downloadReport_1412087767/should-return-query-metric-if-specific-query-segment-in-sb-keyword-report_725775083/recording.har @@ -0,0 +1,337 @@ +{ + "log": { + "_recordingName": "SponsoredBrandsReportOperation/downloadReport/should return query metric if specific query segment in sb keyword report", + "creator": { + "comment": "persister:fs", + "name": "Polly.JS", + "version": "5.1.0" + }, + "entries": [ + { + "_id": "5916ac2a49cc512e63e39fa103350328", + "_order": 0, + "cache": {}, + "request": { + "bodySize": 182, + "cookies": [], + "headers": [ + { + "name": "accept", + "value": "application/json" + }, + { + "name": "content-type", + "value": "application/json" + }, + { + "name": "user-agent", + "value": "@scaleleap/amazon-advertising-api-sdk/0.0.0" + }, + { + "name": "amazon-advertising-api-scope", + "value": "2984328618318898" + }, + { + "name": "bidding_controls_on", + "value": "true" + }, + { + "name": "accept-encoding", + "value": "application/json" + }, + { + "name": "content-length", + "value": 182 + }, + { + "name": "host", + "value": "advertising-api-test.amazon.com" + } + ], + "headersSize": 945, + "httpVersion": "HTTP/1.1", + "method": "POST", + "postData": { + "mimeType": "application/json", + "params": [], + "text": { + "metrics": "campaignId,campaignName,adGroupId,adGroupName,campaignBudgetType,campaignStatus,keywordId,keywordStatus,keywordBid,keywordText", + "reportDate": "20210126", + "segment": "query" + } + }, + "queryString": [], + "url": "https://advertising-api-test.amazon.com/v2/hsa/keywords/report" + }, + "response": { + "bodySize": 164, + "content": { + "mimeType": "text/plain", + "size": 164, + "text": "{\"reportId\":\"amzn1.clicksAPI.v1.m1.601A5EE0.eda6a3f0-e864-404f-8b25-a3b139a530ce\",\"recordType\":\"keyword\",\"status\":\"IN_PROGRESS\",\"statusDetails\":\"Generating report\"}" + }, + "cookies": [], + "headers": [ + { + "name": "server", + "value": "Server" + }, + { + "name": "date", + "value": "Wed, 03 Feb 2021 08:29:20 GMT" + }, + { + "name": "transfer-encoding", + "value": "chunked" + }, + { + "name": "connection", + "value": "close" + }, + { + "name": "vary", + "value": "Content-Type,Accept-Encoding,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment,User-Agent" + } + ], + "headersSize": 219, + "httpVersion": "HTTP/1.1", + "redirectURL": "", + "status": 202, + "statusText": "Accepted" + }, + "startedDateTime": "2021-02-03T08:29:19.929Z", + "time": 133, + "timings": { + "blocked": -1, + "connect": -1, + "dns": -1, + "receive": 0, + "send": 0, + "ssl": -1, + "wait": 133 + } + }, + { + "_id": "841e413aeeaf1b4cc140f0711b3ba40e", + "_order": 0, + "cache": {}, + "request": { + "bodySize": 0, + "cookies": [], + "headers": [ + { + "name": "accept", + "value": "application/json" + }, + { + "name": "content-type", + "value": "application/json" + }, + { + "name": "user-agent", + "value": "@scaleleap/amazon-advertising-api-sdk/0.0.0" + }, + { + "name": "amazon-advertising-api-scope", + "value": "2984328618318898" + }, + { + "name": "bidding_controls_on", + "value": "true" + }, + { + "name": "accept-encoding", + "value": "application/json" + }, + { + "name": "host", + "value": "advertising-api-test.amazon.com" + } + ], + "headersSize": 988, + "httpVersion": "HTTP/1.1", + "method": "GET", + "queryString": [], + "url": "https://advertising-api-test.amazon.com/v2/reports/amzn1.clicksAPI.v1.m1.601A5EE0.eda6a3f0-e864-404f-8b25-a3b139a530ce/download" + }, + "response": { + "bodySize": 0, + "content": { + "mimeType": "text/plain", + "size": 0 + }, + "cookies": [], + "headers": [ + { + "name": "server", + "value": "Server" + }, + { + "name": "date", + "value": "Wed, 03 Feb 2021 08:29:23 GMT" + }, + { + "name": "content-length", + "value": "0" + }, + { + "name": "connection", + "value": "close" + }, + { + "name": "location", + "value": "https://sandboxreports.s3.amazonaws.com/amzn1.clicksAPI.v1.m1.601A5EE0.eda6a3f0-e864-404f-8b25-a3b139a530ce.json.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20210203T082923Z&X-Amz-SignedHeaders=host&X-Amz-Expires=30&X-Amz-Credential=AKIA3P6LC7AREFFJTN2D%2F20210203%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=e324411c4fa5002823d7c3634723a59280065573b944cc911ac3d78f04132826" + }, + { + "name": "x-amz-request-id", + "value": "G164MA0FMADFF94111R8" + }, + { + "name": "vary", + "value": "Content-Type,Accept-Encoding,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment,User-Agent" + } + ], + "headersSize": 642, + "httpVersion": "HTTP/1.1", + "redirectURL": "https://sandboxreports.s3.amazonaws.com/amzn1.clicksAPI.v1.m1.601A5EE0.eda6a3f0-e864-404f-8b25-a3b139a530ce.json.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20210203T082923Z&X-Amz-SignedHeaders=host&X-Amz-Expires=30&X-Amz-Credential=AKIA3P6LC7AREFFJTN2D%2F20210203%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=e324411c4fa5002823d7c3634723a59280065573b944cc911ac3d78f04132826", + "status": 307, + "statusText": "Temporary Redirect" + }, + "startedDateTime": "2021-02-03T08:29:23.065Z", + "time": 71, + "timings": { + "blocked": -1, + "connect": -1, + "dns": -1, + "receive": 0, + "send": 0, + "ssl": -1, + "wait": 71 + } + }, + { + "_id": "6a4cb0d3eafbbdf171036a1c2d4bb792", + "_order": 0, + "cache": {}, + "request": { + "bodySize": 0, + "cookies": [], + "headers": [ + { + "name": "accept", + "value": "application/json, text/plain, */*" + }, + { + "name": "user-agent", + "value": "@scaleleap/amazon-advertising-api-sdk/0.0.0" + }, + { + "name": "host", + "value": "sandboxreports.s3.amazonaws.com" + } + ], + "headersSize": 536, + "httpVersion": "HTTP/1.1", + "method": "GET", + "queryString": [ + { + "name": "X-Amz-Algorithm", + "value": "AWS4-HMAC-SHA256" + }, + { + "name": "X-Amz-Date", + "value": "20210203T082923Z" + }, + { + "name": "X-Amz-SignedHeaders", + "value": "host" + }, + { + "name": "X-Amz-Expires", + "value": "30" + }, + { + "name": "X-Amz-Credential", + "value": "AKIA3P6LC7AREFFJTN2D/20210203/us-east-1/s3/aws4_request" + }, + { + "name": "X-Amz-Signature", + "value": "e324411c4fa5002823d7c3634723a59280065573b944cc911ac3d78f04132826" + } + ], + "url": "https://sandboxreports.s3.amazonaws.com/amzn1.clicksAPI.v1.m1.601A5EE0.eda6a3f0-e864-404f-8b25-a3b139a530ce.json.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20210203T082923Z&X-Amz-SignedHeaders=host&X-Amz-Expires=30&X-Amz-Credential=AKIA3P6LC7AREFFJTN2D%2F20210203%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=e324411c4fa5002823d7c3634723a59280065573b944cc911ac3d78f04132826" + }, + "response": { + "bodySize": 22, + "content": { + "_isBinary": true, + "mimeType": "application/octet-stream", + "size": 22, + "text": "1f8b08000000000000008b8e050029bb4c0d02000000" + }, + "cookies": [], + "headers": [ + { + "name": "x-amz-id-2", + "value": "kdHKNuSTO0E5L3mWJtLmQ48N52McvaEUENyLYZQR/n9HLeIc8PhZJw6y96cs77wS5Ag1X/0Nabg=" + }, + { + "name": "x-amz-request-id", + "value": "3A6BE075925E1336" + }, + { + "name": "date", + "value": "Wed, 03 Feb 2021 08:29:24 GMT" + }, + { + "name": "last-modified", + "value": "Wed, 03 Feb 2021 08:29:21 GMT" + }, + { + "name": "etag", + "value": "\"24d0a027ba0f276ca66203026eecc338\"" + }, + { + "name": "accept-ranges", + "value": "bytes" + }, + { + "name": "content-type", + "value": "application/octet-stream" + }, + { + "name": "content-length", + "value": "22" + }, + { + "name": "server", + "value": "AmazonS3" + }, + { + "name": "connection", + "value": "close" + } + ], + "headersSize": 372, + "httpVersion": "HTTP/1.1", + "redirectURL": "", + "status": 200, + "statusText": "OK" + }, + "startedDateTime": "2021-02-03T08:29:23.140Z", + "time": 65, + "timings": { + "blocked": -1, + "connect": -1, + "dns": -1, + "receive": 0, + "send": 0, + "ssl": -1, + "wait": 65 + } + } + ], + "pages": [], + "version": "1.2" + } +} From cbd687969e28a711d8db555bd2c1341038368c60 Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Wed, 3 Feb 2021 15:41:15 +0700 Subject: [PATCH 3/7] test: remove delay when download sb keyword report --- .../sponsored-brands/sponsored-brands-report-operation.test.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/operations/reports/sponsored-brands/sponsored-brands-report-operation.test.ts b/test/operations/reports/sponsored-brands/sponsored-brands-report-operation.test.ts index d9383a0b0..ff15505d2 100644 --- a/test/operations/reports/sponsored-brands/sponsored-brands-report-operation.test.ts +++ b/test/operations/reports/sponsored-brands/sponsored-brands-report-operation.test.ts @@ -5,7 +5,6 @@ import { SponsoredBrandsReportParams, } from '../../../../src/operations/reports/sponsored-brands/sponsored-brands-report-operation' import { ReportResponseStatus } from '../../../../src' -import { delay } from '../../../test-utils' jest.setTimeout(15000) @@ -198,8 +197,6 @@ describe('SponsoredBrandsReportOperation', () => { const requestReportResult = await reportOperation.requestReport(params) - await delay(3000) - const res = await reportOperation.downloadReport(requestReportResult.reportId) const { query } = res[0] expect(res.length).toBeGreaterThanOrEqual(0) From a044dbd8820a8ffed21aff3ce5b78cf71afe1c48 Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Wed, 3 Feb 2021 15:41:43 +0700 Subject: [PATCH 4/7] test: try to create sb keyword --- .../keywords/sponsored-brands-keywords-operation.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/operations/keywords/sponsored-brands-keywords-operation.test.ts b/test/operations/keywords/sponsored-brands-keywords-operation.test.ts index bacfea430..71086e2ff 100644 --- a/test/operations/keywords/sponsored-brands-keywords-operation.test.ts +++ b/test/operations/keywords/sponsored-brands-keywords-operation.test.ts @@ -62,7 +62,7 @@ describe('SponsoredBrandsKeywordsOperation', () => { }) }) - describe.skip('createKeywords', () => { + describe('createKeywords', () => { it(`should create one or more sb keywords`, async () => { const params: CreateSponsoredBrandsKeywordParams[] = [ { From e2bf1c6cb7f00c46a22d5129a0bb3795eb6ff9dc Mon Sep 17 00:00:00 2001 From: Scale Bot Date: Wed, 3 Feb 2021 08:43:02 +0000 Subject: [PATCH 5/7] test: adds Polly recordings [skip ci] --- .../recording.har | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 test/__recordings__/SponsoredBrandsKeywordsOperation_3255714683/createKeywords_528268509/should-create-one-or-more-sb-keywords_3025258751/recording.har diff --git a/test/__recordings__/SponsoredBrandsKeywordsOperation_3255714683/createKeywords_528268509/should-create-one-or-more-sb-keywords_3025258751/recording.har b/test/__recordings__/SponsoredBrandsKeywordsOperation_3255714683/createKeywords_528268509/should-create-one-or-more-sb-keywords_3025258751/recording.har new file mode 100644 index 000000000..cbdf0c8b4 --- /dev/null +++ b/test/__recordings__/SponsoredBrandsKeywordsOperation_3255714683/createKeywords_528268509/should-create-one-or-more-sb-keywords_3025258751/recording.har @@ -0,0 +1,135 @@ +{ + "log": { + "_recordingName": "SponsoredBrandsKeywordsOperation/createKeywords/should create one or more sb keywords", + "creator": { + "comment": "persister:fs", + "name": "Polly.JS", + "version": "5.1.0" + }, + "entries": [ + { + "_id": "1a96cdd4b060c13b31cae619ae12444e", + "_order": 0, + "cache": {}, + "request": { + "bodySize": 109, + "cookies": [], + "headers": [ + { + "name": "accept", + "value": "application/json" + }, + { + "name": "content-type", + "value": "application/json" + }, + { + "name": "user-agent", + "value": "@scaleleap/amazon-advertising-api-sdk/0.0.0" + }, + { + "name": "amazon-advertising-api-scope", + "value": "2984328618318898" + }, + { + "name": "bidding_controls_on", + "value": "true" + }, + { + "name": "accept-encoding", + "value": "application/json" + }, + { + "name": "content-length", + "value": 109 + }, + { + "name": "host", + "value": "advertising-api-test.amazon.com" + } + ], + "headersSize": 938, + "httpVersion": "HTTP/1.1", + "method": "POST", + "postData": { + "mimeType": "application/json", + "params": [], + "text": [ + { + "adGroupId": 149522344269714, + "bid": 1, + "campaignId": 164069484151709, + "keywordText": "Pear", + "matchType": "broad" + } + ] + }, + "queryString": [], + "url": "https://advertising-api-test.amazon.com/v2/hsa/keywords" + }, + "response": { + "bodySize": 68, + "content": { + "mimeType": "application/json", + "size": 68, + "text": [ + { + "code": "INTERNAL_ERROR", + "description": "Cannot create a keyword." + } + ] + }, + "cookies": [], + "headers": [ + { + "name": "server", + "value": "Server" + }, + { + "name": "date", + "value": "Wed, 03 Feb 2021 08:42:48 GMT" + }, + { + "name": "content-type", + "value": "application/json" + }, + { + "name": "transfer-encoding", + "value": "chunked" + }, + { + "name": "connection", + "value": "close" + }, + { + "name": "x-amz-request-id", + "value": "VNZZG78QVZVZ36KW0XV2" + }, + { + "name": "vary", + "value": "Content-Type,Accept-Encoding,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment,User-Agent" + } + ], + "headersSize": 291, + "httpVersion": "HTTP/1.1", + "redirectURL": "", + "status": 207, + "statusText": "Multi-Status" + }, + "startedDateTime": "2021-02-03T08:42:47.954Z", + "time": 388, + "timings": { + "blocked": -1, + "connect": -1, + "dns": -1, + "receive": 0, + "send": 0, + "ssl": -1, + "wait": 388 + } + } + ], + "pages": [], + "version": "1.2" + } +} From e229f537cffa1ca29d7e7407274ed726a44ea72e Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Thu, 4 Feb 2021 09:30:59 +0700 Subject: [PATCH 6/7] test: remove download sb keyword report recording for testing --- .../recording.har | 135 ------- .../recording.har | 337 ------------------ 2 files changed, 472 deletions(-) delete mode 100644 test/__recordings__/SponsoredBrandsKeywordsOperation_3255714683/createKeywords_528268509/should-create-one-or-more-sb-keywords_3025258751/recording.har delete mode 100644 test/__recordings__/SponsoredBrandsReportOperation_783097385/downloadReport_1412087767/should-return-query-metric-if-specific-query-segment-in-sb-keyword-report_725775083/recording.har diff --git a/test/__recordings__/SponsoredBrandsKeywordsOperation_3255714683/createKeywords_528268509/should-create-one-or-more-sb-keywords_3025258751/recording.har b/test/__recordings__/SponsoredBrandsKeywordsOperation_3255714683/createKeywords_528268509/should-create-one-or-more-sb-keywords_3025258751/recording.har deleted file mode 100644 index cbdf0c8b4..000000000 --- a/test/__recordings__/SponsoredBrandsKeywordsOperation_3255714683/createKeywords_528268509/should-create-one-or-more-sb-keywords_3025258751/recording.har +++ /dev/null @@ -1,135 +0,0 @@ -{ - "log": { - "_recordingName": "SponsoredBrandsKeywordsOperation/createKeywords/should create one or more sb keywords", - "creator": { - "comment": "persister:fs", - "name": "Polly.JS", - "version": "5.1.0" - }, - "entries": [ - { - "_id": "1a96cdd4b060c13b31cae619ae12444e", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 109, - "cookies": [], - "headers": [ - { - "name": "accept", - "value": "application/json" - }, - { - "name": "content-type", - "value": "application/json" - }, - { - "name": "user-agent", - "value": "@scaleleap/amazon-advertising-api-sdk/0.0.0" - }, - { - "name": "amazon-advertising-api-scope", - "value": "2984328618318898" - }, - { - "name": "bidding_controls_on", - "value": "true" - }, - { - "name": "accept-encoding", - "value": "application/json" - }, - { - "name": "content-length", - "value": 109 - }, - { - "name": "host", - "value": "advertising-api-test.amazon.com" - } - ], - "headersSize": 938, - "httpVersion": "HTTP/1.1", - "method": "POST", - "postData": { - "mimeType": "application/json", - "params": [], - "text": [ - { - "adGroupId": 149522344269714, - "bid": 1, - "campaignId": 164069484151709, - "keywordText": "Pear", - "matchType": "broad" - } - ] - }, - "queryString": [], - "url": "https://advertising-api-test.amazon.com/v2/hsa/keywords" - }, - "response": { - "bodySize": 68, - "content": { - "mimeType": "application/json", - "size": 68, - "text": [ - { - "code": "INTERNAL_ERROR", - "description": "Cannot create a keyword." - } - ] - }, - "cookies": [], - "headers": [ - { - "name": "server", - "value": "Server" - }, - { - "name": "date", - "value": "Wed, 03 Feb 2021 08:42:48 GMT" - }, - { - "name": "content-type", - "value": "application/json" - }, - { - "name": "transfer-encoding", - "value": "chunked" - }, - { - "name": "connection", - "value": "close" - }, - { - "name": "x-amz-request-id", - "value": "VNZZG78QVZVZ36KW0XV2" - }, - { - "name": "vary", - "value": "Content-Type,Accept-Encoding,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment,User-Agent" - } - ], - "headersSize": 291, - "httpVersion": "HTTP/1.1", - "redirectURL": "", - "status": 207, - "statusText": "Multi-Status" - }, - "startedDateTime": "2021-02-03T08:42:47.954Z", - "time": 388, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 388 - } - } - ], - "pages": [], - "version": "1.2" - } -} diff --git a/test/__recordings__/SponsoredBrandsReportOperation_783097385/downloadReport_1412087767/should-return-query-metric-if-specific-query-segment-in-sb-keyword-report_725775083/recording.har b/test/__recordings__/SponsoredBrandsReportOperation_783097385/downloadReport_1412087767/should-return-query-metric-if-specific-query-segment-in-sb-keyword-report_725775083/recording.har deleted file mode 100644 index d19f79157..000000000 --- a/test/__recordings__/SponsoredBrandsReportOperation_783097385/downloadReport_1412087767/should-return-query-metric-if-specific-query-segment-in-sb-keyword-report_725775083/recording.har +++ /dev/null @@ -1,337 +0,0 @@ -{ - "log": { - "_recordingName": "SponsoredBrandsReportOperation/downloadReport/should return query metric if specific query segment in sb keyword report", - "creator": { - "comment": "persister:fs", - "name": "Polly.JS", - "version": "5.1.0" - }, - "entries": [ - { - "_id": "5916ac2a49cc512e63e39fa103350328", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 182, - "cookies": [], - "headers": [ - { - "name": "accept", - "value": "application/json" - }, - { - "name": "content-type", - "value": "application/json" - }, - { - "name": "user-agent", - "value": "@scaleleap/amazon-advertising-api-sdk/0.0.0" - }, - { - "name": "amazon-advertising-api-scope", - "value": "2984328618318898" - }, - { - "name": "bidding_controls_on", - "value": "true" - }, - { - "name": "accept-encoding", - "value": "application/json" - }, - { - "name": "content-length", - "value": 182 - }, - { - "name": "host", - "value": "advertising-api-test.amazon.com" - } - ], - "headersSize": 945, - "httpVersion": "HTTP/1.1", - "method": "POST", - "postData": { - "mimeType": "application/json", - "params": [], - "text": { - "metrics": "campaignId,campaignName,adGroupId,adGroupName,campaignBudgetType,campaignStatus,keywordId,keywordStatus,keywordBid,keywordText", - "reportDate": "20210126", - "segment": "query" - } - }, - "queryString": [], - "url": "https://advertising-api-test.amazon.com/v2/hsa/keywords/report" - }, - "response": { - "bodySize": 164, - "content": { - "mimeType": "text/plain", - "size": 164, - "text": "{\"reportId\":\"amzn1.clicksAPI.v1.m1.601A5EE0.eda6a3f0-e864-404f-8b25-a3b139a530ce\",\"recordType\":\"keyword\",\"status\":\"IN_PROGRESS\",\"statusDetails\":\"Generating report\"}" - }, - "cookies": [], - "headers": [ - { - "name": "server", - "value": "Server" - }, - { - "name": "date", - "value": "Wed, 03 Feb 2021 08:29:20 GMT" - }, - { - "name": "transfer-encoding", - "value": "chunked" - }, - { - "name": "connection", - "value": "close" - }, - { - "name": "vary", - "value": "Content-Type,Accept-Encoding,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment,User-Agent" - } - ], - "headersSize": 219, - "httpVersion": "HTTP/1.1", - "redirectURL": "", - "status": 202, - "statusText": "Accepted" - }, - "startedDateTime": "2021-02-03T08:29:19.929Z", - "time": 133, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 133 - } - }, - { - "_id": "841e413aeeaf1b4cc140f0711b3ba40e", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 0, - "cookies": [], - "headers": [ - { - "name": "accept", - "value": "application/json" - }, - { - "name": "content-type", - "value": "application/json" - }, - { - "name": "user-agent", - "value": "@scaleleap/amazon-advertising-api-sdk/0.0.0" - }, - { - "name": "amazon-advertising-api-scope", - "value": "2984328618318898" - }, - { - "name": "bidding_controls_on", - "value": "true" - }, - { - "name": "accept-encoding", - "value": "application/json" - }, - { - "name": "host", - "value": "advertising-api-test.amazon.com" - } - ], - "headersSize": 988, - "httpVersion": "HTTP/1.1", - "method": "GET", - "queryString": [], - "url": "https://advertising-api-test.amazon.com/v2/reports/amzn1.clicksAPI.v1.m1.601A5EE0.eda6a3f0-e864-404f-8b25-a3b139a530ce/download" - }, - "response": { - "bodySize": 0, - "content": { - "mimeType": "text/plain", - "size": 0 - }, - "cookies": [], - "headers": [ - { - "name": "server", - "value": "Server" - }, - { - "name": "date", - "value": "Wed, 03 Feb 2021 08:29:23 GMT" - }, - { - "name": "content-length", - "value": "0" - }, - { - "name": "connection", - "value": "close" - }, - { - "name": "location", - "value": "https://sandboxreports.s3.amazonaws.com/amzn1.clicksAPI.v1.m1.601A5EE0.eda6a3f0-e864-404f-8b25-a3b139a530ce.json.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20210203T082923Z&X-Amz-SignedHeaders=host&X-Amz-Expires=30&X-Amz-Credential=AKIA3P6LC7AREFFJTN2D%2F20210203%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=e324411c4fa5002823d7c3634723a59280065573b944cc911ac3d78f04132826" - }, - { - "name": "x-amz-request-id", - "value": "G164MA0FMADFF94111R8" - }, - { - "name": "vary", - "value": "Content-Type,Accept-Encoding,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment,User-Agent" - } - ], - "headersSize": 642, - "httpVersion": "HTTP/1.1", - "redirectURL": "https://sandboxreports.s3.amazonaws.com/amzn1.clicksAPI.v1.m1.601A5EE0.eda6a3f0-e864-404f-8b25-a3b139a530ce.json.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20210203T082923Z&X-Amz-SignedHeaders=host&X-Amz-Expires=30&X-Amz-Credential=AKIA3P6LC7AREFFJTN2D%2F20210203%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=e324411c4fa5002823d7c3634723a59280065573b944cc911ac3d78f04132826", - "status": 307, - "statusText": "Temporary Redirect" - }, - "startedDateTime": "2021-02-03T08:29:23.065Z", - "time": 71, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 71 - } - }, - { - "_id": "6a4cb0d3eafbbdf171036a1c2d4bb792", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 0, - "cookies": [], - "headers": [ - { - "name": "accept", - "value": "application/json, text/plain, */*" - }, - { - "name": "user-agent", - "value": "@scaleleap/amazon-advertising-api-sdk/0.0.0" - }, - { - "name": "host", - "value": "sandboxreports.s3.amazonaws.com" - } - ], - "headersSize": 536, - "httpVersion": "HTTP/1.1", - "method": "GET", - "queryString": [ - { - "name": "X-Amz-Algorithm", - "value": "AWS4-HMAC-SHA256" - }, - { - "name": "X-Amz-Date", - "value": "20210203T082923Z" - }, - { - "name": "X-Amz-SignedHeaders", - "value": "host" - }, - { - "name": "X-Amz-Expires", - "value": "30" - }, - { - "name": "X-Amz-Credential", - "value": "AKIA3P6LC7AREFFJTN2D/20210203/us-east-1/s3/aws4_request" - }, - { - "name": "X-Amz-Signature", - "value": "e324411c4fa5002823d7c3634723a59280065573b944cc911ac3d78f04132826" - } - ], - "url": "https://sandboxreports.s3.amazonaws.com/amzn1.clicksAPI.v1.m1.601A5EE0.eda6a3f0-e864-404f-8b25-a3b139a530ce.json.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20210203T082923Z&X-Amz-SignedHeaders=host&X-Amz-Expires=30&X-Amz-Credential=AKIA3P6LC7AREFFJTN2D%2F20210203%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=e324411c4fa5002823d7c3634723a59280065573b944cc911ac3d78f04132826" - }, - "response": { - "bodySize": 22, - "content": { - "_isBinary": true, - "mimeType": "application/octet-stream", - "size": 22, - "text": "1f8b08000000000000008b8e050029bb4c0d02000000" - }, - "cookies": [], - "headers": [ - { - "name": "x-amz-id-2", - "value": "kdHKNuSTO0E5L3mWJtLmQ48N52McvaEUENyLYZQR/n9HLeIc8PhZJw6y96cs77wS5Ag1X/0Nabg=" - }, - { - "name": "x-amz-request-id", - "value": "3A6BE075925E1336" - }, - { - "name": "date", - "value": "Wed, 03 Feb 2021 08:29:24 GMT" - }, - { - "name": "last-modified", - "value": "Wed, 03 Feb 2021 08:29:21 GMT" - }, - { - "name": "etag", - "value": "\"24d0a027ba0f276ca66203026eecc338\"" - }, - { - "name": "accept-ranges", - "value": "bytes" - }, - { - "name": "content-type", - "value": "application/octet-stream" - }, - { - "name": "content-length", - "value": "22" - }, - { - "name": "server", - "value": "AmazonS3" - }, - { - "name": "connection", - "value": "close" - } - ], - "headersSize": 372, - "httpVersion": "HTTP/1.1", - "redirectURL": "", - "status": 200, - "statusText": "OK" - }, - "startedDateTime": "2021-02-03T08:29:23.140Z", - "time": 65, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 65 - } - } - ], - "pages": [], - "version": "1.2" - } -} From 0d0e7d3737168a92fe1638fb88409d633f8db1b9 Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Thu, 4 Feb 2021 10:04:22 +0700 Subject: [PATCH 7/7] test: refactor expectation of sb keyword report downloading --- .../sponsored-brands-report-operation.test.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/operations/reports/sponsored-brands/sponsored-brands-report-operation.test.ts b/test/operations/reports/sponsored-brands/sponsored-brands-report-operation.test.ts index ff15505d2..06ec7c6b1 100644 --- a/test/operations/reports/sponsored-brands/sponsored-brands-report-operation.test.ts +++ b/test/operations/reports/sponsored-brands/sponsored-brands-report-operation.test.ts @@ -5,6 +5,7 @@ import { SponsoredBrandsReportParams, } from '../../../../src/operations/reports/sponsored-brands/sponsored-brands-report-operation' import { ReportResponseStatus } from '../../../../src' +import { delay } from '../../../test-utils' jest.setTimeout(15000) @@ -177,6 +178,7 @@ describe('SponsoredBrandsReportOperation', () => { }) it('should return query metric if specific query segment in sb keyword report', async () => { + expect.assertions(2) const params: SponsoredBrandsReportParams = { recordType: 'keywords', segment: 'query', @@ -197,10 +199,15 @@ describe('SponsoredBrandsReportOperation', () => { const requestReportResult = await reportOperation.requestReport(params) + await delay() + const res = await reportOperation.downloadReport(requestReportResult.reportId) - const { query } = res[0] - expect(res.length).toBeGreaterThanOrEqual(0) - expect(query).toBeDefined() + const [report] = res + + if (report) { + expect(report).toHaveProperty('query') + } + expect(res.length).toBeGreaterThan(0) }) }) })