Skip to content

Commit

Permalink
feat: add sb target report
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyentoanit committed Apr 20, 2020
1 parent d5858c9 commit 1acdb28
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/operations/reports/metrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './sponsored-brands-campaign-report-metrics'
export * from './sponsored-brands-headline-search-report-metrics'
export * from './sponsored-brands-keyword-report-metrics'
export * from './sponsored-brands-search-term-report-metrics'
export * from './sponsored-brands-target-report-metrics'
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import * as t from 'io-ts'

export const SponsoredBrandsTargetReportMetrics = 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'),

/**
* One of: daily or lifetime
*/
t.literal('campaignBudgetType'),

/**
* Status of the campaign
*/
t.literal('campaignStatus'),

/**
* The product target identifier
*/
t.literal('targetId'),

/**
* The product targeting expression. Not available for search term report.
*/
t.literal('targetingExpression'),

/**
* The product targeting type.
* One of: asinCategorySameAs, asinBrandSameAs, asinPriceLessThan, asinPriceBetween, asinPriceGreaterThan, asinReviewRatingLessThan, asinReviewRatingBetween, asinReviewRatingGreaterThan, asinSameAs.
* Not available for search term report.
*/
t.literal('targetingType'),

/**
* The product targeting text. Not available for search term report.
*/
t.literal('targetingText'),

/**
* Type of matching for the keyword or phrase used in bid. Must be one of: broad, phrase, or exact
*/
t.literal('matchType'),
])
export type SponsoredBrandsTargetReportMetrics = t.TypeOf<typeof SponsoredBrandsTargetReportMetrics>
1 change: 1 addition & 0 deletions src/operations/reports/report-types-enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export enum SponsoredBrandsReportTypeEnum {
KEYWORDS = 'keywords',
HEADLINE_SEARCH = 'headlineSearch',
SEARCH_TERM = 'searchTerms',
TARGETS = 'targets',
}
1 change: 1 addition & 0 deletions src/operations/reports/sponsored-brands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './sponsored-brands-campaign-report-params'
export * from './sponsored-brands-keyword-report-params'
export * from './sponsored-brands-headline-search-report-params'
export * from './sponsored-brands-search-term-report-params'
export * from './sponsored-brands-target-report-params'
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
SponsoredBrandsKeywordReportParams,
SponsoredBrandsHeadlineSearchReportParams,
SponsoredBrandsSearchTermReportParams,
SponsoredBrandsTargetReportParams,
} from './index'

type SponsoredBrandsReportParams =
Expand All @@ -16,6 +17,8 @@ type SponsoredBrandsReportParams =
| SponsoredBrandsKeywordReportParams
| SponsoredBrandsHeadlineSearchReportParams
| SponsoredBrandsSearchTermReportParams
| SponsoredBrandsSearchTermReportParams
| SponsoredBrandsTargetReportParams

export class SponsoredBrandsReportOperation<
ReportParams extends SponsoredBrandsReportParams
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { BaseReportParams } from '../base-report-params'
import { SponsoredBrandsReportTypeEnum } from '../report-types-enum'
import { SponsoredBrandsTargetReportMetrics } from '../metrics'

export interface SponsoredBrandsTargetReportParams
extends BaseReportParams<SponsoredBrandsReportTypeEnum, SponsoredBrandsTargetReportMetrics> {
recordType: SponsoredBrandsReportTypeEnum.TARGETS
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,31 @@ describe('SponsoredBrandsReportOperation', () => {
expect(res.status).toBe(ReportResponseStatusEnum.IN_PROGRESS)
expect(res.statusDetails).toBeDefined()
})

it(`should return a in progress status with target report`, async () => {
const res = await reportOperation.requestReport({
recordType: SponsoredBrandsReportTypeEnum.TARGETS,
metrics: [
'campaignId',
'campaignName',
'adGroupId',
'adGroupName',
'campaignBudgetType',
'campaignStatus',
'targetId',
'targetingExpression',
'targetingType',
'targetingText',
'matchType',
],
reportDate: '20200314',
})

expect(res.reportId).toBeDefined()
expect(res.recordType).toBeDefined()
expect(res.status).toBe(ReportResponseStatusEnum.IN_PROGRESS)
expect(res.statusDetails).toBeDefined()
})
})

describe('getReport', () => {
Expand Down

0 comments on commit 1acdb28

Please sign in to comment.