github.com/prebid/prebid-server/v2@v2.18.0/adapters/consumable/consumable_test.go (about) 1 package consumable 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/prebid/openrtb/v20/adcom1" 8 "github.com/prebid/openrtb/v20/openrtb2" 9 "github.com/prebid/prebid-server/v2/adapters" 10 "github.com/prebid/prebid-server/v2/adapters/adapterstest" 11 "github.com/prebid/prebid-server/v2/config" 12 "github.com/prebid/prebid-server/v2/openrtb_ext" 13 "github.com/prebid/prebid-server/v2/util/ptrutil" 14 ) 15 16 func TestJsonSamples(t *testing.T) { 17 bidder, buildErr := Builder(openrtb_ext.BidderConsumable, config.Adapter{ 18 Endpoint: "http://ib.adnxs.com/openrtb2"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 19 20 if buildErr != nil { 21 t.Fatalf("Builder returned unexpected error %v", buildErr) 22 } 23 24 adapterstest.RunJSONBidderTest(t, "consumable", bidder) 25 } 26 27 func TestConsumableMakeBidsWithCategoryDuration(t *testing.T) { 28 bidder := &adapter{} 29 30 mockedReq := &openrtb2.BidRequest{ 31 Imp: []openrtb2.Imp{{ 32 ID: "1_1", 33 Video: &openrtb2.Video{ 34 W: ptrutil.ToPtr[int64](640), 35 H: ptrutil.ToPtr[int64](360), 36 MIMEs: []string{"video/mp4"}, 37 MaxDuration: 60, 38 Protocols: []adcom1.MediaCreativeSubtype{2, 3, 5, 6}, 39 }, 40 Ext: json.RawMessage( 41 `{ 42 "prebid": {}, 43 "bidder": { 44 "placementId": "123456" 45 } 46 }`, 47 )}, 48 }, 49 } 50 mockedExtReq := &adapters.RequestData{} 51 mockedBidResponse := &openrtb2.BidResponse{ 52 ID: "test-1", 53 SeatBid: []openrtb2.SeatBid{{ 54 Seat: "Buyer", 55 Bid: []openrtb2.Bid{{ 56 ID: "1", 57 ImpID: "1_1", 58 Price: 1.23, 59 AdID: "123", 60 Cat: []string{"IAB18-1"}, 61 Dur: 30, 62 MType: openrtb2.MarkupVideo, 63 }}, 64 }}, 65 } 66 body, _ := json.Marshal(mockedBidResponse) 67 mockedRes := &adapters.ResponseData{ 68 StatusCode: 200, 69 Body: body, 70 } 71 72 expectedBidCount := 1 73 expectedBidType := openrtb_ext.BidTypeVideo 74 expectedBidDuration := 30 75 expectedBidCategory := "IAB18-1" 76 expectedErrorCount := 0 77 78 bidResponse, errors := bidder.MakeBids(mockedReq, mockedExtReq, mockedRes) 79 80 if len(bidResponse.Bids) != expectedBidCount { 81 t.Errorf("should have 1 bid, bids=%v", bidResponse.Bids) 82 } 83 if bidResponse.Bids[0].BidType != expectedBidType { 84 t.Errorf("bid type should be video, bidType=%s", bidResponse.Bids[0].BidType) 85 } 86 if bidResponse.Bids[0].BidVideo.Duration != expectedBidDuration { 87 t.Errorf("video duration should be set") 88 } 89 if bidResponse.Bids[0].Bid.Cat[0] != expectedBidCategory { 90 t.Errorf("bid category should be set") 91 } 92 if len(errors) != expectedErrorCount { 93 t.Errorf("should not have any errors, errors=%v", errors) 94 } 95 }