Skip to content

Commit

Permalink
fix: updates campaign types edge case no strategy (#789)
Browse files Browse the repository at this point in the history
* feat: adding test for campaign results edge case 

added test for where campaign response has no bidding strategy by making it optional

* feat: updating the type to handle non-existent strategy 

updating the type spec for campaign where the bidding strategy is not returned
  • Loading branch information
mayan-jbsmith authored Jun 22, 2021
1 parent 3048769 commit 076869f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
17 changes: 17 additions & 0 deletions src/operations/campaigns/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,23 @@ describe('SponsoredDisplayCampaign', () => {
})
})

describe('Campaign Edge Case', () => {
it('should allow a non-existent strategy when parsing the bidding parameter', () => {
const edgecaseFragment = t.Campaign.decode({
campaignId: 108971111858080,
name: 'test',
campaignType: 'sponsoredProducts',
targetingType: 'auto',
premiumBidAdjustment: false,
dailyBudget: 1,
startDate: '20161024',
state: 'archived',
bidding: { adjustments: [] }
});
expect(isRight(edgecaseFragment)).toBeTruthy();
});
});

/**
* TODO: Update test script:
* SponsoredBrandsCampaign should pass listCampaigns response
Expand Down
12 changes: 8 additions & 4 deletions src/operations/campaigns/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ export const CampaignState = t.union([
])
export type CampaignState = t.TypeOf<typeof CampaignState>

export const CampaignBidding = t.type({
strategy: CampaignBiddingStrategy,
adjustments: CampaignBiddingAdjustments,
})
export const CampaignBidding = t.intersection([
t.type({
adjustments: CampaignBiddingAdjustments
}),
t.partial({
strategy: CampaignBiddingStrategy
})
])
export type CampaignBidding = t.TypeOf<typeof CampaignBidding>

export const Campaign = t.intersection([
Expand Down

0 comments on commit 076869f

Please sign in to comment.