From 919b74b61ea18eb42bed9b698376e6f263c5f72b Mon Sep 17 00:00:00 2001 From: bsardo <1168933+bsardo@users.noreply.github.com> Date: Wed, 7 Jun 2023 11:09:10 -0400 Subject: [PATCH] Fix: deal tiers no longer ignored due to presence of tid --- exchange/exchange_test.go | 30 +++++++++++------------ openrtb_ext/deal_tier.go | 14 ----------- openrtb_ext/deal_tier_test.go | 45 ++++++++++++++++------------------- 3 files changed, 35 insertions(+), 54 deletions(-) diff --git a/exchange/exchange_test.go b/exchange/exchange_test.go index 141defc8675..7180cfbce46 100644 --- a/exchange/exchange_test.go +++ b/exchange/exchange_test.go @@ -3587,7 +3587,7 @@ func TestApplyDealSupport(t *testing.T) { { description: "hb_pb_cat_dur should be modified", dealPriority: 5, - impExt: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier"}, "placementId": 10433394}}`), + impExt: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier"}, "placementId": 10433394}}}}`), targ: map[string]string{ "hb_pb_cat_dur": "12.00_movies_30s", }, @@ -3598,7 +3598,7 @@ func TestApplyDealSupport(t *testing.T) { { description: "hb_pb_cat_dur should not be modified due to priority not exceeding min", dealPriority: 9, - impExt: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 10, "prefix": "tier"}, "placementId": 10433394}}`), + impExt: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 10, "prefix": "tier"}, "placementId": 10433394}}}}`), targ: map[string]string{ "hb_pb_cat_dur": "12.00_medicine_30s", }, @@ -3609,7 +3609,7 @@ func TestApplyDealSupport(t *testing.T) { { description: "hb_pb_cat_dur should not be modified due to invalid config", dealPriority: 5, - impExt: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 5, "prefix": ""}, "placementId": 10433394}}`), + impExt: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 5, "prefix": ""}, "placementId": 10433394}}}}`), targ: map[string]string{ "hb_pb_cat_dur": "12.00_games_30s", }, @@ -3620,7 +3620,7 @@ func TestApplyDealSupport(t *testing.T) { { description: "hb_pb_cat_dur should not be modified due to deal priority of 0", dealPriority: 0, - impExt: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier"}, "placementId": 10433394}}`), + impExt: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier"}, "placementId": 10433394}}}}`), targ: map[string]string{ "hb_pb_cat_dur": "12.00_auto_30s", }, @@ -3690,11 +3690,11 @@ func TestApplyDealSupportMultiBid(t *testing.T) { Imp: []openrtb2.Imp{ { ID: "imp_id1", - Ext: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier"}, "placementId": 10433394}}`), + Ext: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier"}, "placementId": 10433394}}}}`), }, { ID: "imp_id1", - Ext: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier"}, "placementId": 10433394}}`), + Ext: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier"}, "placementId": 10433394}}}}`), }, }, }, @@ -3736,11 +3736,11 @@ func TestApplyDealSupportMultiBid(t *testing.T) { Imp: []openrtb2.Imp{ { ID: "imp_id1", - Ext: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier"}, "placementId": 10433394}}`), + Ext: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier"}, "placementId": 10433394}}}}`), }, { ID: "imp_id1", - Ext: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier"}, "placementId": 10433394}}`), + Ext: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier"}, "placementId": 10433394}}}}`), }, }, }, @@ -3787,11 +3787,11 @@ func TestApplyDealSupportMultiBid(t *testing.T) { Imp: []openrtb2.Imp{ { ID: "imp_id1", - Ext: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier"}, "placementId": 10433394}}`), + Ext: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier"}, "placementId": 10433394}}}}`), }, { ID: "imp_id1", - Ext: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier"}, "placementId": 10433394}}`), + Ext: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier"}, "placementId": 10433394}}}}`), }, }, }, @@ -3864,7 +3864,7 @@ func TestGetDealTiers(t *testing.T) { description: "One", request: openrtb2.BidRequest{ Imp: []openrtb2.Imp{ - {ID: "imp1", Ext: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier"}}}`)}, + {ID: "imp1", Ext: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier"}}}}}`)}, }, }, expected: map[string]openrtb_ext.DealTierBidderMap{ @@ -3875,8 +3875,8 @@ func TestGetDealTiers(t *testing.T) { description: "Many", request: openrtb2.BidRequest{ Imp: []openrtb2.Imp{ - {ID: "imp1", Ext: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier1"}}}`)}, - {ID: "imp2", Ext: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 8, "prefix": "tier2"}}}`)}, + {ID: "imp1", Ext: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier1"}}}}}`)}, + {ID: "imp2", Ext: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 8, "prefix": "tier2"}}}}}`)}, }, }, expected: map[string]openrtb_ext.DealTierBidderMap{ @@ -3888,8 +3888,8 @@ func TestGetDealTiers(t *testing.T) { description: "Many - Skips Malformed", request: openrtb2.BidRequest{ Imp: []openrtb2.Imp{ - {ID: "imp1", Ext: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier1"}}}`)}, - {ID: "imp2", Ext: json.RawMessage(`{"appnexus": {"dealTier": "wrong type"}}`)}, + {ID: "imp1", Ext: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "tier1"}}}}}`)}, + {ID: "imp2", Ext: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": "wrong type"}}}}`)}, }, }, expected: map[string]openrtb_ext.DealTierBidderMap{ diff --git a/openrtb_ext/deal_tier.go b/openrtb_ext/deal_tier.go index ef85b9b1df8..45285d21663 100644 --- a/openrtb_ext/deal_tier.go +++ b/openrtb_ext/deal_tier.go @@ -27,20 +27,6 @@ func ReadDealTiersFromImp(imp openrtb2.Imp) (DealTierBidderMap, error) { return dealTiers, nil } - // imp.ext.{bidder} - var impExt map[string]struct { - DealTier *DealTier `json:"dealTier"` - } - if err := json.Unmarshal(imp.Ext, &impExt); err != nil { - return nil, err - } - for bidder, param := range impExt { - if param.DealTier != nil { - dealTiers[BidderName(bidder)] = *param.DealTier - } - } - - // imp.ext.prebid.{bidder} var impPrebidExt struct { Prebid struct { Bidders map[string]struct { diff --git a/openrtb_ext/deal_tier_test.go b/openrtb_ext/deal_tier_test.go index 6aaebbab687..0046b788ece 100644 --- a/openrtb_ext/deal_tier_test.go +++ b/openrtb_ext/deal_tier_test.go @@ -31,55 +31,50 @@ func TestReadDealTiersFromImp(t *testing.T) { expectedResult: DealTierBidderMap{}, }, { - description: "imp.ext - with other params", - impExt: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "anyPrefix"}, "placementId": 12345}}`), - expectedResult: DealTierBidderMap{BidderAppnexus: {Prefix: "anyPrefix", MinDealTier: 5}}, + description: "imp.ext - no prebid but with other params", + impExt: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "anyPrefix"}, "placementId": 12345}, "tid": "1234"}`), + expectedResult: DealTierBidderMap{}, }, { - description: "imp.ext - multiple", - impExt: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "appnexusPrefix"}, "placementId": 12345}, "rubicon": {"dealTier": {"minDealTier": 8, "prefix": "rubiconPrefix"}, "placementId": 12345}}`), - expectedResult: DealTierBidderMap{BidderAppnexus: {Prefix: "appnexusPrefix", MinDealTier: 5}, BidderRubicon: {Prefix: "rubiconPrefix", MinDealTier: 8}}, + description: "imp.ext.prebid - nil", + impExt: json.RawMessage(`{"prebid": null}`), + expectedResult: DealTierBidderMap{}, }, { - description: "imp.ext - no deal tier", - impExt: json.RawMessage(`{"appnexus": {"placementId": 12345}}`), + description: "imp.ext.prebid - empty", + impExt: json.RawMessage(`{"prebid": {}}`), expectedResult: DealTierBidderMap{}, }, { - description: "imp.ext - error", - impExt: json.RawMessage(`{"appnexus": {"dealTier": "wrong type", "placementId": 12345}}`), - expectedError: "json: cannot unmarshal string into Go struct field .dealTier of type openrtb_ext.DealTier", + description: "imp.ext.prebid - no bidder but with other params", + impExt: json.RawMessage(`{"prebid": {"supportdeals": true}}`), + expectedResult: DealTierBidderMap{}, }, { - description: "imp.ext.prebid", + description: "imp.ext.prebid.bidder - one", impExt: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "anyPrefix"}, "placementId": 12345}}}}`), expectedResult: DealTierBidderMap{BidderAppnexus: {Prefix: "anyPrefix", MinDealTier: 5}}, }, { - description: "imp.ext.prebid- multiple", + description: "imp.ext.prebid.bidder - one with other params", + impExt: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "anyPrefix"}, "placementId": 12345}}, "supportdeals": true}, "tid": "1234"}`), + expectedResult: DealTierBidderMap{BidderAppnexus: {Prefix: "anyPrefix", MinDealTier: 5}}, + }, + { + description: "imp.ext.prebid.bidder - multiple", impExt: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "appnexusPrefix"}, "placementId": 12345}, "rubicon": {"dealTier": {"minDealTier": 8, "prefix": "rubiconPrefix"}, "placementId": 12345}}}}`), expectedResult: DealTierBidderMap{BidderAppnexus: {Prefix: "appnexusPrefix", MinDealTier: 5}, BidderRubicon: {Prefix: "rubiconPrefix", MinDealTier: 8}}, }, { - description: "imp.ext.prebid - no deal tier", + description: "imp.ext.prebid.bidder - one without deal tier", impExt: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"placementId": 12345}}}}`), expectedResult: DealTierBidderMap{}, }, { - description: "imp.ext.prebid - error", + description: "imp.ext.prebid.bidder - error", impExt: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": "wrong type", "placementId": 12345}}}}`), expectedError: "json: cannot unmarshal string into Go struct field .prebid.bidder.dealTier of type openrtb_ext.DealTier", }, - { - description: "imp.ext.prebid wins over imp.ext", - impExt: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "impExt"}, "placementId": 12345}, "prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 8, "prefix": "impExtPrebid"}, "placementId": 12345}}}}`), - expectedResult: DealTierBidderMap{BidderAppnexus: {Prefix: "impExtPrebid", MinDealTier: 8}}, - }, - { - description: "imp.ext.prebid coexists with imp.ext", - impExt: json.RawMessage(`{"appnexus": {"dealTier": {"minDealTier": 5, "prefix": "impExt"}, "placementId": 12345}, "prebid": {"bidder": {"rubicon": {"dealTier": {"minDealTier": 8, "prefix": "impExtPrebid"}, "placementId": 12345}}}}`), - expectedResult: DealTierBidderMap{BidderAppnexus: {Prefix: "impExt", MinDealTier: 5}, BidderRubicon: {Prefix: "impExtPrebid", MinDealTier: 8}}, - }, } for _, test := range testCases {