github.com/prebid/prebid-server/v2@v2.18.0/usersync/synctype_test.go (about) 1 package usersync 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestSyncTypeFilter(t *testing.T) { 10 bidder := "foo" 11 12 bidderFilterAllowed := NewUniformBidderFilter(BidderFilterModeInclude) 13 bidderFilterNotAllowed := NewUniformBidderFilter(BidderFilterModeExclude) 14 15 testCases := []struct { 16 description string 17 givenIFrameFilter BidderFilter 18 givenRedirectFilter BidderFilter 19 expectedSyncTypes []SyncType 20 }{ 21 { 22 description: "None", 23 givenIFrameFilter: bidderFilterNotAllowed, 24 givenRedirectFilter: bidderFilterNotAllowed, 25 expectedSyncTypes: []SyncType{}, 26 }, 27 { 28 description: "IFrame Only", 29 givenIFrameFilter: bidderFilterAllowed, 30 givenRedirectFilter: bidderFilterNotAllowed, 31 expectedSyncTypes: []SyncType{SyncTypeIFrame}, 32 }, 33 { 34 description: "Redirect Only", 35 givenIFrameFilter: bidderFilterNotAllowed, 36 givenRedirectFilter: bidderFilterAllowed, 37 expectedSyncTypes: []SyncType{SyncTypeRedirect}, 38 }, 39 { 40 description: "All", 41 givenIFrameFilter: bidderFilterAllowed, 42 givenRedirectFilter: bidderFilterAllowed, 43 expectedSyncTypes: []SyncType{SyncTypeIFrame, SyncTypeRedirect}, 44 }, 45 } 46 47 for _, test := range testCases { 48 syncTypeFilter := SyncTypeFilter{IFrame: test.givenIFrameFilter, Redirect: test.givenRedirectFilter} 49 syncTypes := syncTypeFilter.ForBidder(bidder) 50 assert.ElementsMatch(t, test.expectedSyncTypes, syncTypes, test.description) 51 } 52 }