github.com/prebid/prebid-server/v2@v2.18.0/adapters/bidstack/bidstack_test.go (about)

     1  package bidstack
     2  
     3  import (
     4  	"net/http"
     5  	"testing"
     6  
     7  	"github.com/prebid/openrtb/v20/openrtb2"
     8  	"github.com/stretchr/testify/assert"
     9  
    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  )
    14  
    15  func TestJsonSamples(t *testing.T) {
    16  	bidder, buildErr := Builder(openrtb_ext.BidderBidstack, config.Adapter{Endpoint: "http://mock-adserver.url"}, config.Server{})
    17  
    18  	if buildErr != nil {
    19  		t.Fatalf("Builder returned unexpected error %v", buildErr)
    20  	}
    21  
    22  	adapterstest.RunJSONBidderTest(t, "bidstacktest", bidder)
    23  }
    24  
    25  func TestPrepareHeaders(t *testing.T) {
    26  	publisherID := "12345"
    27  	expected := http.Header{
    28  		"Content-Type":  {"application/json"},
    29  		"Authorization": {"Bearer " + publisherID},
    30  	}
    31  
    32  	actual, err := prepareHeaders(&openrtb2.BidRequest{Imp: []openrtb2.Imp{
    33  		{Ext: []byte(`{"bidder":{"publisherId":"` + publisherID + `"}}`)}},
    34  	})
    35  
    36  	assert.NoError(t, err)
    37  	assert.Equal(t, expected, actual)
    38  }
    39  
    40  func TestGetBidderExt(t *testing.T) {
    41  	publisherID := "12345"
    42  	expected := openrtb_ext.ImpExtBidstack{PublisherID: publisherID}
    43  
    44  	actual, err := getBidderExt(openrtb2.Imp{
    45  		Ext: []byte(`{"bidder":{"publisherId":"` + publisherID + `"}}`),
    46  	})
    47  
    48  	assert.NoError(t, err)
    49  	assert.Equal(t, expected, actual)
    50  }