Skip to content

Commit

Permalink
feat: set endDate, costType and deliveryProfile to be optional
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyentoanit committed Aug 18, 2020
1 parent 73edfe0 commit f18f55f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 34 deletions.
18 changes: 18 additions & 0 deletions src/operations/campaigns/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,24 @@ describe('CampaignResponse', () => {
})
})

describe('SponsoredDisplayCampaign', () => {
it('should pass', () => {
const res = t.SponsoredDisplayCampaign.decode({
campaignId: 169989740510339,
name: 'test sd campaign 2020/08/13 21:42',
tactic: 'remarketing',
budget: 1,
budgetType: 'daily',
costType: 'cpc',
deliveryProfile: 'as_soon_as_possible',
startDate: '20201210',
state: 'enabled',
})

expect(isRight(res)).toBeTruthy()
})
})

/**
* TODO: Update test script:
* SponsoredBrandsCampaign should pass listCampaigns response
Expand Down
79 changes: 45 additions & 34 deletions src/operations/campaigns/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export const CampaignServingStatus = t.union([
t.literal('ACCOUNT_OUT_OF_BUDGET'),
t.literal('PORTFOLIO_ENDED'), // The docs don't say about this type
t.literal('CAMPAIGN_INCOMPLETE'), // The docs don't say about this type
t.literal('PENDING_START_DATE'), // The docs don't say about this type
])
export type CampaignServingStatus = t.TypeOf<typeof CampaignServingStatus>

Expand Down Expand Up @@ -539,47 +540,57 @@ export const ListCampaignsParams = t.intersection([
export type ListCampaignsParams = t.TypeOf<typeof ListCampaignsParams>

// Sponsored Display types
export const SponsoredDisplayCampaign = t.strict({
/**
* The ID of the campaign.
*/
campaignId: CampaignId,
export const SponsoredDisplayCampaign = t.intersection([
t.strict({
/**
* The ID of the campaign.
*/
campaignId: CampaignId,

/**
* The name of the campaign.
*/
name: CampaignName,
/**
* The name of the campaign.
*/
name: CampaignName,

/**
* The advertising tactic associated with the campaign.
*/
tactic: Tactic,
/**
* The advertising tactic associated with the campaign.
*/
tactic: Tactic,

/**
* The time period over which the amount specified in the budget property is allocated.
*/
budgetType: t.literal('daily'),
/**
* The time period over which the amount specified in the budget property is allocated.
*/
budgetType: t.literal('daily'),

/**
* The amount of the budget.
*/
budget: t.number,
/**
* The amount of the budget.
*/
budget: t.number,

/**
* The YYYYMMDD start date of the campaign. The date must be today or in the future.
*/
startDate: t.string,
/**
* The YYYYMMDD start date of the campaign. The date must be today or in the future.
*/
startDate: t.string,

/**
* The YYYYMMDD end date of the campaign.
*/
endDate: t.string,
/**
* The state of the campaign.
*/
state: CampaignState,
}),
t.partial({
/**
* The YYYYMMDD end date of the campaign.
*/
endDate: t.string,

/**
* The docs don't metion these fields
*/
costType: t.literal('cpc'),
deliveryProfile: t.literal('as_soon_as_possible'),
}),
])

/**
* The state of the campaign.
*/
state: CampaignState,
})
export type SponsoredDisplayCampaign = t.TypeOf<typeof SponsoredDisplayCampaign>

export const SponsoredDisplayCampaignExtended = t.intersection([
Expand Down

0 comments on commit f18f55f

Please sign in to comment.