Skip to content

Commit

Permalink
feat: change campaign bidding adjustments predicate and strategy to u…
Browse files Browse the repository at this point in the history
…se union string
  • Loading branch information
nguyentoanit committed Apr 20, 2020
1 parent fded09c commit 89d0d0e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 37 deletions.
19 changes: 7 additions & 12 deletions src/operations/bidding/campaign-bidding-adjustments-predicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/

import * as t from 'io-ts'
import { createEnumType } from '../commons/types'

/**
* You can enable controls to adjust your bid based on the placement location.
Expand All @@ -12,29 +11,25 @@ import { createEnumType } from '../commons/types'
* bid adjustment increased. For example, a 50% adjustment on a $1.00 bid would increase the bid
* to $1.50 for the opportunity to win a specified placement.
*/
export enum CampaignBiddingAdjustmentsPredicateEnum {
export const CampaignBiddingAdjustmentsPredicate = t.union([
/**
* Top of search (first page)
*/
PLACEMENT_TOP = 'placementTop',
t.literal('placementTop'),

/**
* Product pages
*/
PLACEMENT_PRODUCT_PAGE = 'placementProductPage',
}

export const CampaignBiddingAdjustmentsPredicateType = createEnumType<
CampaignBiddingAdjustmentsPredicateEnum
>(CampaignBiddingAdjustmentsPredicateEnum)
export type CampaignBiddingAdjustmentsPredicateType = t.TypeOf<
typeof CampaignBiddingAdjustmentsPredicateType
t.literal('placementProductPage'),
])
export type CampaignBiddingAdjustmentsPredicate = t.TypeOf<
typeof CampaignBiddingAdjustmentsPredicate
>

export const CampaignBiddingAdjustments = t.array(
t.intersection([
t.type({
predicate: CampaignBiddingAdjustmentsPredicateType,
predicate: CampaignBiddingAdjustmentsPredicate,
}),
t.partial({
percentage: t.number,
Expand Down
16 changes: 6 additions & 10 deletions src/operations/bidding/campaign-bidding-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,25 @@
*/

import * as t from 'io-ts'
import { createEnumType } from '../commons/types'

export enum CampaignBiddingStrategyEnum {
export const CampaignBiddingStrategy = t.union([
/**
* Lowers your bids in real time when your ad may be less likely to convert to a sale.
* Campaigns created before the release of the bidding controls feature used this setting by default.
*/
LEGACY_FOR_SALES = 'legacyForSales',
t.literal('legacyForSales'),

/**
* Increases or decreases your bids in real time by a maximum of 100%.
* With this setting bids increase when your ad is more likely to convert to a sale,
* and bids decrease when less likely to convert to a sale.
*/
AUTO_FOR_SALES = 'autoForSales',
t.literal('autoForSales'),

/**
* Uses your exact bid and any placement adjustments you set, and is not subject to dynamic
* bidding.
*/
MANUAL = 'manual',
}
export const CampaignBiddingStrategyType = createEnumType<CampaignBiddingStrategyEnum>(
CampaignBiddingStrategyEnum,
)
export type CampaignBiddingStrategyType = t.TypeOf<typeof CampaignBiddingStrategyType>
t.literal('manual'),
])
export type CampaignBiddingStrategy = t.TypeOf<typeof CampaignBiddingStrategy>
4 changes: 2 additions & 2 deletions src/operations/campaigns/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as t from 'io-ts'
import { ResponseStatus, ListPagination } from '../commons/types'
import { DateFromNumber } from 'io-ts-types/lib/DateFromNumber'
import { PortfolioId } from '../portfolios/types'
import { CampaignBiddingStrategyType } from '../bidding/campaign-bidding-strategy'
import { CampaignBiddingStrategy } from '../bidding/campaign-bidding-strategy'
import { CampaignBiddingAdjustments } from '../bidding/campaign-bidding-adjustments-predicate'

/**
Expand Down Expand Up @@ -44,7 +44,7 @@ export const CampaignState = t.union([
export type CampaignState = t.TypeOf<typeof CampaignState>

export const CampaignBidding = t.type({
strategy: CampaignBiddingStrategyType,
strategy: CampaignBiddingStrategy,
adjustments: CampaignBiddingAdjustments,
})
export type CampaignBidding = t.TypeOf<typeof CampaignBidding>
Expand Down
10 changes: 4 additions & 6 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as index from '../src/index'
import * as adGroupEnums from '../src/operations/ad-groups/types'
import { CampaignBiddingAdjustmentsPredicateEnum } from '../src/operations/bidding/campaign-bidding-adjustments-predicate'
import { CampaignBiddingStrategyEnum } from '../src/operations/bidding/campaign-bidding-strategy'
import { CampaignBiddingAdjustmentsPredicate } from '../src/operations/bidding/campaign-bidding-adjustments-predicate'
import { CampaignBiddingStrategy } from '../src/operations/bidding/campaign-bidding-strategy'
import * as biddingEnums from '../src/operations/bidding/types'
import * as campaignEnums from '../src/operations/campaigns/types'
import { BudgetType } from '../src/operations/drafts/types'
Expand All @@ -25,10 +25,8 @@ describe('index', () => {

describe('bidding', () => {
it('should export all enums', () => {
expect(index.CampaignBiddingAdjustmentsPredicateEnum).toEqual(
CampaignBiddingAdjustmentsPredicateEnum,
)
expect(index.CampaignBiddingStrategyEnum).toEqual(CampaignBiddingStrategyEnum)
expect(index.CampaignBiddingAdjustmentsPredicate).toEqual(CampaignBiddingAdjustmentsPredicate)
expect(index.CampaignBiddingStrategy).toEqual(CampaignBiddingStrategy)
expect(index.BidRecommendationsResponseCode).toEqual(
biddingEnums.BidRecommendationsResponseCode,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { OperationProvider } from '../../../src/operations/operation-provider'
import { SponsoredProductsCampaignOperation } from '../../../src/operations/campaigns/sponsored-products-campaign-operation'
import { CampaignBidding, CampaignState } from '../../../src/operations/campaigns/types'
import { httpClientFactory } from '../../http-client-factory'
import { CampaignBiddingStrategyEnum } from '../../../src/operations/bidding/campaign-bidding-strategy'
import { CampaignBiddingAdjustmentsPredicateEnum } from '../../../src/operations/bidding/campaign-bidding-adjustments-predicate'

describe('SponsoredProductsCampaignOperation', () => {
const client = httpClientFactory()
Expand Down Expand Up @@ -72,10 +70,10 @@ describe('SponsoredProductsCampaignOperation', () => {
it(`should create a campaign with auto bidding controls`, async () => {
expect.assertions(2)
const bidding: CampaignBidding = {
strategy: CampaignBiddingStrategyEnum.AUTO_FOR_SALES,
strategy: 'autoForSales',
adjustments: [
{
predicate: CampaignBiddingAdjustmentsPredicateEnum.PLACEMENT_TOP,
predicate: 'placementTop',
percentage: 900,
},
],
Expand Down Expand Up @@ -128,14 +126,14 @@ describe('SponsoredProductsCampaignOperation', () => {

it(`should update a campaign with manual bidding controls`, async () => {
const bidding: CampaignBidding = {
strategy: CampaignBiddingStrategyEnum.MANUAL,
strategy: 'manual',
adjustments: [
{
predicate: CampaignBiddingAdjustmentsPredicateEnum.PLACEMENT_TOP,
predicate: 'placementTop',
percentage: 1,
},
{
predicate: CampaignBiddingAdjustmentsPredicateEnum.PLACEMENT_PRODUCT_PAGE,
predicate: 'placementProductPage',
percentage: 2,
},
],
Expand Down

0 comments on commit 89d0d0e

Please sign in to comment.