Skip to content

Commit

Permalink
Merge branch 'main' into BC-5714-store-upload-state
Browse files Browse the repository at this point in the history
  • Loading branch information
bischofmax authored Jan 17, 2024
2 parents 17269a9 + 72bee55 commit 9abd38f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { Test, TestingModule } from '@nestjs/testing';
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 @@ describe('Group (API)', () => {
};

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

const response = await adminClient.get(`/class`).query({
skip: 0,
Expand All @@ -121,14 +121,14 @@ describe('Group (API)', () => {
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
73 changes: 30 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 { classFactory } from '@modules/class/domain/testing/factory/class.factor
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 @@ import {
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,6 +48,7 @@ describe('GroupUc', () => {
let schoolService: DeepMocked<SchoolService>;
let authorizationService: DeepMocked<AuthorizationService>;
let schoolYearService: DeepMocked<SchoolYearService>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let logger: DeepMocked<Logger>;

beforeAll(async () => {
Expand Down Expand Up @@ -336,7 +336,7 @@ describe('GroupUc', () => {
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 +348,7 @@ describe('GroupUc', () => {
: successorClass.name,
type: ClassRootType.CLASS,
externalSourceName: successorClass.source,
teacherNames: [teacherUser.lastName],
teacherNames: [],
schoolYear: nextSchoolYear.name,
isUpgradable: false,
studentCount: 2,
Expand All @@ -360,24 +360,24 @@ describe('GroupUc', () => {
: 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 +420,7 @@ describe('GroupUc', () => {
: classWithoutSchoolYear.name,
type: ClassRootType.CLASS,
externalSourceName: classWithoutSchoolYear.source,
teacherNames: [teacherUser.lastName],
teacherNames: [],
isUpgradable: false,
studentCount: 2,
},
Expand All @@ -429,7 +429,7 @@ describe('GroupUc', () => {
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 +439,14 @@ describe('GroupUc', () => {
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 +476,7 @@ describe('GroupUc', () => {
id: group.id,
name: group.name,
type: ClassRootType.GROUP,
teacherNames: [teacherUser.lastName],
teacherNames: [],
studentCount: 0,
},
],
Expand Down Expand Up @@ -504,7 +504,7 @@ describe('GroupUc', () => {
: 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 +698,7 @@ describe('GroupUc', () => {

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 +709,7 @@ describe('GroupUc', () => {
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 +718,16 @@ describe('GroupUc', () => {
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 +748,7 @@ describe('GroupUc', () => {

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 +768,7 @@ describe('GroupUc', () => {
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 +778,14 @@ describe('GroupUc', () => {
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 +796,7 @@ describe('GroupUc', () => {

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 +815,7 @@ describe('GroupUc', () => {
id: group.id,
name: group.name,
type: ClassRootType.GROUP,
teacherNames: [teacherUser.lastName],
teacherNames: [],
studentCount: 0,
},
],
Expand Down Expand Up @@ -948,7 +948,7 @@ describe('GroupUc', () => {
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 +957,13 @@ describe('GroupUc', () => {
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

0 comments on commit 9abd38f

Please sign in to comment.