Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,8 @@ export class ExperimentAssignmentService {

//users and groups excluded from GlobalExclude segment
const userExcluded = excludedUsers.find((userId) => userId === experimentUser.id);
const groupExcluded = userGroup.length > 0 ? excludedGroups.filter((group) => userGroup.includes(group)) : [];
const groupExcluded =
userGroup.length > 0 ? excludedGroups.filter((group) => userGroup.includes(group)) : excludedGroups;

return [userExcluded !== undefined, groupExcluded.length > 0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,46 @@ describe('Experiment Assignment Service Test', () => {
expect(exclusionResult).toEqual([true, false]);
});

it('[checkUserOrGroupIsGloballyExcluded] should return true for users with no working group if there is a global group exclusion', async () => {
const userDoc = { id: 'user6', group: {}, workingGroup: {} };
// stub the global exclusion segment with group `anygroup` in groupForSegment
testedModule.segmentService.getSegmentByIds.withArgs(['77777777-7777-7777-7777-777777777777']).resolves([
{
id: '77777777-7777-7777-7777-777777777777',
name: 'Global Exclude',
description: 'Globally excluded Users, Groups and Segments',
context: 'context',
type: 'global_exclude',
individualForSegment: [],
groupForSegment: [{ groupId: 'anygroup', type: 'teacher' }],
subSegments: [],
},
]);

const exclusionResult = await testedModule.checkUserOrGroupIsGloballyExcluded(userDoc, 'context');
expect(exclusionResult).toEqual([false, true]);
});

it('[checkUserOrGroupIsGloballyExcluded] should return false for users with a non-excluded working group if there is a global group exclusion', async () => {
const userDoc = { id: 'user7', group: { schoolId: ['school1'] }, workingGroup: { schoolId: 'school1' } };
// stub the global exclusion segment with group `anygroup` in groupForSegment
testedModule.segmentService.getSegmentByIds.withArgs(['77777777-7777-7777-7777-777777777777']).resolves([
{
id: '77777777-7777-7777-7777-777777777777',
name: 'Global Exclude',
description: 'Globally excluded Users, Groups and Segments',
context: 'context',
type: 'global_exclude',
individualForSegment: [],
groupForSegment: [{ groupId: 'anygroup', type: 'teacher' }],
subSegments: [],
},
]);

const exclusionResult = await testedModule.checkUserOrGroupIsGloballyExcluded(userDoc, 'context');
expect(exclusionResult).toEqual([false, false]);
});

it('[getAssignmentsAndExclusionsForUser] should return empty enrollment/exclusion user and group documents', async () => {
const experimentUser = {
id: 'user123',
Expand Down
Loading