Skip to content

Commit

Permalink
N21-1995 sync group of type class (#5117)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrikallab authored and psachmann committed Jul 24, 2024
1 parent f8ab29b commit e2b51d2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ describe('Group (API)', () => {
role: adminUser.roles[0],
},
],
type: GroupEntityTypes.COURSE,
});
const availableGroupInSchool: GroupEntity = groupEntityFactory.buildWithId({
organization: school,
Expand All @@ -287,6 +288,7 @@ describe('Group (API)', () => {
role: adminUser.roles[0],
},
],
type: GroupEntityTypes.COURSE,
});
const groupInOtherSchool: GroupEntity = groupEntityFactory.buildWithId({
organization: otherSchool,
Expand All @@ -296,6 +298,7 @@ describe('Group (API)', () => {
role: adminUser.roles[0],
},
],
type: GroupEntityTypes.COURSE,
});

const syncedCourse: CourseEntity = courseEntityFactory.build({
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 12 additions & 5 deletions apps/server/src/modules/group/repo/group.repo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Group> = { pagination: { skip: 0 } };
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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);
Expand All @@ -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,
});

Expand Down
6 changes: 5 additions & 1 deletion apps/server/src/modules/group/repo/group.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ export class GroupRepo extends BaseDomainObjectRepo<Group, GroupEntity> {
as: 'syncedCourses',
},
},
{ $match: { syncedCourses: { $size: 0 } } },
{
$match: {
$or: [{ syncedCourses: { $size: 0 } }, { type: { $eq: GroupTypes.CLASS } }],
},
},
{ $sort: { name: 1 } }
);

Expand Down
4 changes: 2 additions & 2 deletions backup/setup/groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit e2b51d2

Please sign in to comment.