From 9ce5bbee2008ec5479de6b793a29e75263533983 Mon Sep 17 00:00:00 2001 From: Benjamin Blanchard Date: Thu, 14 May 2026 15:55:46 -0400 Subject: [PATCH] use working group instead of group for in/exclusions --- .../api/services/ExperimentAssignmentService.ts | 8 +++----- .../services/ExperimentAssignmentService.test.ts | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/api/services/ExperimentAssignmentService.ts b/packages/backend/src/api/services/ExperimentAssignmentService.ts index 57ce1bfac..fe764f024 100644 --- a/packages/backend/src/api/services/ExperimentAssignmentService.ts +++ b/packages/backend/src/api/services/ExperimentAssignmentService.ts @@ -2223,11 +2223,9 @@ export class ExperimentAssignmentService { const explicitGroupExclusionFilteredData: { groupId: string; type: string; id: string }[] = []; const userGroups = []; - if (experimentUser.group) { - Object.keys(experimentUser.group).forEach((type) => { - experimentUser.group[type].forEach((groupId) => { - userGroups.push({ type, groupId }); - }); + if (experimentUser.workingGroup) { + Object.keys(experimentUser.workingGroup).forEach((type) => { + userGroups.push({ type, groupId: experimentUser.workingGroup[type] }); }); } diff --git a/packages/backend/test/unit/services/ExperimentAssignmentService.test.ts b/packages/backend/test/unit/services/ExperimentAssignmentService.test.ts index fcbf71868..e97ee476d 100644 --- a/packages/backend/test/unit/services/ExperimentAssignmentService.test.ts +++ b/packages/backend/test/unit/services/ExperimentAssignmentService.test.ts @@ -558,8 +558,8 @@ describe('Experiment Assignment Service Test', () => { expect(includedExperiment).toEqual([exp]); }); - it('[experimentLevelExclusionInclusion] should return an exclusion reason if a user or userGroup is on exclusion list', async () => { - const userDoc = { id: 'user2', group: { teacher: ['teacher1'] }, workingGroup: {} }; + it('[experimentLevelExclusionInclusion] should return an exclusion reason if a user workingGroup is on exclusion list', async () => { + const userDoc = { id: 'user2', group: { teacher: ['teacher1'] }, workingGroup: { teacher: 'teacher1' } }; const exp = structuredClone(simpleIndividualAssignmentExperiment); const [includedExperiment, exclusionReason] = await testedModule.experimentLevelExclusionInclusion([exp], userDoc); expect(exclusionReason.length).toEqual(1); @@ -568,6 +568,18 @@ describe('Experiment Assignment Service Test', () => { expect(includedExperiment).toEqual([]); }); + it('[experimentLevelExclusionInclusion] should not return an exclusion reason if a user workingGroup is not on exclusion list', async () => { + const userDoc = { + id: 'user2', + group: { teacher: ['teacher1', 'teacher2'] }, + workingGroup: { teacher: 'teacher2' }, + }; + const exp = structuredClone(simpleIndividualAssignmentExperiment); + const [includedExperiment, exclusionReason] = await testedModule.experimentLevelExclusionInclusion([exp], userDoc); + expect(exclusionReason.length).toEqual(0); + expect(includedExperiment).toEqual([exp]); + }); + it('[createExperimentPool] should return empty pool of experiments for no active experiments', async () => { const expResult = await testedModule.createExperimentPool([]); expect(expResult).toEqual([]);