Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorCapCoder committed Nov 1, 2023
1 parent 670ac36 commit 417509c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
36 changes: 28 additions & 8 deletions apps/server/src/modules/group/uc/group.uc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ describe('GroupUc', () => {

throw new Error();
});
schoolYearService.findById.mockResolvedValue(schoolYear);
schoolYearService.findById.mockResolvedValueOnce(schoolYear);
schoolYearService.findById.mockResolvedValueOnce(nextSchoolYear);
schoolYearService.getCurrentSchoolYear.mockResolvedValue(schoolYear);

return {
Expand All @@ -227,6 +228,7 @@ describe('GroupUc', () => {
groupWithSystem,
system,
schoolYear,
nextSchoolYear,
};
};

Expand All @@ -247,12 +249,13 @@ describe('GroupUc', () => {

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

const result: Page<ClassInfoDto> = await uc.findAllClassesForSchool(
teacherUser.id,
teacherUser.school.id,
SchoolYearQueryType.CURRENT_YEAR
undefined
);

expect(result).toEqual<Page<ClassInfoDto>>({
Expand All @@ -267,6 +270,18 @@ describe('GroupUc', () => {
isUpgradable: false,
studentCount: 2,
},
{
id: successorClass.id,
name: successorClass.gradeLevel
? `${successorClass.gradeLevel}${successorClass.name}`
: successorClass.name,
externalSourceName: successorClass.source,
type: ClassRootType.CLASS,
teachers: [teacherUser.lastName],
schoolYear: nextSchoolYear.name,
isUpgradable: false,
studentCount: 2,
},
{
id: group.id,
name: group.name,
Expand All @@ -283,7 +298,7 @@ describe('GroupUc', () => {
studentCount: 1,
},
],
total: 3,
total: 4,
});
});
});
Expand Down Expand Up @@ -366,7 +381,7 @@ describe('GroupUc', () => {

describe('when querying for classes from next school year', () => {
it('should only return classes from next school year', async () => {
const { teacherUser, successorClass } = setup();
const { teacherUser, successorClass, nextSchoolYear } = setup();

const result: Page<ClassInfoDto> = await uc.findAllClassesForSchool(
teacherUser.id,
Expand All @@ -378,10 +393,15 @@ describe('GroupUc', () => {
data: [
{
id: successorClass.id,
name: successorClass.name,
name: successorClass.gradeLevel
? `${successorClass.gradeLevel}${successorClass.name}`
: successorClass.name,
externalSourceName: successorClass.source,
type: ClassRootType.CLASS,
teachers: [teacherUser.lastName],
studentCount: 0,
schoolYear: nextSchoolYear.name,
isUpgradable: false,
studentCount: 2,
},
],
total: 1,
Expand All @@ -396,7 +416,7 @@ describe('GroupUc', () => {
const result: Page<ClassInfoDto> = await uc.findAllClassesForSchool(
teacherUser.id,
teacherUser.school.id,
SchoolYearQueryType.NEXT_YEAR
SchoolYearQueryType.PREVIOUS_YEARS
);

expect(result).toEqual<Page<ClassInfoDto>>({
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/modules/group/uc/group.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class GroupUc {

const classInfosFromClasses = await this.findClassesForSchool(schoolId, schoolYearQueryType);

if (schoolYearQueryType === SchoolYearQueryType.CURRENT_YEAR) {
if (schoolYearQueryType === SchoolYearQueryType.CURRENT_YEAR || schoolYearQueryType === undefined) {
classInfosFromGroups = await this.findGroupsOfTypeClassForSchool(schoolId);
}

Expand Down

0 comments on commit 417509c

Please sign in to comment.