github.com/prebid/prebid-server/v2@v2.18.0/gdpr/gdpr_test.go (about)

     1  package gdpr
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/prebid/go-gdpr/consentconstants"
     8  	"github.com/prebid/go-gdpr/vendorlist"
     9  	"github.com/prebid/prebid-server/v2/config"
    10  	"github.com/prebid/prebid-server/v2/openrtb_ext"
    11  
    12  	"github.com/stretchr/testify/assert"
    13  )
    14  
    15  func TestNewPermissions(t *testing.T) {
    16  	tests := []struct {
    17  		description  string
    18  		gdprEnabled  bool
    19  		hostVendorID int
    20  		wantType     Permissions
    21  	}{
    22  		{
    23  			gdprEnabled:  false,
    24  			hostVendorID: 32,
    25  			wantType:     &AlwaysAllow{},
    26  		},
    27  		{
    28  			gdprEnabled:  true,
    29  			hostVendorID: 0,
    30  			wantType:     &AllowHostCookies{},
    31  		},
    32  		{
    33  			gdprEnabled:  true,
    34  			hostVendorID: 32,
    35  			wantType:     &permissionsImpl{},
    36  		},
    37  	}
    38  
    39  	for _, tt := range tests {
    40  
    41  		config := config.GDPR{
    42  			Enabled:      tt.gdprEnabled,
    43  			HostVendorID: tt.hostVendorID,
    44  		}
    45  		vendorIDs := map[openrtb_ext.BidderName]uint16{}
    46  		vendorListFetcher := func(ctx context.Context, specVersion, listVersion uint16) (vendorlist.VendorList, error) {
    47  			return nil, nil
    48  		}
    49  
    50  		fakePurposeEnforcerBuilder := fakePurposeEnforcerBuilder{
    51  			purposeEnforcer: nil,
    52  		}.Builder
    53  		perms := NewPermissions(config, &tcf2Config{}, vendorIDs, vendorListFetcher, fakePurposeEnforcerBuilder, RequestInfo{})
    54  
    55  		assert.IsType(t, tt.wantType, perms, tt.description)
    56  	}
    57  }
    58  
    59  type fakePurposeEnforcerBuilder struct {
    60  	purposeEnforcer PurposeEnforcer
    61  }
    62  
    63  func (fpeb fakePurposeEnforcerBuilder) Builder(consentconstants.Purpose, string) PurposeEnforcer {
    64  	return fpeb.purposeEnforcer
    65  }