-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: consent plugin updates and test cases (#894)
- Loading branch information
Showing
13 changed files
with
1,172 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/core/src/plugins/__tests__/consent/analytics-swift-consent
Submodule analytics-swift-consent
added at
8e2324
115 changes: 115 additions & 0 deletions
115
packages/core/src/plugins/__tests__/consent/consentNotEnabledAtSegment.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { createTestClient } from '../../../__tests__/__helpers__/setupSegmentClient'; | ||
import { ConsentPlugin } from '../../ConsentPlugin'; | ||
|
||
import { | ||
setupTestDestinations, | ||
createConsentProvider, | ||
createSegmentWatcher, | ||
} from './utils'; | ||
import consentNotEnabledAtSegment from './mockSettings/ConsentNotEnabledAtSegment.json'; | ||
|
||
describe('Consent not enabled at Segment', () => { | ||
const createClient = () => | ||
createTestClient( | ||
{ | ||
settings: consentNotEnabledAtSegment.integrations, | ||
}, | ||
{ autoAddSegmentDestination: true } | ||
); | ||
|
||
test('no to all', async () => { | ||
const { client } = createClient(); | ||
const testDestinations = setupTestDestinations(client); | ||
const mockConsentStatuses = { | ||
C0001: false, | ||
C0002: false, | ||
C0003: false, | ||
C0004: false, | ||
C0005: false, | ||
}; | ||
|
||
client.add({ | ||
plugin: new ConsentPlugin( | ||
createConsentProvider(mockConsentStatuses), | ||
Object.keys(mockConsentStatuses) | ||
), | ||
}); | ||
|
||
await client.init(); | ||
|
||
const segmentDestination = createSegmentWatcher(client); | ||
|
||
await client.track('test'); | ||
|
||
expect(segmentDestination).toHaveBeenCalled(); | ||
expect(testDestinations.dest1.track).toHaveBeenCalled(); | ||
expect(testDestinations.dest2.track).toHaveBeenCalled(); | ||
expect(testDestinations.dest3.track).toHaveBeenCalled(); | ||
expect(testDestinations.dest4.track).toHaveBeenCalled(); | ||
expect(testDestinations.dest5.track).toHaveBeenCalled(); | ||
}); | ||
|
||
test('yes to some', async () => { | ||
const { client } = createClient(); | ||
const testDestinations = setupTestDestinations(client); | ||
const mockConsentStatuses = { | ||
C0001: false, | ||
C0002: true, | ||
C0003: false, | ||
C0004: true, | ||
C0005: true, | ||
}; | ||
|
||
client.add({ | ||
plugin: new ConsentPlugin( | ||
createConsentProvider(mockConsentStatuses), | ||
Object.keys(mockConsentStatuses) | ||
), | ||
}); | ||
|
||
await client.init(); | ||
|
||
const segmentDestination = createSegmentWatcher(client); | ||
|
||
await client.track('test'); | ||
|
||
expect(segmentDestination).toHaveBeenCalled(); | ||
expect(testDestinations.dest1.track).toHaveBeenCalled(); | ||
expect(testDestinations.dest2.track).toHaveBeenCalled(); | ||
expect(testDestinations.dest3.track).toHaveBeenCalled(); | ||
expect(testDestinations.dest4.track).toHaveBeenCalled(); | ||
expect(testDestinations.dest5.track).toHaveBeenCalled(); | ||
}); | ||
|
||
test('yes to all', async () => { | ||
const { client } = createClient(); | ||
const testDestinations = setupTestDestinations(client); | ||
const mockConsentStatuses = { | ||
C0001: true, | ||
C0002: true, | ||
C0003: true, | ||
C0004: true, | ||
C0005: true, | ||
}; | ||
|
||
client.add({ | ||
plugin: new ConsentPlugin( | ||
createConsentProvider(mockConsentStatuses), | ||
Object.keys(mockConsentStatuses) | ||
), | ||
}); | ||
|
||
await client.init(); | ||
|
||
const segmentDestination = createSegmentWatcher(client); | ||
|
||
await client.track('test'); | ||
|
||
expect(segmentDestination).toHaveBeenCalled(); | ||
expect(testDestinations.dest1.track).toHaveBeenCalled(); | ||
expect(testDestinations.dest2.track).toHaveBeenCalled(); | ||
expect(testDestinations.dest3.track).toHaveBeenCalled(); | ||
expect(testDestinations.dest4.track).toHaveBeenCalled(); | ||
expect(testDestinations.dest5.track).toHaveBeenCalled(); | ||
}); | ||
}); |
135 changes: 135 additions & 0 deletions
135
packages/core/src/plugins/__tests__/consent/destinationMultipleCategories.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { createTestClient } from '../../../__tests__/__helpers__/setupSegmentClient'; | ||
import { ConsentPlugin } from '../../ConsentPlugin'; | ||
|
||
import { | ||
setupTestDestinations, | ||
createConsentProvider, | ||
createSegmentWatcher, | ||
} from './utils'; | ||
import destinationsMultipleCategories from './mockSettings/DestinationsMultipleCategories.json'; | ||
|
||
describe('Destinations multiple categories', () => { | ||
const createClient = () => | ||
createTestClient( | ||
{ | ||
settings: destinationsMultipleCategories.integrations, | ||
}, | ||
{ autoAddSegmentDestination: true } | ||
); | ||
|
||
test('no to all', async () => { | ||
const { client } = createClient(); | ||
const testDestinations = setupTestDestinations(client); | ||
const mockConsentStatuses = { | ||
C0001: false, | ||
C0002: false, | ||
C0003: false, | ||
C0004: false, | ||
C0005: false, | ||
}; | ||
|
||
client.add({ | ||
plugin: new ConsentPlugin( | ||
createConsentProvider(mockConsentStatuses), | ||
Object.keys(mockConsentStatuses) | ||
), | ||
}); | ||
|
||
await client.init(); | ||
|
||
const segmentDestination = createSegmentWatcher(client); | ||
|
||
await client.track('test'); | ||
|
||
expect(segmentDestination).not.toHaveBeenCalled(); | ||
expect(testDestinations.dest1.track).not.toHaveBeenCalled(); | ||
expect(testDestinations.dest2.track).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test('yes to 1', async () => { | ||
const { client } = createClient(); | ||
const testDestinations = setupTestDestinations(client); | ||
const mockConsentStatuses = { | ||
C0001: true, | ||
C0002: false, | ||
C0003: false, | ||
C0004: false, | ||
C0005: false, | ||
}; | ||
|
||
client.add({ | ||
plugin: new ConsentPlugin( | ||
createConsentProvider(mockConsentStatuses), | ||
Object.keys(mockConsentStatuses) | ||
), | ||
}); | ||
|
||
await client.init(); | ||
|
||
const segmentDestination = createSegmentWatcher(client); | ||
|
||
await client.track('test'); | ||
|
||
expect(segmentDestination).toHaveBeenCalled(); | ||
expect(testDestinations.dest1.track).not.toHaveBeenCalled(); | ||
expect(testDestinations.dest2.track).toHaveBeenCalled(); | ||
}); | ||
|
||
test('yes to 2', async () => { | ||
const { client } = createClient(); | ||
const testDestinations = setupTestDestinations(client); | ||
const mockConsentStatuses = { | ||
C0001: false, | ||
C0002: true, | ||
C0003: false, | ||
C0004: false, | ||
C0005: false, | ||
}; | ||
|
||
client.add({ | ||
plugin: new ConsentPlugin( | ||
createConsentProvider(mockConsentStatuses), | ||
Object.keys(mockConsentStatuses) | ||
), | ||
}); | ||
|
||
await client.init(); | ||
|
||
const segmentDestination = createSegmentWatcher(client); | ||
|
||
await client.track('test'); | ||
|
||
expect(segmentDestination).toHaveBeenCalled(); | ||
expect(testDestinations.dest1.track).not.toHaveBeenCalled(); | ||
expect(testDestinations.dest2.track).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test('yes to all', async () => { | ||
const { client } = createClient(); | ||
const testDestinations = setupTestDestinations(client); | ||
const mockConsentStatuses = { | ||
C0001: true, | ||
C0002: true, | ||
C0003: true, | ||
C0004: true, | ||
C0005: true, | ||
}; | ||
|
||
client.add({ | ||
plugin: new ConsentPlugin( | ||
createConsentProvider(mockConsentStatuses), | ||
Object.keys(mockConsentStatuses) | ||
), | ||
}); | ||
|
||
await client.init(); | ||
|
||
const segmentDestination = createSegmentWatcher(client); | ||
|
||
await client.track('test'); | ||
|
||
expect(segmentDestination).toHaveBeenCalled(); | ||
expect(testDestinations.dest1.track).toHaveBeenCalled(); | ||
expect(testDestinations.dest2.track).toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.