github.com/prebid/prebid-server@v0.275.0/adapters/smaato/smaato_test.go (about) 1 package smaato 2 3 import ( 4 "encoding/json" 5 "testing" 6 "time" 7 8 "github.com/prebid/openrtb/v19/adcom1" 9 "github.com/prebid/openrtb/v19/openrtb2" 10 "github.com/stretchr/testify/assert" 11 12 "github.com/prebid/prebid-server/adapters" 13 "github.com/prebid/prebid-server/adapters/adapterstest" 14 "github.com/prebid/prebid-server/config" 15 "github.com/prebid/prebid-server/openrtb_ext" 16 ) 17 18 func TestJsonSamples(t *testing.T) { 19 bidder, buildErr := Builder(openrtb_ext.BidderSmaato, config.Adapter{ 20 Endpoint: "https://prebid/bidder"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 21 22 if buildErr != nil { 23 t.Fatalf("Builder returned unexpected error %v", buildErr) 24 } 25 26 adapter, _ := bidder.(*adapter) 27 assert.NotNil(t, adapter.clock) 28 adapter.clock = &mockTime{time: time.Date(2021, 6, 25, 10, 00, 0, 0, time.UTC)} 29 30 adapterstest.RunJSONBidderTest(t, "smaatotest", bidder) 31 } 32 33 func TestVideoWithCategoryAndDuration(t *testing.T) { 34 bidder := &adapter{} 35 36 mockedReq := &openrtb2.BidRequest{ 37 Imp: []openrtb2.Imp{{ 38 ID: "1_1", 39 Video: &openrtb2.Video{ 40 W: 640, 41 H: 360, 42 MIMEs: []string{"video/mp4"}, 43 MaxDuration: 60, 44 Protocols: []adcom1.MediaCreativeSubtype{2, 3, 5, 6}, 45 }, 46 Ext: json.RawMessage( 47 `{ 48 "bidder": { 49 "publisherId": "12345" 50 "adbreakId": "4123456" 51 } 52 }`, 53 )}, 54 }, 55 } 56 mockedExtReq := &adapters.RequestData{} 57 mockedBidResponse := &openrtb2.BidResponse{ 58 ID: "some-id", 59 SeatBid: []openrtb2.SeatBid{{ 60 Seat: "some-seat", 61 Bid: []openrtb2.Bid{{ 62 ID: "6906aae8-7f74-4edd-9a4f-f49379a3cadd", 63 ImpID: "1_1", 64 Price: 0.01, 65 AdM: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><VAST version=\"2.0\"></VAST>", 66 Cat: []string{"IAB1"}, 67 Ext: json.RawMessage( 68 `{ 69 "duration": 5 70 }`, 71 ), 72 }}, 73 }}, 74 } 75 body, _ := json.Marshal(mockedBidResponse) 76 mockedRes := &adapters.ResponseData{ 77 StatusCode: 200, 78 Body: body, 79 } 80 81 expectedBidCount := 1 82 expectedBidType := openrtb_ext.BidTypeVideo 83 expectedBidDuration := 5 84 expectedBidCategory := "IAB1" 85 expectedErrorCount := 0 86 87 bidResponse, errors := bidder.MakeBids(mockedReq, mockedExtReq, mockedRes) 88 89 if len(bidResponse.Bids) != expectedBidCount { 90 t.Errorf("should have 1 bid, bids=%v", bidResponse.Bids) 91 } 92 if bidResponse.Bids[0].BidType != expectedBidType { 93 t.Errorf("bid type should be video, bidType=%s", bidResponse.Bids[0].BidType) 94 } 95 if bidResponse.Bids[0].BidVideo.Duration != expectedBidDuration { 96 t.Errorf("video duration should be set") 97 } 98 if bidResponse.Bids[0].BidVideo.PrimaryCategory != expectedBidCategory { 99 t.Errorf("bid category should be set") 100 } 101 if bidResponse.Bids[0].Bid.Cat[0] != expectedBidCategory { 102 t.Errorf("bid category should be set") 103 } 104 if len(errors) != expectedErrorCount { 105 t.Errorf("should not have any errors, errors=%v", errors) 106 } 107 } 108 109 type mockTime struct { 110 time time.Time 111 } 112 113 func (mt *mockTime) Now() time.Time { 114 return mt.time 115 }