Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I1503: Added dealTierSatisfied parameters in exchange.pbsOrtbBid and openrtb_ext.ExtBidPrebid and dealPriority in openrtb_ext.ExtBidPrebid #1558

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion endpoints/openrtb2/video_auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ func (m *mockExchangeVideo) HoldAuction(ctx context.Context, bidRequest *openrtb
if debugLog != nil && debugLog.Enabled {
m.cache.called = true
}
ext := []byte(`{"prebid":{"targeting":{"hb_bidder_appnexus":"appnexus","hb_pb_appnexus":"20.00","hb_pb_cat_dur_appnex":"20.00_395_30s","hb_size":"1x1", "hb_uuid_appnexus":"837ea3b7-5598-4958-8c45-8e9ef2bf7cc1"},"type":"video"},"bidder":{"appnexus":{"brand_id":1,"auction_id":7840037870526938650,"bidder_id":2,"bid_ad_type":1,"creative_info":{"video":{"duration":30,"mimes":["video\/mp4"]}}}}}`)
ext := []byte(`{"prebid":{"targeting":{"hb_bidder_appnexus":"appnexus","hb_pb_appnexus":"20.00","hb_pb_cat_dur_appnex":"20.00_395_30s","hb_size":"1x1", "hb_uuid_appnexus":"837ea3b7-5598-4958-8c45-8e9ef2bf7cc1"},"type":"video","dealpriority":0,"dealtiersatisfied":false},"bidder":{"appnexus":{"brand_id":1,"auction_id":7840037870526938650,"bidder_id":2,"bid_ad_type":1,"creative_info":{"video":{"duration":30,"mimes":["video\/mp4"]}}}}}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This modification is not needed because, when ommited, both missing JSON int and boolean fields default to 0 and false respectively. Anyway, not a big deal if included.

return &openrtb.BidResponse{
SeatBid: []openrtb.SeatBid{{
Seat: "appnexus",
Expand Down
12 changes: 7 additions & 5 deletions exchange/bidder.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ type adaptedBidder interface {
// pbsOrtbBid.bidTargets does not need to be filled out by the Bidder. It will be set later by the exchange.
// pbsOrtbBid.bidVideo is optional but should be filled out by the Bidder if bidType is video.
// pbsOrtbBid.dealPriority is optionally provided by adapters and used internally by the exchange to support deal targeted campaigns.
// pbsOrtbBid.dealTierSatisfied is set to true by exchange.updateHbPbCatDur if deal tier satisfied otherwise it will be set to false
type pbsOrtbBid struct {
bid *openrtb.Bid
bidType openrtb_ext.BidType
bidTargets map[string]string
bidVideo *openrtb_ext.ExtBidPrebidVideo
dealPriority int
bid *openrtb.Bid
bidType openrtb_ext.BidType
bidTargets map[string]string
bidVideo *openrtb_ext.ExtBidPrebidVideo
dealPriority int
dealTierSatisfied bool
}

// pbsOrtbSeatBid is a SeatBid returned by an adaptedBidder.
Expand Down
9 changes: 6 additions & 3 deletions exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ func validateDealTier(dealTier openrtb_ext.DealTier) bool {
func updateHbPbCatDur(bid *pbsOrtbBid, dealTier openrtb_ext.DealTier, bidCategory map[string]string) {
if bid.dealPriority >= dealTier.MinDealTier {
prefixTier := fmt.Sprintf("%s%d_", dealTier.Prefix, bid.dealPriority)
bid.dealTierSatisfied = true

if oldCatDur, ok := bidCategory[bid.bid.ID]; ok {
oldCatDurSplit := strings.SplitAfterN(oldCatDur, "_", 2)
Expand Down Expand Up @@ -773,9 +774,11 @@ func (e *exchange) makeBid(Bids []*pbsOrtbBid, auc *auction, returnCreative bool
bidExt := &openrtb_ext.ExtBid{
Bidder: thisBid.bid.Ext,
Prebid: &openrtb_ext.ExtBidPrebid{
Targeting: thisBid.bidTargets,
Type: thisBid.bidType,
Video: thisBid.bidVideo,
Targeting: thisBid.bidTargets,
Type: thisBid.bidType,
Video: thisBid.bidVideo,
DealPriority: thisBid.dealPriority,
DealTierSatisfied: thisBid.dealTierSatisfied,
},
}
if cacheInfo, found := e.getBidCacheInfo(thisBid, auc); found {
Expand Down
132 changes: 74 additions & 58 deletions exchange/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,11 @@ func TestBidReturnsCreative(t *testing.T) {

assert.Equal(t, 0, len(resultingErrs), "%s. Test should not return errors \n", test.description)
assert.Equal(t, test.expectedCreativeMarkup, resultingBids[0].AdM, "%s. Ad markup string doesn't match expected \n", test.description)

var bidExt openrtb_ext.ExtBid
json.Unmarshal(resultingBids[0].Ext, &bidExt)
assert.Equal(t, 0, bidExt.Prebid.DealPriority, "%s. Test should have DealPriority set to 0", test.description)
assert.Equal(t, false, bidExt.Prebid.DealTierSatisfied, "%s. Test should have DealTierSatisfied set to false", test.description)
}
}

Expand Down Expand Up @@ -1514,10 +1519,10 @@ func TestCategoryMapping(t *testing.T) {
bid3 := openrtb.Bid{ID: "bid_id3", ImpID: "imp_id3", Price: 30.0000, Cat: cats3, W: 1, H: 1}
bid4 := openrtb.Bid{ID: "bid_id4", ImpID: "imp_id4", Price: 40.0000, Cat: cats4, W: 1, H: 1}

bid1_1 := pbsOrtbBid{&bid1, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_2 := pbsOrtbBid{&bid2, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 40}, 0}
bid1_3 := pbsOrtbBid{&bid3, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30, PrimaryCategory: "AdapterOverride"}, 0}
bid1_4 := pbsOrtbBid{&bid4, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_1 := pbsOrtbBid{&bid1, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}
bid1_2 := pbsOrtbBid{&bid2, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 40}, 0, false}
bid1_3 := pbsOrtbBid{&bid3, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30, PrimaryCategory: "AdapterOverride"}, 0, false}
bid1_4 := pbsOrtbBid{&bid4, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}

innerBids := []*pbsOrtbBid{
&bid1_1,
Expand Down Expand Up @@ -1569,10 +1574,10 @@ func TestCategoryMappingNoIncludeBrandCategory(t *testing.T) {
bid3 := openrtb.Bid{ID: "bid_id3", ImpID: "imp_id3", Price: 30.0000, Cat: cats3, W: 1, H: 1}
bid4 := openrtb.Bid{ID: "bid_id4", ImpID: "imp_id4", Price: 40.0000, Cat: cats4, W: 1, H: 1}

bid1_1 := pbsOrtbBid{&bid1, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_2 := pbsOrtbBid{&bid2, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 40}, 0}
bid1_3 := pbsOrtbBid{&bid3, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30, PrimaryCategory: "AdapterOverride"}, 0}
bid1_4 := pbsOrtbBid{&bid4, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 50}, 0}
bid1_1 := pbsOrtbBid{&bid1, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}
bid1_2 := pbsOrtbBid{&bid2, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 40}, 0, false}
bid1_3 := pbsOrtbBid{&bid3, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30, PrimaryCategory: "AdapterOverride"}, 0, false}
bid1_4 := pbsOrtbBid{&bid4, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 50}, 0, false}

innerBids := []*pbsOrtbBid{
&bid1_1,
Expand Down Expand Up @@ -1623,9 +1628,9 @@ func TestCategoryMappingTranslateCategoriesNil(t *testing.T) {
bid2 := openrtb.Bid{ID: "bid_id2", ImpID: "imp_id2", Price: 20.0000, Cat: cats2, W: 1, H: 1}
bid3 := openrtb.Bid{ID: "bid_id3", ImpID: "imp_id3", Price: 30.0000, Cat: cats3, W: 1, H: 1}

bid1_1 := pbsOrtbBid{&bid1, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_2 := pbsOrtbBid{&bid2, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 40}, 0}
bid1_3 := pbsOrtbBid{&bid3, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_1 := pbsOrtbBid{&bid1, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}
bid1_2 := pbsOrtbBid{&bid2, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 40}, 0, false}
bid1_3 := pbsOrtbBid{&bid3, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}

innerBids := []*pbsOrtbBid{
&bid1_1,
Expand Down Expand Up @@ -1705,9 +1710,9 @@ func TestCategoryMappingTranslateCategoriesFalse(t *testing.T) {
bid2 := openrtb.Bid{ID: "bid_id2", ImpID: "imp_id2", Price: 20.0000, Cat: cats2, W: 1, H: 1}
bid3 := openrtb.Bid{ID: "bid_id3", ImpID: "imp_id3", Price: 30.0000, Cat: cats3, W: 1, H: 1}

bid1_1 := pbsOrtbBid{&bid1, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_2 := pbsOrtbBid{&bid2, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 40}, 0}
bid1_3 := pbsOrtbBid{&bid3, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_1 := pbsOrtbBid{&bid1, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}
bid1_2 := pbsOrtbBid{&bid2, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 40}, 0, false}
bid1_3 := pbsOrtbBid{&bid3, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}

innerBids := []*pbsOrtbBid{
&bid1_1,
Expand Down Expand Up @@ -1757,11 +1762,11 @@ func TestCategoryDedupe(t *testing.T) {
bid4 := openrtb.Bid{ID: "bid_id4", ImpID: "imp_id4", Price: 20.0000, Cat: cats4, W: 1, H: 1}
bid5 := openrtb.Bid{ID: "bid_id5", ImpID: "imp_id5", Price: 20.0000, Cat: cats1, W: 1, H: 1}

bid1_1 := pbsOrtbBid{&bid1, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_2 := pbsOrtbBid{&bid2, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 50}, 0}
bid1_3 := pbsOrtbBid{&bid3, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_4 := pbsOrtbBid{&bid4, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_5 := pbsOrtbBid{&bid5, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_1 := pbsOrtbBid{&bid1, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}
bid1_2 := pbsOrtbBid{&bid2, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 50}, 0, false}
bid1_3 := pbsOrtbBid{&bid3, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}
bid1_4 := pbsOrtbBid{&bid4, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}
bid1_5 := pbsOrtbBid{&bid5, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}

selectedBids := make(map[string]int)
expectedCategories := map[string]string{
Expand Down Expand Up @@ -1836,11 +1841,11 @@ func TestNoCategoryDedupe(t *testing.T) {
bid4 := openrtb.Bid{ID: "bid_id4", ImpID: "imp_id4", Price: 20.0000, Cat: cats4, W: 1, H: 1}
bid5 := openrtb.Bid{ID: "bid_id5", ImpID: "imp_id5", Price: 10.0000, Cat: cats1, W: 1, H: 1}

bid1_1 := pbsOrtbBid{&bid1, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_2 := pbsOrtbBid{&bid2, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_3 := pbsOrtbBid{&bid3, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_4 := pbsOrtbBid{&bid4, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_5 := pbsOrtbBid{&bid5, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_1 := pbsOrtbBid{&bid1, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}
bid1_2 := pbsOrtbBid{&bid2, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}
bid1_3 := pbsOrtbBid{&bid3, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}
bid1_4 := pbsOrtbBid{&bid4, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}
bid1_5 := pbsOrtbBid{&bid5, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}

selectedBids := make(map[string]int)
expectedCategories := map[string]string{
Expand Down Expand Up @@ -1916,8 +1921,8 @@ func TestCategoryMappingBidderName(t *testing.T) {
bid1 := openrtb.Bid{ID: "bid_id1", ImpID: "imp_id1", Price: 10.0000, Cat: cats1, W: 1, H: 1}
bid2 := openrtb.Bid{ID: "bid_id2", ImpID: "imp_id2", Price: 10.0000, Cat: cats2, W: 1, H: 1}

bid1_1 := pbsOrtbBid{&bid1, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_2 := pbsOrtbBid{&bid2, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_1 := pbsOrtbBid{&bid1, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}
bid1_2 := pbsOrtbBid{&bid2, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}

innerBids1 := []*pbsOrtbBid{
&bid1_1,
Expand Down Expand Up @@ -1970,8 +1975,8 @@ func TestCategoryMappingBidderNameNoCategories(t *testing.T) {
bid1 := openrtb.Bid{ID: "bid_id1", ImpID: "imp_id1", Price: 10.0000, Cat: cats1, W: 1, H: 1}
bid2 := openrtb.Bid{ID: "bid_id2", ImpID: "imp_id2", Price: 12.0000, Cat: cats2, W: 1, H: 1}

bid1_1 := pbsOrtbBid{&bid1, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_2 := pbsOrtbBid{&bid2, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_1 := pbsOrtbBid{&bid1, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}
bid1_2 := pbsOrtbBid{&bid2, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}

innerBids1 := []*pbsOrtbBid{
&bid1_1,
Expand Down Expand Up @@ -2082,7 +2087,7 @@ func TestBidRejectionErrors(t *testing.T) {
innerBids := []*pbsOrtbBid{}
for _, bid := range test.bids {
currentBid := pbsOrtbBid{
bid, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: test.duration}, 0,
bid, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: test.duration}, 0, false,
}
innerBids = append(innerBids, &currentBid)
}
Expand Down Expand Up @@ -2131,8 +2136,8 @@ func TestCategoryMappingTwoBiddersOneBidEachNoCategorySamePrice(t *testing.T) {
bidApn1 := openrtb.Bid{ID: "bid_idApn1", ImpID: "imp_idApn1", Price: 10.0000, Cat: cats1, W: 1, H: 1}
bidApn2 := openrtb.Bid{ID: "bid_idApn2", ImpID: "imp_idApn2", Price: 10.0000, Cat: cats2, W: 1, H: 1}

bid1_Apn1 := pbsOrtbBid{&bidApn1, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_Apn2 := pbsOrtbBid{&bidApn2, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0}
bid1_Apn1 := pbsOrtbBid{&bidApn1, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}
bid1_Apn2 := pbsOrtbBid{&bidApn2, "video", nil, &openrtb_ext.ExtBidPrebidVideo{Duration: 30}, 0, false}

innerBidsApn1 := []*pbsOrtbBid{
&bid1_Apn1,
Expand Down Expand Up @@ -2193,12 +2198,13 @@ func TestUpdateRejections(t *testing.T) {

func TestApplyDealSupport(t *testing.T) {
testCases := []struct {
description string
dealPriority int
impExt json.RawMessage
targ map[string]string
expectedHbPbCatDur string
expectedDealErr string
description string
dealPriority int
impExt json.RawMessage
targ map[string]string
expectedHbPbCatDur string
expectedDealErr string
expectedDealTierSatisfied bool
}{
{
description: "hb_pb_cat_dur should be modified",
Expand All @@ -2207,8 +2213,9 @@ func TestApplyDealSupport(t *testing.T) {
targ: map[string]string{
"hb_pb_cat_dur": "12.00_movies_30s",
},
expectedHbPbCatDur: "tier5_movies_30s",
expectedDealErr: "",
expectedHbPbCatDur: "tier5_movies_30s",
expectedDealErr: "",
expectedDealTierSatisfied: true,
},
{
description: "hb_pb_cat_dur should not be modified due to priority not exceeding min",
Expand All @@ -2217,8 +2224,9 @@ func TestApplyDealSupport(t *testing.T) {
targ: map[string]string{
"hb_pb_cat_dur": "12.00_medicine_30s",
},
expectedHbPbCatDur: "12.00_medicine_30s",
expectedDealErr: "",
expectedHbPbCatDur: "12.00_medicine_30s",
expectedDealErr: "",
expectedDealTierSatisfied: false,
},
{
description: "hb_pb_cat_dur should not be modified due to invalid config",
Expand All @@ -2227,8 +2235,9 @@ func TestApplyDealSupport(t *testing.T) {
targ: map[string]string{
"hb_pb_cat_dur": "12.00_games_30s",
},
expectedHbPbCatDur: "12.00_games_30s",
expectedDealErr: "dealTier configuration invalid for bidder 'appnexus', imp ID 'imp_id1'",
expectedHbPbCatDur: "12.00_games_30s",
expectedDealErr: "dealTier configuration invalid for bidder 'appnexus', imp ID 'imp_id1'",
expectedDealTierSatisfied: false,
},
{
description: "hb_pb_cat_dur should not be modified due to deal priority of 0",
Expand All @@ -2237,8 +2246,9 @@ func TestApplyDealSupport(t *testing.T) {
targ: map[string]string{
"hb_pb_cat_dur": "12.00_auto_30s",
},
expectedHbPbCatDur: "12.00_auto_30s",
expectedDealErr: "",
expectedHbPbCatDur: "12.00_auto_30s",
expectedDealErr: "",
expectedDealTierSatisfied: false,
},
}

Expand All @@ -2254,7 +2264,7 @@ func TestApplyDealSupport(t *testing.T) {
},
}

bid := pbsOrtbBid{&openrtb.Bid{ID: "123456"}, "video", map[string]string{}, &openrtb_ext.ExtBidPrebidVideo{}, test.dealPriority}
bid := pbsOrtbBid{&openrtb.Bid{ID: "123456"}, "video", map[string]string{}, &openrtb_ext.ExtBidPrebidVideo{}, test.dealPriority, false}
bidCategory := map[string]string{
bid.bid.ID: test.targ["hb_pb_cat_dur"],
}
Expand All @@ -2270,6 +2280,7 @@ func TestApplyDealSupport(t *testing.T) {
dealErrs := applyDealSupport(bidRequest, auc, bidCategory)

assert.Equal(t, test.expectedHbPbCatDur, bidCategory[auc.winningBidsByBidder["imp_id1"][bidderName].bid.ID], test.description)
assert.Equal(t, test.expectedDealTierSatisfied, auc.winningBidsByBidder["imp_id1"][bidderName].dealTierSatisfied, "expectedDealTierSatisfied=%v when %v", test.expectedDealTierSatisfied, test.description)
if len(test.expectedDealErr) > 0 {
assert.Containsf(t, dealErrs, errors.New(test.expectedDealErr), "Expected error message not found in deal errors")
}
Expand Down Expand Up @@ -2368,11 +2379,12 @@ func TestValidateDealTier(t *testing.T) {

func TestUpdateHbPbCatDur(t *testing.T) {
testCases := []struct {
description string
targ map[string]string
dealTier openrtb_ext.DealTier
dealPriority int
expectedHbPbCatDur string
description string
targ map[string]string
dealTier openrtb_ext.DealTier
dealPriority int
expectedHbPbCatDur string
expectedDealTierSatisfied bool
}{
{
description: "hb_pb_cat_dur should be updated with prefix and tier",
Expand All @@ -2384,8 +2396,9 @@ func TestUpdateHbPbCatDur(t *testing.T) {
Prefix: "tier",
MinDealTier: 5,
},
dealPriority: 5,
expectedHbPbCatDur: "tier5_movies_30s",
dealPriority: 5,
expectedHbPbCatDur: "tier5_movies_30s",
expectedDealTierSatisfied: true,
},
{
description: "hb_pb_cat_dur should not be updated due to bid priority",
Expand All @@ -2397,8 +2410,9 @@ func TestUpdateHbPbCatDur(t *testing.T) {
Prefix: "tier",
MinDealTier: 10,
},
dealPriority: 6,
expectedHbPbCatDur: "12.00_auto_30s",
dealPriority: 6,
expectedHbPbCatDur: "12.00_auto_30s",
expectedDealTierSatisfied: false,
},
{
description: "hb_pb_cat_dur should be updated with prefix and tier",
Expand All @@ -2410,20 +2424,22 @@ func TestUpdateHbPbCatDur(t *testing.T) {
Prefix: "tier",
MinDealTier: 1,
},
dealPriority: 7,
expectedHbPbCatDur: "tier7_medicine_30s",
dealPriority: 7,
expectedHbPbCatDur: "tier7_medicine_30s",
expectedDealTierSatisfied: true,
},
}

for _, test := range testCases {
bid := pbsOrtbBid{&openrtb.Bid{ID: "123456"}, "video", map[string]string{}, &openrtb_ext.ExtBidPrebidVideo{}, test.dealPriority}
bid := pbsOrtbBid{&openrtb.Bid{ID: "123456"}, "video", map[string]string{}, &openrtb_ext.ExtBidPrebidVideo{}, test.dealPriority, false}
bidCategory := map[string]string{
bid.bid.ID: test.targ["hb_pb_cat_dur"],
}

updateHbPbCatDur(&bid, test.dealTier, bidCategory)

assert.Equal(t, test.expectedHbPbCatDur, bidCategory[bid.bid.ID], test.description)
assert.Equal(t, test.expectedDealTierSatisfied, bid.dealTierSatisfied, test.description)
}
}

Expand Down
12 changes: 8 additions & 4 deletions openrtb_ext/bid.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ type ExtBid struct {
}

// ExtBidPrebid defines the contract for bidresponse.seatbid.bid[i].ext.prebid
// DealPriority represents priority of deal bid. If its non deal bid then value will be 0
// DealTierSatisfied true represents corresponding bid has satisfied the deal tier
type ExtBidPrebid struct {
Cache *ExtBidPrebidCache `json:"cache,omitempty"`
Targeting map[string]string `json:"targeting,omitempty"`
Type BidType `json:"type"`
Video *ExtBidPrebidVideo `json:"video,omitempty"`
Cache *ExtBidPrebidCache `json:"cache,omitempty"`
Targeting map[string]string `json:"targeting,omitempty"`
Type BidType `json:"type"`
Video *ExtBidPrebidVideo `json:"video,omitempty"`
DealPriority int `json:"dealpriority,omitempty"`
DealTierSatisfied bool `json:"dealtiersatisfied,omitempty"`
}

// ExtBidPrebidCache defines the contract for bidresponse.seatbid.bid[i].ext.prebid.cache
Expand Down