Skip to content

Commit 076869f

Browse files
fix: updates campaign types edge case no strategy (#789)
* 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
1 parent 3048769 commit 076869f

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/operations/campaigns/types.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,23 @@ describe('SponsoredDisplayCampaign', () => {
127127
})
128128
})
129129

130+
describe('Campaign Edge Case', () => {
131+
it('should allow a non-existent strategy when parsing the bidding parameter', () => {
132+
const edgecaseFragment = t.Campaign.decode({
133+
campaignId: 108971111858080,
134+
name: 'test',
135+
campaignType: 'sponsoredProducts',
136+
targetingType: 'auto',
137+
premiumBidAdjustment: false,
138+
dailyBudget: 1,
139+
startDate: '20161024',
140+
state: 'archived',
141+
bidding: { adjustments: [] }
142+
});
143+
expect(isRight(edgecaseFragment)).toBeTruthy();
144+
});
145+
});
146+
130147
/**
131148
* TODO: Update test script:
132149
* SponsoredBrandsCampaign should pass listCampaigns response

src/operations/campaigns/types.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ export const CampaignState = t.union([
4343
])
4444
export type CampaignState = t.TypeOf<typeof CampaignState>
4545

46-
export const CampaignBidding = t.type({
47-
strategy: CampaignBiddingStrategy,
48-
adjustments: CampaignBiddingAdjustments,
49-
})
46+
export const CampaignBidding = t.intersection([
47+
t.type({
48+
adjustments: CampaignBiddingAdjustments
49+
}),
50+
t.partial({
51+
strategy: CampaignBiddingStrategy
52+
})
53+
])
5054
export type CampaignBidding = t.TypeOf<typeof CampaignBidding>
5155

5256
export const Campaign = t.intersection([

0 commit comments

Comments
 (0)