From 076869f3d5983cd49c280d1e9afe2d2706be90ce Mon Sep 17 00:00:00 2001 From: mayan-jbsmith <85377498+mayan-jbsmith@users.noreply.github.com> Date: Tue, 22 Jun 2021 08:04:05 -0700 Subject: [PATCH] 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 --- src/operations/campaigns/types.test.ts | 17 +++++++++++++++++ src/operations/campaigns/types.ts | 12 ++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/operations/campaigns/types.test.ts b/src/operations/campaigns/types.test.ts index 921def0ca..ec0dc8430 100644 --- a/src/operations/campaigns/types.test.ts +++ b/src/operations/campaigns/types.test.ts @@ -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 diff --git a/src/operations/campaigns/types.ts b/src/operations/campaigns/types.ts index 4419e9672..354ddd5e3 100644 --- a/src/operations/campaigns/types.ts +++ b/src/operations/campaigns/types.ts @@ -43,10 +43,14 @@ export const CampaignState = t.union([ ]) export type CampaignState = t.TypeOf -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 export const Campaign = t.intersection([