Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N21-1655 Fix group timeout #4699

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -7,13 +7,13 @@
import { Role, SchoolEntity, SchoolYearEntity, SystemEntity, User } from '@shared/domain/entity';
import { RoleName, SortOrder } from '@shared/domain/interface';
import {
TestApiClient,
UserAndAccountTestFactory,
groupEntityFactory,
roleFactory,
schoolFactory,
schoolYearFactory,
systemEntityFactory,
TestApiClient,
UserAndAccountTestFactory,
userFactory,
} from '@shared/testing';
import { ObjectId } from 'bson';
Expand Down Expand Up @@ -104,7 +104,7 @@
};

it('should return the classes of his school', async () => {
const { adminClient, group, clazz, system, adminUser, teacherUser, schoolYear } = await setup();

Check failure on line 107 in apps/server/src/modules/group/controller/api-test/group.api.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'adminUser' is assigned a value but never used

Check failure on line 107 in apps/server/src/modules/group/controller/api-test/group.api.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'teacherUser' is assigned a value but never used

const response = await adminClient.get(`/class`).query({
skip: 0,
Expand All @@ -121,14 +121,14 @@
type: ClassRootType.GROUP,
name: group.name,
externalSourceName: system.displayName,
teachers: [adminUser.lastName],
teachers: [],
studentCount: 0,
},
{
id: clazz.id,
type: ClassRootType.CLASS,
name: clazz.gradeLevel ? `${clazz.gradeLevel}${clazz.name}` : clazz.name,
teachers: [teacherUser.lastName],
teachers: [],
schoolYear: schoolYear.name,
isUpgradable: false,
studentCount: 0,
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/modules/group/controller/group.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { ErrorResponse } from '@src/core/error/dto';
import { GroupUc } from '../uc';
import { ClassInfoDto, ResolvedGroupDto } from '../uc/dto';
import {
ClassCallerParams,
ClassFilterParams,
ClassInfoSearchListResponse,
ClassSortParams,
GroupIdParams,
GroupResponse,
GroupPaginationParams,
ClassCallerParams,
GroupResponse,
} from './dto';
import { GroupResponseMapper } from './mapper';

Expand Down
72 changes: 29 additions & 43 deletions apps/server/src/modules/group/uc/group.uc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import { SchoolYearService } from '@modules/legacy-school';
import { RoleService } from '@modules/role';
import { RoleDto } from '@modules/role/service/dto/role.dto';
import { School, SchoolService } from '@modules/school/domain';
import { schoolFactory } from '@modules/school/testing';
import { LegacySystemService, SystemDto } from '@modules/system';
import { UserService } from '@modules/user';
import { ForbiddenException } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { ReferencedEntityNotFoundLoggable } from '@shared/common/loggable';
import { NotFoundLoggableException } from '@shared/common/loggable-exception';
import { Page, UserDO } from '@shared/domain/domainobject';
import { SchoolYearEntity, User } from '@shared/domain/entity';
Expand All @@ -27,8 +28,6 @@
userFactory,
} from '@shared/testing';
import { Logger } from '@src/core/logger';
import { School, SchoolService } from '@modules/school/domain';
import { schoolFactory } from '@modules/school/testing';
import { ClassRequestContext, SchoolYearQueryType } from '../controller/dto/interface';
import { Group, GroupTypes } from '../domain';
import { UnknownQueryTypeLoggableException } from '../loggable';
Expand All @@ -49,7 +48,7 @@
let schoolService: DeepMocked<SchoolService>;
let authorizationService: DeepMocked<AuthorizationService>;
let schoolYearService: DeepMocked<SchoolYearService>;
let logger: DeepMocked<Logger>;

Check failure on line 51 in apps/server/src/modules/group/uc/group.uc.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'logger' is assigned a value but never used

beforeAll(async () => {
module = await Test.createTestingModule({
Expand Down Expand Up @@ -336,7 +335,7 @@
name: clazz.gradeLevel ? `${clazz.gradeLevel}${clazz.name}` : clazz.name,
type: ClassRootType.CLASS,
externalSourceName: clazz.source,
teacherNames: [teacherUser.lastName],
teacherNames: [],
schoolYear: schoolYear.name,
isUpgradable: false,
studentCount: 2,
Expand All @@ -348,7 +347,7 @@
: successorClass.name,
type: ClassRootType.CLASS,
externalSourceName: successorClass.source,
teacherNames: [teacherUser.lastName],
teacherNames: [],
schoolYear: nextSchoolYear.name,
isUpgradable: false,
studentCount: 2,
Expand All @@ -360,24 +359,24 @@
: classWithoutSchoolYear.name,
type: ClassRootType.CLASS,
externalSourceName: classWithoutSchoolYear.source,
teacherNames: [teacherUser.lastName],
teacherNames: [],
isUpgradable: false,
studentCount: 2,
},
{
id: group.id,
name: group.name,
type: ClassRootType.GROUP,
teacherNames: [teacherUser.lastName],
teacherNames: [],
studentCount: 0,
},
{
id: groupWithSystem.id,
name: groupWithSystem.name,
type: ClassRootType.GROUP,
externalSourceName: system.displayName,
teacherNames: [teacherUser.lastName],
studentCount: 1,
teacherNames: [],
studentCount: 0,
},
],
total: 5,
Expand Down Expand Up @@ -420,7 +419,7 @@
: classWithoutSchoolYear.name,
type: ClassRootType.CLASS,
externalSourceName: classWithoutSchoolYear.source,
teacherNames: [teacherUser.lastName],
teacherNames: [],
isUpgradable: false,
studentCount: 2,
},
Expand All @@ -429,7 +428,7 @@
name: clazz.gradeLevel ? `${clazz.gradeLevel}${clazz.name}` : clazz.name,
type: ClassRootType.CLASS,
externalSourceName: clazz.source,
teacherNames: [teacherUser.lastName],
teacherNames: [],
schoolYear: schoolYear.name,
isUpgradable: false,
studentCount: 2,
Expand All @@ -439,14 +438,14 @@
name: groupWithSystem.name,
type: ClassRootType.GROUP,
externalSourceName: system.displayName,
teacherNames: [teacherUser.lastName],
studentCount: 1,
teacherNames: [],
studentCount: 0,
},
{
id: group.id,
name: group.name,
type: ClassRootType.GROUP,
teacherNames: [teacherUser.lastName],
teacherNames: [],
studentCount: 0,
},
],
Expand Down Expand Up @@ -476,7 +475,7 @@
id: group.id,
name: group.name,
type: ClassRootType.GROUP,
teacherNames: [teacherUser.lastName],
teacherNames: [],
studentCount: 0,
},
],
Expand Down Expand Up @@ -504,7 +503,7 @@
: successorClass.name,
externalSourceName: successorClass.source,
type: ClassRootType.CLASS,
teacherNames: [teacherUser.lastName],
teacherNames: [],
schoolYear: nextSchoolYear.name,
isUpgradable: false,
studentCount: 2,
Expand Down Expand Up @@ -698,7 +697,7 @@

describe('when no pagination is given', () => {
it('should return all classes sorted by name', async () => {
const { adminUser, teacherUser, clazz, group, groupWithSystem, system, schoolYear } = setup();
const { adminUser, clazz, group, groupWithSystem, system, schoolYear } = setup();

const result: Page<ClassInfoDto> = await uc.findAllClasses(adminUser.id, adminUser.school.id);

Expand All @@ -709,7 +708,7 @@
name: clazz.gradeLevel ? `${clazz.gradeLevel}${clazz.name}` : clazz.name,
type: ClassRootType.CLASS,
externalSourceName: clazz.source,
teacherNames: [teacherUser.lastName],
teacherNames: [],
schoolYear: schoolYear.name,
isUpgradable: false,
studentCount: 2,
Expand All @@ -718,16 +717,16 @@
id: group.id,
name: group.name,
type: ClassRootType.GROUP,
teacherNames: [teacherUser.lastName],
teacherNames: [],
studentCount: 0,
},
{
id: groupWithSystem.id,
name: groupWithSystem.name,
type: ClassRootType.GROUP,
externalSourceName: system.displayName,
teacherNames: [teacherUser.lastName],
studentCount: 1,
teacherNames: [],
studentCount: 0,
},
],
total: 3,
Expand All @@ -748,7 +747,7 @@

describe('when sorting by external source name in descending order', () => {
it('should return all classes sorted by external source name in descending order', async () => {
const { adminUser, teacherUser, clazz, group, groupWithSystem, system, schoolYear } = setup();
const { adminUser, clazz, group, groupWithSystem, system, schoolYear } = setup();

const result: Page<ClassInfoDto> = await uc.findAllClasses(
adminUser.id,
Expand All @@ -768,7 +767,7 @@
name: clazz.gradeLevel ? `${clazz.gradeLevel}${clazz.name}` : clazz.name,
type: ClassRootType.CLASS,
externalSourceName: clazz.source,
teacherNames: [teacherUser.lastName],
teacherNames: [],
schoolYear: schoolYear.name,
isUpgradable: false,
studentCount: 2,
Expand All @@ -778,14 +777,14 @@
name: groupWithSystem.name,
type: ClassRootType.GROUP,
externalSourceName: system.displayName,
teacherNames: [teacherUser.lastName],
studentCount: 1,
teacherNames: [],
studentCount: 0,
},
{
id: group.id,
name: group.name,
type: ClassRootType.GROUP,
teacherNames: [teacherUser.lastName],
teacherNames: [],
studentCount: 0,
},
],
Expand All @@ -796,7 +795,7 @@

describe('when using pagination', () => {
it('should return the selected page', async () => {
const { adminUser, teacherUser, group } = setup();
const { adminUser, group } = setup();

const result: Page<ClassInfoDto> = await uc.findAllClasses(
adminUser.id,
Expand All @@ -815,7 +814,7 @@
id: group.id,
name: group.name,
type: ClassRootType.GROUP,
teacherNames: [teacherUser.lastName],
teacherNames: [],
studentCount: 0,
},
],
Expand Down Expand Up @@ -948,7 +947,7 @@
name: clazz.gradeLevel ? `${clazz.gradeLevel}${clazz.name}` : clazz.name,
type: ClassRootType.CLASS,
externalSourceName: clazz.source,
teacherNames: [teacherUser.lastName],
teacherNames: [],
schoolYear: schoolYear.name,
isUpgradable: false,
studentCount: 2,
Expand All @@ -957,26 +956,13 @@
id: group.id,
name: group.name,
type: ClassRootType.GROUP,
teacherNames: [teacherUser.lastName],
teacherNames: [],
studentCount: 0,
},
],
total: 2,
});
});

it('should log the missing user', async () => {
const { teacherUser, clazz, group, notFoundReferenceId } = setup();

await uc.findAllClasses(teacherUser.id, teacherUser.school.id);

expect(logger.warning).toHaveBeenCalledWith(
new ReferencedEntityNotFoundLoggable(Class.name, clazz.id, UserDO.name, notFoundReferenceId)
);
expect(logger.warning).toHaveBeenCalledWith(
new ReferencedEntityNotFoundLoggable(Group.name, group.id, UserDO.name, notFoundReferenceId)
);
});
});
});

Expand Down
Loading
Loading