@@ -91,6 +91,54 @@ class ConsentBlockerTests {
9191 assertNull(processedEvent)
9292 }
9393
94+ @Test
95+ fun `blocks when no consent and no unmapped destinations` () {
96+ val store = SynchronousStore ()
97+ store.provide(ConsentState .defaultState)
98+ var mappings: MutableMap <String , Array <String >> = HashMap ()
99+ mappings[" foo" ] = arrayOf(" cat1" , " cat2" )
100+ val state = ConsentState (mappings, false , mutableListOf<String >(),true )
101+ store.dispatch(UpdateConsentStateActionFull (state), ConsentState ::class )
102+ val blockingPlugin = ConsentBlocker (" foo" , store)
103+
104+ // Stamped Event with all categories false
105+ var stamppedEvent = TrackEvent (properties = emptyJsonObject, event = " MyEvent" )
106+ stamppedEvent.context = buildJsonObject {
107+ put(Constants .CONSENT_KEY , buildJsonObject {
108+ put(Constants .CATEGORY_PREFERENCE_KEY , buildJsonObject {
109+ put(" cat1" , JsonPrimitive (false ))
110+ put(" cat2" , JsonPrimitive (false ))
111+ })
112+ })
113+ }
114+ val processedEvent = blockingPlugin.execute(stamppedEvent)
115+ assertNull(processedEvent)
116+ }
117+
118+ @Test
119+ fun `does not block the Segment Consent Preference event` () {
120+ val store = SynchronousStore ()
121+ store.provide(ConsentState .defaultState)
122+ var mappings: MutableMap <String , Array <String >> = HashMap ()
123+ mappings[" foo" ] = arrayOf(" cat1" , " cat2" )
124+ val state = ConsentState (mappings, false , mutableListOf<String >(),true )
125+ store.dispatch(UpdateConsentStateActionFull (state), ConsentState ::class )
126+ val blockingPlugin = ConsentBlocker (" foo" , store)
127+
128+ // Stamped Event with all categories false
129+ var stamppedEvent = TrackEvent (properties = emptyJsonObject, event = Constants .EVENT_SEGMENT_CONSENT_PREFERENCE )
130+ stamppedEvent.context = buildJsonObject {
131+ put(Constants .CONSENT_KEY , buildJsonObject {
132+ put(Constants .CATEGORY_PREFERENCE_KEY , buildJsonObject {
133+ put(" cat1" , JsonPrimitive (false ))
134+ put(" cat2" , JsonPrimitive (false ))
135+ })
136+ })
137+ }
138+ val processedEvent = blockingPlugin.execute(stamppedEvent)
139+ assertNotNull(processedEvent)
140+ }
141+
94142 @Test
95143 fun `block when nothing in store` () {
96144 val store = SynchronousStore ()
0 commit comments