github.com/prebid/prebid-server/v2@v2.18.0/adapters/flipp/flipp_test.go (about)

     1  package flipp
     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  const fakeUuid = "30470a14-2949-4110-abce-b62d57304ad5"
    16  
    17  type TestUUIDGenerator struct{}
    18  
    19  func (TestUUIDGenerator) Generate() (string, error) {
    20  	return fakeUuid, nil
    21  }
    22  
    23  func TestJsonSamples(t *testing.T) {
    24  	bidder, buildErr := Builder(openrtb_ext.BidderFlipp, config.Adapter{
    25  		Endpoint: "http://example.com/pserver"},
    26  		config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})
    27  
    28  	setFakeUUIDGenerator(bidder)
    29  
    30  	if buildErr != nil {
    31  		t.Fatalf("Builder returned unexpected error %v", buildErr)
    32  	}
    33  
    34  	adapterstest.RunJSONBidderTest(t, "flipptest", bidder)
    35  }
    36  
    37  func setFakeUUIDGenerator(bidder adapters.Bidder) {
    38  	bidderFlipp, _ := bidder.(*adapter)
    39  	bidderFlipp.uuidGenerator = TestUUIDGenerator{}
    40  }
    41  
    42  func TestParamsUserKeyPermitted(t *testing.T) {
    43  	t.Run("Coppa is in effect", func(t *testing.T) {
    44  		request := &openrtb2.BidRequest{
    45  			Regs: &openrtb2.Regs{
    46  				COPPA: 1,
    47  			},
    48  		}
    49  		result := paramsUserKeyPermitted(request)
    50  		assert.New(t)
    51  		assert.False(t, result, "param user key not permitted because coppa is in effect")
    52  	})
    53  	t.Run("The Global Privacy Control is set", func(t *testing.T) {
    54  		request := &openrtb2.BidRequest{
    55  			Regs: &openrtb2.Regs{
    56  				GDPR: openrtb2.Int8Ptr(1),
    57  			},
    58  		}
    59  		result := paramsUserKeyPermitted(request)
    60  		assert.New(t)
    61  		assert.False(t, result, "param user key not permitted because Global Privacy Control is set")
    62  	})
    63  	t.Run("The Prebid transmitEids activity is disallowed", func(t *testing.T) {
    64  		extData := struct {
    65  			TransmitEids bool `json:"transmitEids"`
    66  		}{
    67  			TransmitEids: false,
    68  		}
    69  		ext, err := json.Marshal(extData)
    70  		if err != nil {
    71  			t.Fatalf("failed to marshal ext data: %v", err)
    72  		}
    73  		request := &openrtb2.BidRequest{
    74  			Ext: ext,
    75  		}
    76  
    77  		result := paramsUserKeyPermitted(request)
    78  		assert.New(t)
    79  		assert.False(t, result, "param user key not permitted because Prebid transmitEids activity is disallowed")
    80  	})
    81  }