github.com/prebid/prebid-server/v2@v2.18.0/adapters/tappx/tappx_test.go (about)

     1  package tappx
     2  
     3  import (
     4  	"regexp"
     5  	"testing"
     6  
     7  	"github.com/prebid/prebid-server/v2/adapters/adapterstest"
     8  	"github.com/prebid/prebid-server/v2/config"
     9  	"github.com/prebid/prebid-server/v2/openrtb_ext"
    10  	"github.com/stretchr/testify/assert"
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestJsonSamples(t *testing.T) {
    15  	bidder, buildErr := Builder(openrtb_ext.BidderTappx, config.Adapter{
    16  		Endpoint: "http://{{.Host}}"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})
    17  
    18  	if buildErr != nil {
    19  		t.Fatalf("Builder returned unexpected error %v", buildErr)
    20  	}
    21  
    22  	adapterstest.RunJSONBidderTest(t, "tappxtest", bidder)
    23  }
    24  
    25  func TestEndpointTemplateMalformed(t *testing.T) {
    26  	_, buildErr := Builder(openrtb_ext.BidderTappx, config.Adapter{
    27  		Endpoint: "{{Malformed}}"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})
    28  
    29  	assert.Error(t, buildErr)
    30  }
    31  
    32  func TestTsValue(t *testing.T) {
    33  	bidder, buildErr := Builder(openrtb_ext.BidderTappx, config.Adapter{
    34  		Endpoint: "http://{{.Host}}"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})
    35  
    36  	if buildErr != nil {
    37  		t.Fatalf("Builder returned unexpected error %v", buildErr)
    38  	}
    39  
    40  	bidderTappx := bidder.(*TappxAdapter)
    41  
    42  	test := 0
    43  	var tappxExt openrtb_ext.ExtImpTappx
    44  	tappxExt.Endpoint = "DUMMYENDPOINT"
    45  	tappxExt.TappxKey = "dummy-tappx-key"
    46  
    47  	url, err := bidderTappx.buildEndpointURL(&tappxExt, test)
    48  	require.NoError(t, err, "buildEndpointURL")
    49  
    50  	match, err := regexp.MatchString(`http://ssp\.api\.tappx\.com/rtb/v2/DUMMYENDPOINT\?tappxkey=dummy-tappx-key&ts=[0-9]{13}&type_cnn=prebid&v=1\.5`, url)
    51  	if err != nil {
    52  		t.Errorf("Error while running regex validation: %s", err.Error())
    53  		return
    54  	}
    55  	assert.True(t, match)
    56  }