forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OTT-64: Deal Prioritisation - Auction Model based issues (#101)
OTT-64: Deal Prioritisation - Auction Model based issues (#101) Co-authored-by: Shriprasad <shriprasad.marathe@pubmatic.com>
- Loading branch information
1 parent
57e72aa
commit 85920d9
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package openrtb2 | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/PubMatic-OpenWrap/openrtb" | ||
"github.com/PubMatic-OpenWrap/prebid-server/openrtb_ext" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAddTargetingKeys(t *testing.T) { | ||
var tests = []struct { | ||
scenario string // Testcase scenario | ||
key string | ||
value string | ||
bidExt string | ||
expect map[string]string | ||
}{ | ||
{scenario: "key_not_exists", key: "hb_pb_cat_dur", value: "some_value", bidExt: `{"prebid":{"targeting":{}}}`, expect: map[string]string{"hb_pb_cat_dur": "some_value"}}, | ||
{scenario: "key_already_exists", key: "hb_pb_cat_dur", value: "new_value", bidExt: `{"prebid":{"targeting":{"hb_pb_cat_dur":"old_value"}}}`, expect: map[string]string{"hb_pb_cat_dur": "new_value"}}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.scenario, func(t *testing.T) { | ||
bid := new(openrtb.Bid) | ||
bid.Ext = []byte(test.bidExt) | ||
key := openrtb_ext.TargetingKey(test.key) | ||
assert.Nil(t, addTargetingKey(bid, key, test.value)) | ||
extBid := openrtb_ext.ExtBid{} | ||
json.Unmarshal(bid.Ext, &extBid) | ||
assert.Equal(t, test.expect, extBid.Prebid.Targeting) | ||
}) | ||
} | ||
assert.Equal(t, "Invalid bid", addTargetingKey(nil, openrtb_ext.HbCategoryDurationKey, "some value").Error()) | ||
} |