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

MetaX: Add BidVideo for video ads #4095

Merged
merged 2 commits into from
Dec 16, 2024
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
16 changes: 14 additions & 2 deletions adapters/metax/metax.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ func (a *adapter) MakeBids(bidReq *openrtb2.BidRequest, reqData *adapters.Reques
return nil, []error{err}
}
resp.Bids = append(resp.Bids, &adapters.TypedBid{
Bid: bid,
BidType: bidType,
Bid: bid,
BidType: bidType,
BidVideo: getBidVideo(bid),
})
}
}
Expand Down Expand Up @@ -177,6 +178,17 @@ func getBidType(bid *openrtb2.Bid) (openrtb_ext.BidType, error) {
}
}

func getBidVideo(bid *openrtb2.Bid) *openrtb_ext.ExtBidPrebidVideo {
bidVideo := openrtb_ext.ExtBidPrebidVideo{}
if len(bid.Cat) > 0 {
bidVideo.PrimaryCategory = bid.Cat[0]
}
if bid.Dur > 0 {
bidVideo.Duration = int(bid.Dur)
}
Comment on lines +183 to +188
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please update one of your exemplary JSON tests so that the bid response contains a cat and dur? While the unit tests are nice they aren't required while coverage through JSON tests are.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated one JSON test

return &bidVideo
}

// Builder builds a new instance of the MetaX adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
if config.Endpoint == "" {
Expand Down
42 changes: 42 additions & 0 deletions adapters/metax/metax_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,48 @@ func TestGetBidType(t *testing.T) {
}
}

func TestGetBidVideo(t *testing.T) {
tests := []struct {
description string
bid *openrtb2.Bid
bidvideo openrtb_ext.ExtBidPrebidVideo
}{
{
description: "One category, no duration",
bid: &openrtb2.Bid{Cat: []string{"IAB1-1"}},
bidvideo: openrtb_ext.ExtBidPrebidVideo{PrimaryCategory: "IAB1-1", Duration: 0},
},
{
description: "Two categories and use the first, no duration",
bid: &openrtb2.Bid{Cat: []string{"IAB1-1", "IAB1-2"}},
bidvideo: openrtb_ext.ExtBidPrebidVideo{PrimaryCategory: "IAB1-1", Duration: 0},
},
{
description: "No category, no duration",
bid: &openrtb2.Bid{Cat: []string{}},
bidvideo: openrtb_ext.ExtBidPrebidVideo{PrimaryCategory: "", Duration: 0},
},
{
description: "No category(nil), no duration",
bid: &openrtb2.Bid{Cat: nil},
bidvideo: openrtb_ext.ExtBidPrebidVideo{PrimaryCategory: "", Duration: 0},
},
{
description: "Two categories and use the first, duration is 15",
bid: &openrtb2.Bid{Cat: []string{"IAB1-1", "IAB1-2"}, Dur: 15},
bidvideo: openrtb_ext.ExtBidPrebidVideo{PrimaryCategory: "IAB1-1", Duration: 15},
},
}

for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
bidVideo := getBidVideo(test.bid)
assert.Equal(t, test.bidvideo.PrimaryCategory, bidVideo.PrimaryCategory)
assert.Equal(t, test.bidvideo.Duration, bidVideo.Duration)
})
}
}

func TestBuilder(t *testing.T) {
serverCfg := config.Server{}

Expand Down
20 changes: 17 additions & 3 deletions adapters/metax/metaxtest/exemplary/simple-app-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@
"crid": "test-crid",
"w": 1024,
"h": 576,
"mtype": 2
"mtype": 2,
"dur": 15,
"cat": [
"IAB1-5",
"IAB1-6"
]
}
]
}
Expand All @@ -120,9 +125,18 @@
"crid": "test-crid",
"w": 1024,
"h": 576,
"mtype": 2
"mtype": 2,
"dur": 15,
"cat": [
"IAB1-5",
"IAB1-6"
]
},
"type": "video"
"type": "video",
"video": {
"duration": 15,
"primary_category": "IAB1-5"
}
}
]
}
Expand Down
Loading