From fead7ecbda51f8856883e67ad08e487b3057027f Mon Sep 17 00:00:00 2001 From: metax-kehan <115962296+metax-kehan@users.noreply.github.com> Date: Mon, 16 Dec 2024 22:01:34 +0800 Subject: [PATCH] MetaX: Add BidVideo for video ads (#4095) Signed-off-by: Kehan Pan --- adapters/metax/metax.go | 16 ++++++- adapters/metax/metax_test.go | 42 +++++++++++++++++++ .../metaxtest/exemplary/simple-app-video.json | 20 +++++++-- 3 files changed, 73 insertions(+), 5 deletions(-) diff --git a/adapters/metax/metax.go b/adapters/metax/metax.go index bd1f6272bea..8b197043623 100644 --- a/adapters/metax/metax.go +++ b/adapters/metax/metax.go @@ -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), }) } } @@ -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) + } + 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 == "" { diff --git a/adapters/metax/metax_test.go b/adapters/metax/metax_test.go index cd1e39ad6c4..f4f9d7e4966 100644 --- a/adapters/metax/metax_test.go +++ b/adapters/metax/metax_test.go @@ -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{} diff --git a/adapters/metax/metaxtest/exemplary/simple-app-video.json b/adapters/metax/metaxtest/exemplary/simple-app-video.json index 4f4272ee3db..1761f626137 100644 --- a/adapters/metax/metaxtest/exemplary/simple-app-video.json +++ b/adapters/metax/metaxtest/exemplary/simple-app-video.json @@ -98,7 +98,12 @@ "crid": "test-crid", "w": 1024, "h": 576, - "mtype": 2 + "mtype": 2, + "dur": 15, + "cat": [ + "IAB1-5", + "IAB1-6" + ] } ] } @@ -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" + } } ] }