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

     1  package gdpr
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/prebid/prebid-server/v2/openrtb_ext"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestPurposeConfigBasicEnforcementVendor(t *testing.T) {
    12  	var (
    13  		appnexus = string(openrtb_ext.BidderAppnexus)
    14  		ix       = string(openrtb_ext.BidderIx)
    15  		pubmatic = string(openrtb_ext.BidderPubmatic)
    16  		rubicon  = string(openrtb_ext.BidderRubicon)
    17  	)
    18  
    19  	tests := []struct {
    20  		description      string
    21  		giveBasicVendors map[string]struct{}
    22  		giveBidder       string
    23  		wantFound        bool
    24  	}{
    25  		{
    26  			description:      "vendor map is nil",
    27  			giveBasicVendors: nil,
    28  			giveBidder:       appnexus,
    29  			wantFound:        false,
    30  		},
    31  		{
    32  			description:      "vendor map is empty",
    33  			giveBasicVendors: map[string]struct{}{},
    34  			giveBidder:       appnexus,
    35  			wantFound:        false,
    36  		},
    37  		{
    38  			description: "vendor map has one bidders - bidder not found",
    39  			giveBasicVendors: map[string]struct{}{
    40  				pubmatic: {},
    41  			},
    42  			giveBidder: appnexus,
    43  			wantFound:  false,
    44  		},
    45  		{
    46  			description: "vendor map has one bidders - bidder found",
    47  			giveBasicVendors: map[string]struct{}{
    48  				appnexus: {},
    49  			},
    50  			giveBidder: appnexus,
    51  			wantFound:  true,
    52  		},
    53  		{
    54  			description: "vendor map has many bidderss - bidder not found",
    55  			giveBasicVendors: map[string]struct{}{
    56  				ix:       {},
    57  				pubmatic: {},
    58  				rubicon:  {},
    59  			},
    60  			giveBidder: appnexus,
    61  			wantFound:  false,
    62  		},
    63  		{
    64  			description: "vendor map has many bidderss - bidder found",
    65  			giveBasicVendors: map[string]struct{}{
    66  				ix:       {},
    67  				pubmatic: {},
    68  				appnexus: {},
    69  				rubicon:  {},
    70  			},
    71  			giveBidder: appnexus,
    72  			wantFound:  true,
    73  		},
    74  	}
    75  
    76  	for _, tt := range tests {
    77  		cfg := purposeConfig{
    78  			BasicEnforcementVendorsMap: tt.giveBasicVendors,
    79  		}
    80  		found := cfg.basicEnforcementVendor(tt.giveBidder)
    81  
    82  		assert.Equal(t, tt.wantFound, found, tt.description)
    83  	}
    84  }
    85  
    86  func TestPurposeConfigVendorException(t *testing.T) {
    87  	var (
    88  		appnexus = string(openrtb_ext.BidderAppnexus)
    89  		ix       = string(openrtb_ext.BidderIx)
    90  		pubmatic = string(openrtb_ext.BidderPubmatic)
    91  		rubicon  = string(openrtb_ext.BidderRubicon)
    92  	)
    93  
    94  	tests := []struct {
    95  		description    string
    96  		giveExceptions map[string]struct{}
    97  		giveBidder     string
    98  		wantFound      bool
    99  	}{
   100  		{
   101  			description:    "vendor exception map is nil",
   102  			giveExceptions: nil,
   103  			giveBidder:     appnexus,
   104  			wantFound:      false,
   105  		},
   106  		{
   107  			description:    "vendor exception map is empty",
   108  			giveExceptions: map[string]struct{}{},
   109  			giveBidder:     appnexus,
   110  			wantFound:      false,
   111  		},
   112  		{
   113  			description: "vendor exception map has one bidders - bidder not found",
   114  			giveExceptions: map[string]struct{}{
   115  				pubmatic: {},
   116  			},
   117  			giveBidder: appnexus,
   118  			wantFound:  false,
   119  		},
   120  		{
   121  			description: "vendor exception map has one bidders - bidder found",
   122  			giveExceptions: map[string]struct{}{
   123  				appnexus: {},
   124  			},
   125  			giveBidder: appnexus,
   126  			wantFound:  true,
   127  		},
   128  		{
   129  			description: "vendor exception map has many bidderss - bidder not found",
   130  			giveExceptions: map[string]struct{}{
   131  				ix:       {},
   132  				pubmatic: {},
   133  				rubicon:  {},
   134  			},
   135  			giveBidder: appnexus,
   136  			wantFound:  false,
   137  		},
   138  		{
   139  			description: "vendor exception map has many bidderss - bidder found",
   140  			giveExceptions: map[string]struct{}{
   141  				ix:       {},
   142  				pubmatic: {},
   143  				appnexus: {},
   144  				rubicon:  {},
   145  			},
   146  			giveBidder: appnexus,
   147  			wantFound:  true,
   148  		},
   149  	}
   150  
   151  	for _, tt := range tests {
   152  		cfg := purposeConfig{
   153  			VendorExceptionMap: tt.giveExceptions,
   154  		}
   155  		found := cfg.vendorException(tt.giveBidder)
   156  
   157  		assert.Equal(t, tt.wantFound, found, tt.description)
   158  	}
   159  }