Skip to content

Commit

Permalink
Fix: deal tiers no longer ignored due to presence of tid
Browse files Browse the repository at this point in the history
  • Loading branch information
bsardo committed Jun 7, 2023
1 parent 6501d7d commit 919b74b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 54 deletions.
30 changes: 15 additions & 15 deletions exchange/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand All @@ -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",
},
Expand All @@ -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",
},
Expand All @@ -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",
},
Expand Down Expand Up @@ -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}}}}`),
},
},
},
Expand Down Expand Up @@ -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}}}}`),
},
},
},
Expand Down Expand Up @@ -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}}}}`),
},
},
},
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand Down
14 changes: 0 additions & 14 deletions openrtb_ext/deal_tier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
45 changes: 20 additions & 25 deletions openrtb_ext/deal_tier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 919b74b

Please sign in to comment.