From f3f2755449164318854dba2f527d04df8480acee Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Wed, 15 Apr 2020 22:14:11 +0700 Subject: [PATCH] feat: add sb ad group and keyword report metrics --- src/operations/reports/metrics/index.ts | 4 +- ...ponsored-brands-ad-group-report-metrics.ts | 38 ++++++ ...sponsored-brands-keyword-report-metrics.ts | 58 ++++++++ ...sponsored-brands-ad-group-report-params.ts | 4 +- .../sponsored-brands-keyword-report-params.ts | 4 +- .../recording.har | 126 ------------------ .../recording.har | 126 ------------------ test/index.test.ts | 6 + .../sponsored-brands-report-operation.test.ts | 42 +++++- 9 files changed, 148 insertions(+), 260 deletions(-) create mode 100644 src/operations/reports/metrics/sponsored-brands-ad-group-report-metrics.ts create mode 100644 src/operations/reports/metrics/sponsored-brands-keyword-report-metrics.ts delete mode 100644 test/__recordings__/SponsoredBrandsReportOperation_783097385/requestReport_2012826696/should-return-a-in-progress-status-with-adgroups-report_3288827722/recording.har delete mode 100644 test/__recordings__/SponsoredBrandsReportOperation_783097385/requestReport_2012826696/should-return-a-in-progress-status-with-keywords-report_4030230505/recording.har diff --git a/src/operations/reports/metrics/index.ts b/src/operations/reports/metrics/index.ts index 61b5071ad..20f19fcd2 100644 --- a/src/operations/reports/metrics/index.ts +++ b/src/operations/reports/metrics/index.ts @@ -4,5 +4,7 @@ export * from './sponsored-products-campaign-report-metrics' export * from './sponsored-products-keyword-report-metrics' export * from './sponsored-products-product-ads-report-metrics' export * from './sponsored-products-product-targeting-report-metrics' -export * from './sponsored-brands-headline-search-report-metrics' +export * from './sponsored-brands-ad-group-report-metrics' export * from './sponsored-brands-campaign-report-metrics' +export * from './sponsored-brands-headline-search-report-metrics' +export * from './sponsored-brands-keyword-report-metrics' diff --git a/src/operations/reports/metrics/sponsored-brands-ad-group-report-metrics.ts b/src/operations/reports/metrics/sponsored-brands-ad-group-report-metrics.ts new file mode 100644 index 000000000..21a951ce0 --- /dev/null +++ b/src/operations/reports/metrics/sponsored-brands-ad-group-report-metrics.ts @@ -0,0 +1,38 @@ +import * as t from 'io-ts' + +export const SponsoredBrandsAdGroupReportMetrics = t.union([ + /** + * Unique numerical ID of the campaign + */ + t.literal('campaignId'), + + /** + * Unique name of the campaign + */ + t.literal('campaignName'), + + /** + * Total budget allotted to the campaign + */ + t.literal('campaignBudget'), + + t.literal('campaignBudgetType'), + + /** + * Status of the campaign + */ + t.literal('campaignStatus'), + + /** + * Unique name of the ad group + */ + t.literal('adGroupName'), + + /** + * Unique numerical ID of the ad group + */ + t.literal('adGroupId'), +]) +export type SponsoredBrandsAdGroupReportMetrics = t.TypeOf< + typeof SponsoredBrandsAdGroupReportMetrics +> diff --git a/src/operations/reports/metrics/sponsored-brands-keyword-report-metrics.ts b/src/operations/reports/metrics/sponsored-brands-keyword-report-metrics.ts new file mode 100644 index 000000000..ef86ca0f2 --- /dev/null +++ b/src/operations/reports/metrics/sponsored-brands-keyword-report-metrics.ts @@ -0,0 +1,58 @@ +import * as t from 'io-ts' + +export const SponsoredBrandsKeywordReportMetrics = t.union([ + /** + * Unique numerical ID of the campaign + */ + t.literal('campaignId'), + + /** + * Unique name of the campaign + */ + t.literal('campaignName'), + + /** + * Unique numerical ID of the ad group + */ + t.literal('adGroupId'), + + /** + * Unique name of the ad group + */ + t.literal('adGroupName'), + + t.literal('campaignBudgetType'), + + /** + * Status of the campaign + */ + t.literal('campaignStatus'), + + /** + * ID of the keyword used in bid + */ + t.literal('keywordId'), + + /** + * Keyword state. + */ + t.literal('keywordStatus'), + + /** + * User-set bid value for keyword. + */ + t.literal('keywordBid'), + + /** + * Text of the keyword or phrase used in bid + */ + t.literal('keywordText'), + + /** + * Type of matching for the keyword or phrase used in bid. Must be one of: broad, phrase, or exact + */ + t.literal('matchType'), +]) +export type SponsoredBrandsKeywordReportMetrics = t.TypeOf< + typeof SponsoredBrandsKeywordReportMetrics +> diff --git a/src/operations/reports/sponsored-brands/sponsored-brands-ad-group-report-params.ts b/src/operations/reports/sponsored-brands/sponsored-brands-ad-group-report-params.ts index b40570361..fcd039e51 100644 --- a/src/operations/reports/sponsored-brands/sponsored-brands-ad-group-report-params.ts +++ b/src/operations/reports/sponsored-brands/sponsored-brands-ad-group-report-params.ts @@ -1,8 +1,8 @@ import { BaseReportParams } from '../base-report-params' import { SponsoredBrandsReportTypeEnum } from '../report-types-enum' -import { SponsoredProductsAdGroupReportMetrics } from '../metrics/sponsored-products-ad-group-report-metrics' +import { SponsoredBrandsAdGroupReportMetrics } from '../metrics' export interface SponsoredBrandsAdGroupReportParams - extends BaseReportParams { + extends BaseReportParams { recordType: SponsoredBrandsReportTypeEnum.AD_GROUPS } diff --git a/src/operations/reports/sponsored-brands/sponsored-brands-keyword-report-params.ts b/src/operations/reports/sponsored-brands/sponsored-brands-keyword-report-params.ts index ddd50f62a..e555259e8 100644 --- a/src/operations/reports/sponsored-brands/sponsored-brands-keyword-report-params.ts +++ b/src/operations/reports/sponsored-brands/sponsored-brands-keyword-report-params.ts @@ -1,8 +1,8 @@ import { BaseReportParams } from '../base-report-params' import { SponsoredBrandsReportTypeEnum } from '../report-types-enum' -import { SponsoredProductsKeywordReportMetrics } from '../metrics/sponsored-products-keyword-report-metrics' +import { SponsoredBrandsKeywordReportMetrics } from '../metrics' export interface SponsoredBrandsKeywordReportParams - extends BaseReportParams { + extends BaseReportParams { recordType: SponsoredBrandsReportTypeEnum.KEYWORDS } diff --git a/test/__recordings__/SponsoredBrandsReportOperation_783097385/requestReport_2012826696/should-return-a-in-progress-status-with-adgroups-report_3288827722/recording.har b/test/__recordings__/SponsoredBrandsReportOperation_783097385/requestReport_2012826696/should-return-a-in-progress-status-with-adgroups-report_3288827722/recording.har deleted file mode 100644 index c853c9ef4..000000000 --- a/test/__recordings__/SponsoredBrandsReportOperation_783097385/requestReport_2012826696/should-return-a-in-progress-status-with-adgroups-report_3288827722/recording.har +++ /dev/null @@ -1,126 +0,0 @@ -{ - "log": { - "_recordingName": "SponsoredBrandsReportOperation/requestReport/should return a in progress status with adgroups report", - "creator": { - "comment": "persister:fs", - "name": "Polly.JS", - "version": "4.0.2" - }, - "entries": [ - { - "_id": "d58277f0c4d05f9d78e1b94b30f492ee", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 100, - "cookies": [], - "headers": [ - { - "_fromType": "array", - "name": "content-type", - "value": "application/json" - }, - { - "_fromType": "array", - "name": "accept", - "value": "application/json" - }, - { - "_fromType": "array", - "name": "user-agent", - "value": "amazon-advertising-api-sdk/1.3.0" - }, - { - "_fromType": "array", - "name": "amazon-advertising-api-scope", - "value": "2984328618318898" - }, - { - "_fromType": "array", - "name": "bidding_controls_on", - "value": "true" - }, - { - "_fromType": "array", - "name": "accept-encoding", - "value": "application/json" - }, - { - "_fromType": "array", - "name": "content-length", - "value": "100" - }, - { - "_fromType": "array", - "name": "connection", - "value": "close" - }, - { - "name": "host", - "value": "advertising-api-test.amazon.com" - } - ], - "headersSize": 1124, - "httpVersion": "HTTP/1.1", - "method": "POST", - "postData": { - "mimeType": "application/json", - "params": [], - "text": "{\"metrics\":\"campaignId,campaignName,adGroupId,adGroupName,cost,impressions\",\"reportDate\":\"20200314\"}" - }, - "queryString": [], - "url": "https://advertising-api-test.amazon.com/v2/hsa/adGroups/report" - }, - "response": { - "bodySize": 164, - "content": { - "mimeType": "text/plain", - "size": 164, - "text": "{\"reportId\":\"amzn1.clicksAPI.v1.m1.5E6C4F31.a87597c1-ab1c-442e-9b71-51374a0fe709\",\"recordType\":\"adGroup\",\"status\":\"IN_PROGRESS\",\"statusDetails\":\"Generating report\"}" - }, - "cookies": [], - "headers": [ - { - "name": "server", - "value": "Server" - }, - { - "name": "date", - "value": "Sat, 14 Mar 2020 03:27:45 GMT" - }, - { - "name": "transfer-encoding", - "value": "chunked" - }, - { - "name": "connection", - "value": "close" - }, - { - "name": "vary", - "value": "Accept-Encoding,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment,User-Agent" - } - ], - "headersSize": 206, - "httpVersion": "HTTP/1.1", - "redirectURL": "", - "status": 202, - "statusText": "Accepted" - }, - "startedDateTime": "2020-03-14T03:27:45.629Z", - "time": 106, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 106 - } - } - ], - "pages": [], - "version": "1.2" - } -} diff --git a/test/__recordings__/SponsoredBrandsReportOperation_783097385/requestReport_2012826696/should-return-a-in-progress-status-with-keywords-report_4030230505/recording.har b/test/__recordings__/SponsoredBrandsReportOperation_783097385/requestReport_2012826696/should-return-a-in-progress-status-with-keywords-report_4030230505/recording.har deleted file mode 100644 index 5a5490e55..000000000 --- a/test/__recordings__/SponsoredBrandsReportOperation_783097385/requestReport_2012826696/should-return-a-in-progress-status-with-keywords-report_4030230505/recording.har +++ /dev/null @@ -1,126 +0,0 @@ -{ - "log": { - "_recordingName": "SponsoredBrandsReportOperation/requestReport/should return a in progress status with keywords report", - "creator": { - "comment": "persister:fs", - "name": "Polly.JS", - "version": "4.0.2" - }, - "entries": [ - { - "_id": "5916ac2a49cc512e63e39fa103350328", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 75, - "cookies": [], - "headers": [ - { - "_fromType": "array", - "name": "content-type", - "value": "application/json" - }, - { - "_fromType": "array", - "name": "accept", - "value": "application/json" - }, - { - "_fromType": "array", - "name": "user-agent", - "value": "amazon-advertising-api-sdk/1.3.0" - }, - { - "_fromType": "array", - "name": "amazon-advertising-api-scope", - "value": "2984328618318898" - }, - { - "_fromType": "array", - "name": "bidding_controls_on", - "value": "true" - }, - { - "_fromType": "array", - "name": "accept-encoding", - "value": "application/json" - }, - { - "_fromType": "array", - "name": "content-length", - "value": "75" - }, - { - "_fromType": "array", - "name": "connection", - "value": "close" - }, - { - "name": "host", - "value": "advertising-api-test.amazon.com" - } - ], - "headersSize": 1123, - "httpVersion": "HTTP/1.1", - "method": "POST", - "postData": { - "mimeType": "application/json", - "params": [], - "text": "{\"metrics\":\"campaignId,keywordId,cost,impressions\",\"reportDate\":\"20200314\"}" - }, - "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.5E6C4F31.e103637b-95fb-4a74-a0ae-f1679d971733\",\"recordType\":\"keyword\",\"status\":\"IN_PROGRESS\",\"statusDetails\":\"Generating report\"}" - }, - "cookies": [], - "headers": [ - { - "name": "server", - "value": "Server" - }, - { - "name": "date", - "value": "Sat, 14 Mar 2020 03:27:45 GMT" - }, - { - "name": "transfer-encoding", - "value": "chunked" - }, - { - "name": "connection", - "value": "close" - }, - { - "name": "vary", - "value": "Accept-Encoding,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment,User-Agent" - } - ], - "headersSize": 206, - "httpVersion": "HTTP/1.1", - "redirectURL": "", - "status": 202, - "statusText": "Accepted" - }, - "startedDateTime": "2020-03-14T03:27:45.741Z", - "time": 107, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 107 - } - } - ], - "pages": [], - "version": "1.2" - } -} diff --git a/test/index.test.ts b/test/index.test.ts index a59732d84..fa6e557da 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -169,12 +169,18 @@ describe('index', () => { reportEnum.SponsoredProductsReportTypeEnum, ) expect(index.ReportResponseStatusType).toEqual(reportEnum.ReportResponseStatusType) + expect(index.SponsoredBrandsAdGroupReportMetrics).toEqual( + reportEnum.SponsoredBrandsAdGroupReportMetrics, + ) expect(index.SponsoredBrandsCampaignReportMetrics).toEqual( reportEnum.SponsoredBrandsCampaignReportMetrics, ) expect(index.SponsoredBrandsHeadlineSearchReportMetrics).toEqual( reportEnum.SponsoredBrandsHeadlineSearchReportMetrics, ) + expect(index.SponsoredBrandsKeywordReportMetrics).toEqual( + reportEnum.SponsoredBrandsKeywordReportMetrics, + ) }) }) 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 448a0daca..27848c99d 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 @@ -3,6 +3,7 @@ import { httpClientFactory } from '../../../http-client-factory' import { SponsoredBrandsReportOperation } from '../../../../src/operations/reports/sponsored-brands/sponsored-brands-report-operation' import { SponsoredBrandsReportTypeEnum } from '../../../../src/operations/reports/report-types-enum' import { ReportResponseStatusEnum } from '../../../../src/operations/reports/report-response' +import { delay } from '../../../test-utils' jest.setTimeout(15000) @@ -28,7 +29,15 @@ describe('SponsoredBrandsReportOperation', () => { it(`should return a in progress status with adgroups report`, async () => { const res = await reportOperation.requestReport({ recordType: SponsoredBrandsReportTypeEnum.AD_GROUPS, - metrics: ['campaignId', 'campaignName', 'adGroupId', 'adGroupName', 'cost', 'impressions'], + metrics: [ + 'campaignId', + 'campaignName', + 'campaignBudget', + 'campaignBudgetType', + 'campaignStatus', + 'adGroupName', + 'adGroupId', + ], reportDate: '20200314', }) @@ -41,7 +50,19 @@ describe('SponsoredBrandsReportOperation', () => { it(`should return a in progress status with keywords report`, async () => { const res = await reportOperation.requestReport({ recordType: SponsoredBrandsReportTypeEnum.KEYWORDS, - metrics: ['campaignId', 'keywordId', 'cost', 'impressions'], + metrics: [ + 'campaignId', + 'campaignName', + 'adGroupId', + 'adGroupName', + 'campaignBudgetType', + 'campaignStatus', + 'keywordId', + 'keywordStatus', + 'keywordBid', + 'keywordText', + 'matchType', + ], reportDate: '20200314', }) @@ -54,12 +75,27 @@ describe('SponsoredBrandsReportOperation', () => { describe('getReport', () => { it(`only return report location when report status is SUCCESS`, async () => { + expect.assertions(4) const requestReportResult = await reportOperation.requestReport({ recordType: SponsoredBrandsReportTypeEnum.KEYWORDS, - metrics: ['campaignId', 'keywordId', 'cost', 'impressions'], + metrics: [ + 'campaignId', + 'campaignName', + 'adGroupId', + 'adGroupName', + 'campaignBudgetType', + 'campaignStatus', + 'keywordId', + 'keywordStatus', + 'keywordBid', + 'keywordText', + 'matchType', + ], reportDate: '20200314', }) + delay(60000) + const res = await reportOperation.getReport(requestReportResult.reportId) expect(res.reportId).toBeDefined() expect(res.statusDetails).toBeDefined()