github.com/prebid/prebid-server/v2@v2.18.0/adapters/silverpush/silverpush_test.go (about)

     1  package silverpush
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/prebid/openrtb/v20/openrtb2"
     8  	"github.com/prebid/prebid-server/v2/adapters"
     9  	"github.com/prebid/prebid-server/v2/adapters/adapterstest"
    10  	"github.com/prebid/prebid-server/v2/config"
    11  	"github.com/prebid/prebid-server/v2/openrtb_ext"
    12  	"github.com/stretchr/testify/assert"
    13  )
    14  
    15  func TestJsonSamples(t *testing.T) {
    16  	bidder, buildErr := Builder(openrtb_ext.BidderSilverPush, config.Adapter{
    17  		Endpoint: "http://localhost:8080/bidder/?identifier=5krH8Q"}, config.Server{})
    18  	if buildErr != nil {
    19  		t.Fatalf("Builder returned unexpected error %v", buildErr)
    20  	}
    21  	adapterstest.RunJSONBidderTest(t, "silverpushtest", bidder)
    22  }
    23  
    24  func TestResponseWithCurrencies(t *testing.T) {
    25  	assertCurrencyInBidResponse(t, "USD", nil)
    26  
    27  	currency := "USD"
    28  	assertCurrencyInBidResponse(t, "USD", &currency)
    29  	currency = "EUR"
    30  	assertCurrencyInBidResponse(t, "EUR", &currency)
    31  }
    32  
    33  func assertCurrencyInBidResponse(t *testing.T, expectedCurrency string, currency *string) {
    34  	bidder, buildErr := Builder(openrtb_ext.BidderOpenx, config.Adapter{
    35  		Endpoint: "http://rtb.openx.net/prebid"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})
    36  
    37  	if buildErr != nil {
    38  		t.Fatalf("Builder returned unexpected error %v", buildErr)
    39  	}
    40  
    41  	prebidRequest := &openrtb2.BidRequest{
    42  		Imp: []openrtb2.Imp{},
    43  	}
    44  	mockedBidResponse := &openrtb2.BidResponse{}
    45  	if currency != nil {
    46  		mockedBidResponse.Cur = *currency
    47  	}
    48  	body, _ := json.Marshal(mockedBidResponse)
    49  	responseData := &adapters.ResponseData{
    50  		StatusCode: 200,
    51  		Body:       body,
    52  	}
    53  	bidResponse, errs := bidder.MakeBids(prebidRequest, nil, responseData)
    54  
    55  	if errs != nil {
    56  		t.Fatalf("Failed to make bids %v", errs)
    57  	}
    58  	assert.Equal(t, expectedCurrency, bidResponse.Currency)
    59  }