Skip to content

Commit

Permalink
Fix: flakey deal tier test (#3322)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsardo authored Nov 27, 2023
1 parent fb5e849 commit 9cf8acc
Showing 1 changed file with 34 additions and 27 deletions.
61 changes: 34 additions & 27 deletions openrtb_ext/deal_tier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,93 +17,100 @@ func TestReadDealTiersFromImp(t *testing.T) {
expectedErrorType error
}{
{
description: "Nil",
description: "nil",
impExt: nil,
expectedResult: DealTierBidderMap{},
},
{
description: "None",
description: "none",
impExt: json.RawMessage(``),
expectedResult: DealTierBidderMap{},
},
{
description: "Empty Object",
description: "empty_object",
impExt: json.RawMessage(`{}`),
expectedResult: DealTierBidderMap{},
},
{
description: "imp.ext - no prebid but with other params",
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.prebid - nil",
description: "imp.ext.prebid_nil",
impExt: json.RawMessage(`{"prebid": null}`),
expectedResult: DealTierBidderMap{},
},
{
description: "imp.ext.prebid - empty",
description: "imp.ext.prebid_empty",
impExt: json.RawMessage(`{"prebid": {}}`),
expectedResult: DealTierBidderMap{},
},
{
description: "imp.ext.prebid - no bidder but with other params",
description: "imp.ext.prebid_no bidder but with other params",
impExt: json.RawMessage(`{"prebid": {"supportdeals": true}}`),
expectedResult: DealTierBidderMap{},
},
{
description: "imp.ext.prebid.bidder - one",
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.bidder - one but it's not found in the Adapter Bidder list",
description: "imp.ext.prebid.bidder_one_but_not_found_in_the_adapter_bidder_list",
impExt: json.RawMessage(`{"prebid": {"bidder": {"unknown": {"dealTier": {"minDealTier": 5, "prefix": "anyPrefix"}, "placementId": 12345}}}}`),
expectedResult: DealTierBidderMap{},
},
{
description: "imp.ext.prebid.bidder - one but case is different from the Adapter Bidder list",
description: "imp.ext.prebid.bidder_one_but_case_is_different_from_the_adapter_bidder_list",
impExt: json.RawMessage(`{"prebid": {"bidder": {"APpNExUS": {"dealTier": {"minDealTier": 5, "prefix": "anyPrefix"}, "placementId": 12345}}}}`),
expectedResult: DealTierBidderMap{BidderAppnexus: {Prefix: "anyPrefix", MinDealTier: 5}},
},
{
description: "imp.ext.prebid.bidder - one with other params",
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",
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.bidder - same bidder listed twice but with different case the last one prevails",
impExt: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": {"minDealTier": 100, "prefix": "appnexusPrefix"}, "placementId": 12345},"APpNExUS": {"dealTier": {"minDealTier": 5, "prefix": "APpNExUSPrefix"}, "placementId": 12345}}}}`),
expectedResult: DealTierBidderMap{BidderAppnexus: {Prefix: "APpNExUSPrefix", MinDealTier: 5}},
},
{
description: "imp.ext.prebid.bidder - one without 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.bidder - error",
description: "imp.ext.prebid.bidder_error",
impExt: json.RawMessage(`{"prebid": {"bidder": {"appnexus": {"dealTier": "wrong type", "placementId": 12345}}}}`),
expectedErrorType: &errortypes.FailedToUnmarshal{},
},
}

for _, test := range testCases {
imp := openrtb2.Imp{Ext: test.impExt}
t.Run(test.description, func(t *testing.T) {

result, err := ReadDealTiersFromImp(imp)
imp := openrtb2.Imp{Ext: test.impExt}
result, err := ReadDealTiersFromImp(imp)

assert.Equal(t, test.expectedResult, result, test.description+":result")
assert.Equal(t, test.expectedResult, result)

if test.expectedErrorType != nil {
assert.IsType(t, test.expectedErrorType, err)
} else {
assert.NoError(t, err, test.description+":error")
}
if test.expectedErrorType != nil {
assert.IsType(t, test.expectedErrorType, err)
} else {
assert.NoError(t, err)
}
})
}

t.Run("imp.ext.prebid.bidder_dedupe", func(t *testing.T) {
impExt := json.RawMessage(`{"prebid": {"bidder": {"APPNEXUS": {"dealTier": {"minDealTier": 100}},"APpNExUS": {"dealTier": {"minDealTier": 5}}}}}`)
imp := openrtb2.Imp{Ext: impExt}
result, err := ReadDealTiersFromImp(imp)

assert.Len(t, result, 1)
assert.NotNil(t, result["appnexus"])
assert.NoError(t, err)
})
}

0 comments on commit 9cf8acc

Please sign in to comment.