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