github.com/prebid/prebid-server/v2@v2.18.0/adapters/openx/openx_test.go (about)

     1  package openx
     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.BidderOpenx, config.Adapter{
    17  		Endpoint: "http://rtb.openx.net/prebid"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})
    18  
    19  	if buildErr != nil {
    20  		t.Fatalf("Builder returned unexpected error %v", buildErr)
    21  	}
    22  
    23  	adapterstest.RunJSONBidderTest(t, "openxtest", bidder)
    24  }
    25  
    26  func TestResponseWithCurrencies(t *testing.T) {
    27  	assertCurrencyInBidResponse(t, "USD", nil)
    28  
    29  	currency := "USD"
    30  	assertCurrencyInBidResponse(t, "USD", &currency)
    31  
    32  	currency = "EUR"
    33  	assertCurrencyInBidResponse(t, "EUR", &currency)
    34  }
    35  
    36  func assertCurrencyInBidResponse(t *testing.T, expectedCurrency string, currency *string) {
    37  	bidder, buildErr := Builder(openrtb_ext.BidderOpenx, config.Adapter{
    38  		Endpoint: "http://rtb.openx.net/prebid"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})
    39  
    40  	if buildErr != nil {
    41  		t.Fatalf("Builder returned unexpected error %v", buildErr)
    42  	}
    43  
    44  	prebidRequest := &openrtb2.BidRequest{
    45  		Imp: []openrtb2.Imp{},
    46  	}
    47  	mockedBidResponse := &openrtb2.BidResponse{}
    48  	if currency != nil {
    49  		mockedBidResponse.Cur = *currency
    50  	}
    51  	body, _ := json.Marshal(mockedBidResponse)
    52  	responseData := &adapters.ResponseData{
    53  		StatusCode: 200,
    54  		Body:       body,
    55  	}
    56  	bidResponse, errs := bidder.MakeBids(prebidRequest, nil, responseData)
    57  
    58  	if errs != nil {
    59  		t.Fatalf("Failed to make bids %v", errs)
    60  	}
    61  	assert.Equal(t, expectedCurrency, bidResponse.Currency)
    62  }