From a07e4083215d7f4aef3540f93a1d2373b066a879 Mon Sep 17 00:00:00 2001 From: mrikallab <93978883+mrikallab@users.noreply.github.com> Date: Fri, 19 Jul 2024 15:05:01 +0200 Subject: [PATCH] N21-1995 sync group of type class (#5117) --- .../group/controller/api-test/group.api.spec.ts | 10 +++++++++- .../src/modules/group/repo/group.repo.spec.ts | 17 ++++++++++++----- .../server/src/modules/group/repo/group.repo.ts | 6 +++++- backup/setup/groups.json | 4 ++-- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/apps/server/src/modules/group/controller/api-test/group.api.spec.ts b/apps/server/src/modules/group/controller/api-test/group.api.spec.ts index 4bd62ffcf36..12eb54d3e4d 100644 --- a/apps/server/src/modules/group/controller/api-test/group.api.spec.ts +++ b/apps/server/src/modules/group/controller/api-test/group.api.spec.ts @@ -278,6 +278,7 @@ describe('Group (API)', () => { role: adminUser.roles[0], }, ], + type: GroupEntityTypes.COURSE, }); const availableGroupInSchool: GroupEntity = groupEntityFactory.buildWithId({ organization: school, @@ -287,6 +288,7 @@ describe('Group (API)', () => { role: adminUser.roles[0], }, ], + type: GroupEntityTypes.COURSE, }); const groupInOtherSchool: GroupEntity = groupEntityFactory.buildWithId({ organization: otherSchool, @@ -296,6 +298,7 @@ describe('Group (API)', () => { role: adminUser.roles[0], }, ], + type: GroupEntityTypes.COURSE, }); const syncedCourse: CourseEntity = courseEntityFactory.build({ @@ -459,12 +462,17 @@ describe('Group (API)', () => { const teachersGroup: GroupEntity = groupEntityFactory.buildWithId({ organization: school, users: [{ user: teacherUser, role: teacherUser.roles[0] }], + type: GroupEntityTypes.COURSE, }); const availableTeachersGroup: GroupEntity = groupEntityFactory.buildWithId({ organization: school, users: [{ user: teacherUser, role: teacherUser.roles[0] }], + type: GroupEntityTypes.COURSE, + }); + const groupWithoutTeacher: GroupEntity = groupEntityFactory.buildWithId({ + organization: school, + type: GroupEntityTypes.COURSE, }); - const groupWithoutTeacher: GroupEntity = groupEntityFactory.buildWithId({ organization: school }); const syncedCourse: CourseEntity = courseEntityFactory.build({ school, diff --git a/apps/server/src/modules/group/repo/group.repo.spec.ts b/apps/server/src/modules/group/repo/group.repo.spec.ts index 6d5353ef171..5de475a626f 100644 --- a/apps/server/src/modules/group/repo/group.repo.spec.ts +++ b/apps/server/src/modules/group/repo/group.repo.spec.ts @@ -382,13 +382,20 @@ describe('GroupRepo', () => { const groups: GroupEntity[] = groupEntityFactory.buildListWithId(3, { users: [groupUserEntity], }); + + const courseGroup = groupEntityFactory.buildWithId({ + users: [groupUserEntity], + type: GroupEntityTypes.COURSE, + }); + groups.push(courseGroup); const nameQuery = groups[2].name.slice(-3); const course: CourseEntity = courseFactory.build({ syncedWithGroup: groups[0] }); - const availableGroupsCount = 2; + const courseSyncedWithGroupOfTypeClass = courseFactory.build({ syncedWithGroup: groups[3] }); + const availableGroupsCount = 3; const otherGroups: GroupEntity[] = groupEntityFactory.buildListWithId(2); - await em.persistAndFlush([userEntity, ...groups, ...otherGroups, course]); + await em.persistAndFlush([userEntity, ...groups, ...otherGroups, course, courseSyncedWithGroupOfTypeClass]); em.clear(); const defaultOptions: IFindOptions = { pagination: { skip: 0 } }; @@ -418,7 +425,7 @@ describe('GroupRepo', () => { expect(result.total).toEqual(availableGroupsCount); expect(result.data.length).toEqual(1); - expect(result.data[0].id).toEqual(groups[2].id); + expect(result.data[0].id).toEqual(groups[1].id); }); it('should return groups according to name query', async () => { @@ -463,7 +470,7 @@ describe('GroupRepo', () => { const school: SchoolEntity = schoolEntityFactory.buildWithId(); const schoolId: EntityId = school.id; const groups: GroupEntity[] = groupEntityFactory.buildListWithId(3, { - type: GroupEntityTypes.CLASS, + type: GroupEntityTypes.OTHER, organization: school, }); const nameQuery = groups[2].name.slice(-3); @@ -472,7 +479,7 @@ describe('GroupRepo', () => { const otherSchool: SchoolEntity = schoolEntityFactory.buildWithId(); const otherGroups: GroupEntity[] = groupEntityFactory.buildListWithId(2, { - type: GroupEntityTypes.CLASS, + type: GroupEntityTypes.OTHER, organization: otherSchool, }); diff --git a/apps/server/src/modules/group/repo/group.repo.ts b/apps/server/src/modules/group/repo/group.repo.ts index 3c92c427918..8807e6850b4 100644 --- a/apps/server/src/modules/group/repo/group.repo.ts +++ b/apps/server/src/modules/group/repo/group.repo.ts @@ -109,7 +109,11 @@ export class GroupRepo extends BaseDomainObjectRepo { as: 'syncedCourses', }, }, - { $match: { syncedCourses: { $size: 0 } } }, + { + $match: { + $or: [{ syncedCourses: { $size: 0 } }, { type: { $eq: GroupTypes.CLASS } }], + }, + }, { $sort: { name: 1 } } ); diff --git a/backup/setup/groups.json b/backup/setup/groups.json index 3a3f140b472..7c4d1a276ce 100644 --- a/backup/setup/groups.json +++ b/backup/setup/groups.json @@ -120,7 +120,7 @@ "$date": "2023-10-17T12:15:26.461Z" }, "name": "Cypress-Test-Group-Course-Sync", - "type": "class", + "type": "other", "externalSource_externalId": "fd84869b-56e8-41d2-a3dd-6c7239068ed5", "externalSource_system": { "$oid": "0000d186816abba584714c93" @@ -155,7 +155,7 @@ "$date": "2023-10-17T12:15:26.461Z" }, "name": "Cypress-Test-Group-Course-Sync2", - "type": "class", + "type": "course", "externalSource_externalId": "fd84869b-56e8-41d2-a3dd-6c7239068ed5", "externalSource_system": { "$oid": "0000d186816abba584714c93"