Skip to content

Commit

Permalink
IX: Set bidVideo when category and duration is available (prebid#1794)
Browse files Browse the repository at this point in the history
  • Loading branch information
ixjohnny authored and Dan Barnett committed May 11, 2021
1 parent d79cc34 commit c6f2ec8
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
18 changes: 16 additions & 2 deletions adapters/ix/ix.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,23 @@ func (a *IxAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalReque
if !ok {
errs = append(errs, fmt.Errorf("Unmatched impression id: %s.", bid.ImpID))
}

var bidExtVideo *openrtb_ext.ExtBidPrebidVideo
var bidExt openrtb_ext.ExtBid
if bidType == openrtb_ext.BidTypeVideo {
unmarshalExtErr := json.Unmarshal(bid.Ext, &bidExt)
if unmarshalExtErr == nil && bidExt.Prebid != nil && bidExt.Prebid.Video != nil {
bidExtVideo = &openrtb_ext.ExtBidPrebidVideo{
Duration: bidExt.Prebid.Video.Duration,
PrimaryCategory: bidExt.Prebid.Video.PrimaryCategory,
}
}
}

bidderResponse.Bids = append(bidderResponse.Bids, &adapters.TypedBid{
Bid: &bid,
BidType: bidType,
Bid: &bid,
BidType: bidType,
BidVideo: bidExtVideo,
})
}
}
Expand Down
77 changes: 77 additions & 0 deletions adapters/ix/ix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,3 +722,80 @@ func TestIxMaxRequests(t *testing.T) {
t.Fatalf("Should have received %d bid", adapter.maxRequests)
}
}

func TestIxMakeBidsWithCategoryDuration(t *testing.T) {
bidder := &IxAdapter{}

mockedReq := &openrtb2.BidRequest{
Imp: []openrtb2.Imp{{
ID: "1_1",
Video: &openrtb2.Video{
W: 640,
H: 360,
MIMEs: []string{"video/mp4"},
MaxDuration: 60,
Protocols: []openrtb2.Protocol{2, 3, 5, 6},
},
Ext: json.RawMessage(
`{
"prebid": {},
"bidder": {
"siteID": 123456
}
}`,
)},
},
}
mockedExtReq := &adapters.RequestData{}
mockedBidResponse := &openrtb2.BidResponse{
ID: "test-1",
SeatBid: []openrtb2.SeatBid{{
Seat: "Buyer",
Bid: []openrtb2.Bid{{
ID: "1",
ImpID: "1_1",
Price: 1.23,
AdID: "123",
Ext: json.RawMessage(
`{
"prebid": {
"video": {
"duration": 60,
"primary_category": "IAB18-1"
}
}
}`,
),
}},
}},
}
body, _ := json.Marshal(mockedBidResponse)
mockedRes := &adapters.ResponseData{
StatusCode: 200,
Body: body,
}

expectedBidCount := 1
expectedBidType := openrtb_ext.BidTypeVideo
expectedBidDuration := 60
expectedBidCategory := "IAB18-1"
expectedErrorCount := 0

bidResponse, errors := bidder.MakeBids(mockedReq, mockedExtReq, mockedRes)

if len(bidResponse.Bids) != expectedBidCount {
t.Errorf("should have 1 bid, bids=%v", bidResponse.Bids)
}
if bidResponse.Bids[0].BidType != expectedBidType {
t.Errorf("bid type should be video, bidType=%s", bidResponse.Bids[0].BidType)
}
if bidResponse.Bids[0].BidVideo.Duration != expectedBidDuration {
t.Errorf("video duration should be set")
}
if bidResponse.Bids[0].BidVideo.PrimaryCategory != expectedBidCategory {
t.Errorf("video category should be set")
}
if len(errors) != expectedErrorCount {
t.Errorf("should not have any errors, errors=%v", errors)
}
}

0 comments on commit c6f2ec8

Please sign in to comment.