Merge branch 'dev' into feat/discussions

This commit is contained in:
Tibo De Peuter 2025-05-17 19:52:21 +02:00
commit edc52a559c
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
181 changed files with 7820 additions and 1515 deletions

View file

@ -5,7 +5,6 @@ import { Language } from '@dwengo-1/common/util/language';
import { getAllAnswersHandler, getAnswerHandler, updateAnswerHandler } from '../../src/controllers/answers';
import { BadRequestException } from '../../src/exceptions/bad-request-exception';
import { NotFoundException } from '../../src/exceptions/not-found-exception';
import { getQuestion02 } from '../test_assets/questions/questions.testdata';
import { getAnswer02 } from '../test_assets/questions/answers.testdata';
describe('Questions controllers', () => {

View file

@ -0,0 +1,76 @@
import { setupTestApp } from '../setup-tests.js';
import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest';
import { Request, Response } from 'express';
import { getAssignmentHandler, getAllAssignmentsHandler, getAssignmentsSubmissionsHandler } from '../../src/controllers/assignments.js';
import { NotFoundException } from '../../src/exceptions/not-found-exception';
import { getClass01 } from '../test_assets/classes/classes.testdata';
import { getAssignment01 } from '../test_assets/assignments/assignments.testdata';
function createRequestObject(
classid: string,
assignmentid: string
): {
query: { full: string };
params: { classid: string; id: string };
} {
return {
params: {
classid: classid,
id: assignmentid,
},
query: {
full: 'true',
},
};
}
describe('Assignment controllers', () => {
let req: Partial<Request>;
let res: Partial<Response>;
let jsonMock: Mock;
let statusMock: Mock;
beforeAll(async () => {
await setupTestApp();
});
beforeEach(async () => {
jsonMock = vi.fn();
statusMock = vi.fn().mockReturnThis();
res = {
json: jsonMock,
status: statusMock,
};
});
it('return error non-existing assignment', async () => {
req = createRequestObject('doesnotexist', '43000'); // Should not exist
await expect(async () => getAssignmentHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
it('should return an assignment', async () => {
const assignment = getAssignment01();
req = createRequestObject(assignment.within.classId as string, (assignment.id ?? 1).toString());
await getAssignmentHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ assignment: expect.anything() }));
});
it('should return a list of assignments', async () => {
req = createRequestObject(getClass01().classId as string, 'irrelevant');
await getAllAssignmentsHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ assignments: expect.anything() }));
});
it('should return a list of submissions for an assignment', async () => {
const assignment = getAssignment01();
req = createRequestObject(assignment.within.classId as string, (assignment.id ?? 1).toString());
await getAssignmentsSubmissionsHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ submissions: expect.anything() }));
});
});

View file

@ -0,0 +1,123 @@
import { setupTestApp } from '../setup-tests.js';
import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest';
import {
createClassHandler,
deleteClassHandler,
getAllClassesHandler,
getClassHandler,
getClassStudentsHandler,
getTeacherInvitationsHandler,
} from '../../src/controllers/classes.js';
import { Request, Response } from 'express';
import { NotFoundException } from '../../src/exceptions/not-found-exception';
import { BadRequestException } from '../../src/exceptions/bad-request-exception';
import { getClass01 } from '../test_assets/classes/classes.testdata';
describe('Class controllers', () => {
let req: Partial<Request>;
let res: Partial<Response>;
let jsonMock: Mock;
let statusMock: Mock;
beforeAll(async () => {
await setupTestApp();
});
beforeEach(async () => {
jsonMock = vi.fn();
statusMock = vi.fn().mockReturnThis();
res = {
json: jsonMock,
status: statusMock,
};
});
it('create and delete class', async () => {
req = {
body: { displayName: 'coole_nieuwe_klas' },
};
await createClassHandler(req as Request, res as Response);
const result = jsonMock.mock.lastCall?.[0];
// Console.log('class', result.class);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ class: expect.anything() }));
req = {
params: { id: result.class.id },
};
await deleteClassHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ class: expect.anything() }));
});
it('Error class not found', async () => {
req = {
params: { id: 'doesnotexist' },
};
await expect(async () => getClassHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
it('Error create a class without name', async () => {
req = {
body: {},
};
await expect(async () => createClassHandler(req as Request, res as Response)).rejects.toThrow(BadRequestException);
});
it('return list of students', async () => {
req = {
params: { id: getClass01().classId as string },
query: {},
};
await getClassStudentsHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ students: expect.anything() }));
});
it('Error students on a non-existent class', async () => {
req = {
params: { id: 'doesnotexist' },
query: {},
};
await expect(async () => getClassStudentsHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
it('should return 200 and a list of teacher-invitations', async () => {
const classId = getClass01().classId as string;
req = {
params: { id: classId },
query: {},
};
await getTeacherInvitationsHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ invitations: expect.anything() }));
});
it('Error teacher-invitations on a non-existent class', async () => {
req = {
params: { id: 'doesnotexist' },
query: {},
};
await expect(async () => getTeacherInvitationsHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
it('should return a list of classes', async () => {
req = {
query: {},
};
await getAllClassesHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ classes: expect.anything() }));
});
});

View file

@ -0,0 +1,140 @@
import { setupTestApp } from '../setup-tests.js';
import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest';
import { Request, Response } from 'express';
import {
createGroupHandler,
deleteGroupHandler,
getAllGroupsHandler,
getGroupHandler,
getGroupSubmissionsHandler,
} from '../../src/controllers/groups.js';
import { NotFoundException } from '../../src/exceptions/not-found-exception';
import { getClass01 } from '../test_assets/classes/classes.testdata';
import { getAssignment01, getAssignment02 } from '../test_assets/assignments/assignments.testdata';
import { getTestGroup01 } from '../test_assets/assignments/groups.testdata';
function createRequestObject(
classid: string,
assignmentid: string,
groupNumber: string
): {
query: { full: string };
params: { classid: string; groupid: string; assignmentid: string };
} {
return {
params: {
classid: classid,
assignmentid: assignmentid,
groupid: groupNumber,
},
query: {
full: 'true',
},
};
}
describe('Group controllers', () => {
let req: Partial<Request>;
let res: Partial<Response>;
let jsonMock: Mock;
let statusMock: Mock;
beforeAll(async () => {
await setupTestApp();
});
beforeEach(async () => {
jsonMock = vi.fn();
statusMock = vi.fn().mockReturnThis();
res = {
json: jsonMock,
status: statusMock,
};
});
it('Error not found on a non-existing group', async () => {
req = {
params: {
classid: 'id01',
assignmentid: '1',
groupid: '154981', // Should not exist
},
query: {},
};
await expect(async () => getGroupHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
it('should return 404 not found on a non-existing assignment', async () => {
req = {
params: {
classid: 'id01',
assignmentid: '1000', // Should not exist
groupid: '42000', // Should not exist
},
query: {},
};
await expect(async () => getGroupHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
it('should return 404 not found ont a non-existing class', async () => {
req = {
params: {
classid: 'doesnotexist', // Should not exist
assignmentid: '1000', // Should not exist
groupid: '42000', // Should not exist
},
query: {},
};
await expect(async () => getGroupHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
it('should return an existing group', async () => {
const group = getTestGroup01();
const classId = getClass01().classId as string;
req = createRequestObject(classId, (group.assignment.id ?? 1).toString(), (group.groupNumber ?? 1).toString());
await getGroupHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ group: expect.anything() }));
});
it('Create and delete', async () => {
const assignment = getAssignment02();
const classId = assignment.within.classId as string;
req = createRequestObject(classId, (assignment.id ?? 1).toString(), '1');
req.body = {
members: ['Noordkaap', 'DireStraits'],
};
await createGroupHandler(req as Request, res as Response);
await deleteGroupHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ group: expect.anything() }));
});
it('should return the submissions for a group', async () => {
const group = getTestGroup01();
const classId = getClass01().classId as string;
req = createRequestObject(classId, (group.assignment.id ?? 1).toString(), (group.groupNumber ?? 1).toString());
await getGroupSubmissionsHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ submissions: expect.anything() }));
});
it('should return a list of groups for an assignment', async () => {
const assignment = getAssignment01();
const classId = assignment.within.classId as string;
req = createRequestObject(classId, (assignment.id ?? 1).toString(), '1');
await getAllGroupsHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ groups: expect.anything() }));
});
});

View file

@ -15,7 +15,7 @@ import {
deleteClassJoinRequestHandler,
getStudentRequestHandler,
} from '../../src/controllers/students.js';
import { getDireStraits, getNoordkaap, getPinkFloyd, getTheDoors, TEST_STUDENTS } from '../test_assets/users/students.testdata.js';
import { getDireStraits, getNoordkaap, getTheDoors, TEST_STUDENTS } from '../test_assets/users/students.testdata.js';
import { NotFoundException } from '../../src/exceptions/not-found-exception.js';
import { BadRequestException } from '../../src/exceptions/bad-request-exception.js';
import { ConflictException } from '../../src/exceptions/conflict-exception.js';
@ -25,7 +25,6 @@ import { getClass02 } from '../test_assets/classes/classes.testdata.js';
import { getClassJoinRequest02 } from '../test_assets/classes/class-join-requests.testdata.js';
import { getTestGroup01 } from '../test_assets/assignments/groups.testdata.js';
import { getSubmission01 } from '../test_assets/assignments/submission.testdata.js';
import { getQuestion } from '../../src/services/questions.js';
import { getQuestion01 } from '../test_assets/questions/questions.testdata.js';
describe('Student controllers', () => {

View file

@ -0,0 +1,61 @@
import { setupTestApp } from '../setup-tests.js';
import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest';
import { getSubmissionHandler, getAllSubmissionsHandler } from '../../src/controllers/submissions.js';
import { Request, Response } from 'express';
import { NotFoundException } from '../../src/exceptions/not-found-exception';
import { getClass02 } from '../test_assets/classes/classes.testdata';
function createRequestObject(
hruid: string,
submissionNumber: string
): {
query: { language: string; version: string };
params: { hruid: string; id: string };
} {
return {
params: {
hruid: hruid,
id: submissionNumber,
},
query: {
language: 'en',
version: '1',
},
};
}
describe('Submission controllers', () => {
let req: Partial<Request>;
let res: Partial<Response>;
let jsonMock: Mock;
let statusMock: Mock;
beforeAll(async () => {
await setupTestApp();
});
beforeEach(async () => {
jsonMock = vi.fn();
statusMock = vi.fn().mockReturnThis();
res = {
json: jsonMock,
status: statusMock,
};
});
it('error submission is not found', async () => {
req = createRequestObject('id01', '1000000');
await expect(async () => getSubmissionHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
it('should return a list of submissions for a learning object', async () => {
req = createRequestObject(getClass02().classId as string, 'irrelevant');
await getAllSubmissionsHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ submissions: expect.anything() }));
});
});

View file

@ -14,7 +14,6 @@ import { BadRequestException } from '../../src/exceptions/bad-request-exception'
import { ClassStatus } from '@dwengo-1/common/util/class-join-request';
import { getTeacherInvitation01 } from '../test_assets/classes/teacher-invitations.testdata.js';
import { getLimpBizkit, getTestleerkracht1 } from '../test_assets/users/teachers.testdata.js';
import { getTestGroup01 } from '../test_assets/assignments/groups.testdata.js';
import { getClass02 } from '../test_assets/classes/classes.testdata.js';
describe('Teacher controllers', () => {

View file

@ -15,12 +15,10 @@ import {
import { BadRequestException } from '../../src/exceptions/bad-request-exception.js';
import { EntityAlreadyExistsException } from '../../src/exceptions/entity-already-exists-exception.js';
import { getStudentRequestsHandler } from '../../src/controllers/students.js';
import { TeacherDTO } from '@dwengo-1/common/interfaces/teacher';
import { getClassHandler } from '../../src/controllers/classes';
import { getFooFighters, getTestleerkracht1 } from '../test_assets/users/teachers.testdata.js';
import { getClass02 } from '../test_assets/classes/classes.testdata.js';
import { getPinkFloyd, TEST_STUDENTS } from '../test_assets/users/students.testdata.js';
import { getClassJoinRequest01, getClassJoinRequest02 } from '../test_assets/classes/class-join-requests.testdata.js';
import { getClassJoinRequest01 } from '../test_assets/classes/class-join-requests.testdata.js';
describe('Teacher controllers', () => {
let req: Partial<Request>;
@ -102,7 +100,7 @@ describe('Teacher controllers', () => {
});
it('Teacher list', async () => {
req = { query: { full: 'true' } };
req = { query: { full: 'false' } };
await getAllTeachersHandler(req as Request, res as Response);
@ -110,12 +108,10 @@ describe('Teacher controllers', () => {
const result = jsonMock.mock.lastCall?.[0];
const teacherUsernames = result.teachers.map((s: TeacherDTO) => s.username);
const teacher = getTestleerkracht1();
expect(teacherUsernames).toContain(teacher.username);
expect(result.teachers).toContain(teacher.username);
expect(result.teachers).toHaveLength(5);
expect(result.teachers.length).toBeGreaterThan(0);
});
it('Deleting non-existent teacher', async () => {
@ -156,27 +152,6 @@ describe('Teacher controllers', () => {
expect(result.students.length).toBeGreaterThan(0);
});
/*
It('Get teacher questions', async () => {
req = {
params: { username: 'FooFighters' },
query: { full: 'true' },
};
await getTeacherQuestionHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ questions: expect.anything() }));
const result = jsonMock.mock.lastCall?.[0];
// console.log('[TEACHER QUESTIONS]', result.questions);
expect(result.questions.length).toBeGreaterThan(0);
// TODO fix
});
*/
it('Get join requests by class', async () => {
const jr = getClassJoinRequest01();
req = {

View file

@ -2,7 +2,7 @@ import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests';
import { AssignmentRepository } from '../../../src/data/assignments/assignment-repository';
import { getAssignmentRepository } from '../../../src/data/repositories';
import { getClass01, getClass02 } from '../../test_assets/classes/classes.testdata';
import { getClass02 } from '../../test_assets/classes/classes.testdata';
import { getAssignment02, getAssignment03 } from '../../test_assets/assignments/assignments.testdata';
import { getTestleerkracht1 } from '../../test_assets/users/teachers.testdata';
@ -17,7 +17,7 @@ describe('AssignmentRepository', () => {
it('should return the requested assignment', async () => {
const class_ = getClass02();
const usedAssignment = getAssignment02();
const assignment = await assignmentRepository.findByClassAndId(class_!, 21001);
const assignment = await assignmentRepository.findByClassAndId(class_, 21001);
expect(assignment).toBeTruthy();
expect(assignment!.description).toBe(usedAssignment.description);
@ -30,7 +30,7 @@ describe('AssignmentRepository', () => {
it('should return all assignments for a class', async () => {
const class_ = getClass02();
const usedAssignment = getAssignment02();
const assignments = await assignmentRepository.findAllAssignmentsInClass(class_!);
const assignments = await assignmentRepository.findAllAssignmentsInClass(class_);
expect(assignments).toBeTruthy();
expect(assignments).toHaveLength(1);

View file

@ -1,8 +1,7 @@
import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests';
import { GroupRepository } from '../../../src/data/assignments/group-repository';
import { getAssignmentRepository, getClassRepository, getGroupRepository } from '../../../src/data/repositories';
import { getClass01 } from '../../test_assets/classes/classes.testdata';
import { getGroupRepository } from '../../../src/data/repositories';
import { getAssignment01, getAssignment02 } from '../../test_assets/assignments/assignments.testdata';
import { getTestGroup01, getTestGroup02, getTestGroup03 } from '../../test_assets/assignments/groups.testdata';
import { getDireStraits, getNoordkaap } from '../../test_assets/users/students.testdata';
@ -21,7 +20,7 @@ describe('GroupRepository', () => {
const member1 = getNoordkaap();
const member2 = getDireStraits();
const group = await groupRepository.findByAssignmentAndGroupNumber(assignment!, usedGroup.groupNumber!);
const group = await groupRepository.findByAssignmentAndGroupNumber(assignment, usedGroup.groupNumber!);
expect(group).toBeTruthy();
expect(group?.groupNumber).toBe(usedGroup.groupNumber);
@ -36,7 +35,7 @@ describe('GroupRepository', () => {
const gr2 = getTestGroup02();
const gr3 = getTestGroup03();
const groups = await groupRepository.findAllGroupsForAssignment(assignment!);
const groups = await groupRepository.findAllGroupsForAssignment(assignment);
expect(groups).toBeTruthy();
expect(groups).toHaveLength(3);
@ -49,9 +48,9 @@ describe('GroupRepository', () => {
const assignment = getAssignment02();
const deleted = getTestGroup01();
await groupRepository.deleteByAssignmentAndGroupNumber(assignment!, deleted.groupNumber!);
await groupRepository.deleteByAssignmentAndGroupNumber(assignment, deleted.groupNumber!);
const group = await groupRepository.findByAssignmentAndGroupNumber(assignment!, deleted.groupNumber!);
const group = await groupRepository.findByAssignmentAndGroupNumber(assignment, deleted.groupNumber!);
expect(group).toBeNull();
});

View file

@ -1,21 +1,11 @@
import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests';
import { SubmissionRepository } from '../../../src/data/assignments/submission-repository';
import {
getAssignmentRepository,
getClassRepository,
getGroupRepository,
getStudentRepository,
getSubmissionRepository,
} from '../../../src/data/repositories';
import { getSubmissionRepository } from '../../../src/data/repositories';
import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier';
import { Language } from '@dwengo-1/common/util/language';
import { Submission } from '../../../src/entities/assignments/submission.entity';
import { Class } from '../../../src/entities/classes/class.entity';
import { Assignment } from '../../../src/entities/assignments/assignment.entity';
import { testLearningObject01, testLearningObject03 } from '../../test_assets/content/learning-objects.testdata';
import { testLearningObject01 } from '../../test_assets/content/learning-objects.testdata';
import { getSubmission01, getSubmission02, getSubmission07, getSubmission08 } from '../../test_assets/assignments/submission.testdata';
import { use } from 'marked';
import { getAssignment01 } from '../../test_assets/assignments/assignments.testdata';
import { getTestGroup02 } from '../../test_assets/assignments/groups.testdata';
@ -29,7 +19,11 @@ describe('SubmissionRepository', () => {
it('should find the requested submission', async () => {
const usedSubmission = getSubmission01();
const id = new LearningObjectIdentifier(usedSubmission.learningObjectHruid, usedSubmission.learningObjectLanguage, usedSubmission.learningObjectVersion);
const id = new LearningObjectIdentifier(
usedSubmission.learningObjectHruid,
usedSubmission.learningObjectLanguage,
usedSubmission.learningObjectVersion
);
const submission = await submissionRepository.findSubmissionByLearningObjectAndSubmissionNumber(id, usedSubmission.submissionNumber!);
expect(submission).toBeTruthy();
@ -40,9 +34,13 @@ describe('SubmissionRepository', () => {
it('should find the most recent submission for a student', async () => {
const usedSubmission = getSubmission02();
const id = new LearningObjectIdentifier(usedSubmission.learningObjectHruid, usedSubmission.learningObjectLanguage, usedSubmission.learningObjectVersion);
const submission = await submissionRepository.findMostRecentSubmissionForStudent(id, usedSubmission.submitter!);
const id = new LearningObjectIdentifier(
usedSubmission.learningObjectHruid,
usedSubmission.learningObjectLanguage,
usedSubmission.learningObjectVersion
);
const submission = await submissionRepository.findMostRecentSubmissionForStudent(id, usedSubmission.submitter);
expect(submission).toBeTruthy();
expect(submission?.submissionTime).toStrictEqual(usedSubmission.submissionTime);
@ -50,8 +48,12 @@ describe('SubmissionRepository', () => {
it('should find the most recent submission for a group', async () => {
const usedSubmission = getSubmission02();
const id = new LearningObjectIdentifier(usedSubmission.learningObjectHruid, usedSubmission.learningObjectLanguage, usedSubmission.learningObjectVersion);
const id = new LearningObjectIdentifier(
usedSubmission.learningObjectHruid,
usedSubmission.learningObjectLanguage,
usedSubmission.learningObjectVersion
);
const submission = await submissionRepository.findMostRecentSubmissionForGroup(id, usedSubmission.onBehalfOf);
expect(submission).toBeTruthy();
@ -61,13 +63,13 @@ describe('SubmissionRepository', () => {
it('should find all submissions for a certain learning object and assignment', async () => {
const usedSubmission = getSubmission08();
const assignment = getAssignment01();
const loId = {
hruid: usedSubmission.learningObjectHruid,
language: usedSubmission.learningObjectLanguage,
version: usedSubmission.learningObjectVersion,
};
const result = await submissionRepository.findAllSubmissionsForLearningObjectAndAssignment(loId, assignment!);
const result = await submissionRepository.findAllSubmissionsForLearningObjectAndAssignment(loId, assignment);
sortSubmissions(result);
expect(result).toHaveLength(3);
@ -94,7 +96,7 @@ describe('SubmissionRepository', () => {
version: usedSubmission.learningObjectVersion,
};
const result = await submissionRepository.findAllSubmissionsForLearningObjectAndGroup(loId, group!);
const result = await submissionRepository.findAllSubmissionsForLearningObjectAndGroup(loId, group);
expect(result).toHaveLength(1);

View file

@ -1,7 +1,7 @@
import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests';
import { ClassJoinRequestRepository } from '../../../src/data/classes/class-join-request-repository';
import { getClassJoinRequestRepository, getClassRepository, getStudentRepository } from '../../../src/data/repositories';
import { getClassJoinRequestRepository } from '../../../src/data/repositories';
import { getPinkFloyd, getSmashingPumpkins } from '../../test_assets/users/students.testdata';
import { getClass02, getClass03 } from '../../test_assets/classes/classes.testdata';
import { getClassJoinRequest01, getClassJoinRequest02, getClassJoinRequest03 } from '../../test_assets/classes/class-join-requests.testdata';
@ -30,7 +30,7 @@ describe('ClassJoinRequestRepository', () => {
const class_ = getClass02();
const jr1 = getClassJoinRequest01();
const jr2 = getClassJoinRequest02();
const requests = await classJoinRequestRepository.findAllOpenRequestsTo(class_!);
const requests = await classJoinRequestRepository.findAllOpenRequestsTo(class_);
expect(requests).toBeTruthy();
expect(requests).toHaveLength(2);
@ -41,9 +41,9 @@ describe('ClassJoinRequestRepository', () => {
it('should not find a removed request', async () => {
const studentUsed = getSmashingPumpkins();
const class_ = getClass03();
await classJoinRequestRepository.deleteBy(studentUsed!, class_!);
await classJoinRequestRepository.deleteBy(studentUsed, class_);
const request = await classJoinRequestRepository.findAllRequestsBy(studentUsed!);
const request = await classJoinRequestRepository.findAllRequestsBy(studentUsed);
expect(request).toHaveLength(0);
});

View file

@ -3,6 +3,7 @@ import { ClassRepository } from '../../../src/data/classes/class-repository';
import { setupTestApp } from '../../setup-tests';
import { getClassRepository } from '../../../src/data/repositories';
import { getClass01, getClass04 } from '../../test_assets/classes/classes.testdata';
import { getClass01, getClass04 } from '../../test_assets/classes/classes.testdata';
describe('ClassRepository', () => {
let classRepository: ClassRepository;

View file

@ -1,6 +1,6 @@
import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests';
import { getTeacherInvitationRepository, getTeacherRepository } from '../../../src/data/repositories';
import { getTeacherInvitationRepository } from '../../../src/data/repositories';
import { TeacherInvitationRepository } from '../../../src/data/classes/teacher-invitation-repository';
import { getFooFighters, getLimpBizkit } from '../../test_assets/users/teachers.testdata';
import { getTeacherInvitation01, getTeacherInvitation02, getTeacherInvitation03 } from '../../test_assets/classes/teacher-invitations.testdata';
@ -18,7 +18,7 @@ describe('ClassRepository', () => {
const teacher = getLimpBizkit();
const ti1 = getTeacherInvitation01();
const ti2 = getTeacherInvitation02();
const invitations = await teacherInvitationRepository.findAllInvitationsBy(teacher!);
const invitations = await teacherInvitationRepository.findAllInvitationsBy(teacher);
expect(invitations).toBeTruthy();
expect(invitations).toHaveLength(2);
@ -30,7 +30,7 @@ describe('ClassRepository', () => {
const teacher = getFooFighters();
const ti1 = getTeacherInvitation01();
const ti2 = getTeacherInvitation03();
const invitations = await teacherInvitationRepository.findAllInvitationsFor(teacher!);
const invitations = await teacherInvitationRepository.findAllInvitationsFor(teacher);
expect(invitations).toBeTruthy();
expect(invitations).toHaveLength(2);
@ -42,22 +42,21 @@ describe('ClassRepository', () => {
const class_ = getClass02();
const ti1 = getTeacherInvitation01();
const ti2 = getTeacherInvitation02();
const invitations = await teacherInvitationRepository.findAllInvitationsForClass(class_!);
const invitations = await teacherInvitationRepository.findAllInvitationsForClass(class_);
expect(invitations).toBeTruthy();
expect(invitations).toHaveLength(2);
expect(invitations[0].class.classId).toBeOneOf([ti1.class.classId, ti2.class.classId]);
expect(invitations[1].class.classId).toBeOneOf([ti1.class.classId, ti2.class.classId]);
});
it('should not find a removed invitation', async () => {
const class_ = getClass01();
const sender = getFooFighters();
const receiver = getLimpBizkit();
await teacherInvitationRepository.deleteBy(class_!, sender!, receiver!);
await teacherInvitationRepository.deleteBy(class_, sender, receiver);
const invitation = await teacherInvitationRepository.findAllInvitationsBy(sender!);
const invitation = await teacherInvitationRepository.findAllInvitationsBy(sender);
expect(invitation).toHaveLength(0);
});

View file

@ -2,7 +2,6 @@ import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests.js';
import { getAttachmentRepository } from '../../../src/data/repositories.js';
import { AttachmentRepository } from '../../../src/data/content/attachment-repository.js';
import { testLearningObject02 } from '../../test_assets/content/learning-objects.testdata';
import { getAttachment01 } from '../../test_assets/content/attachments.testdata.js';
describe('AttachmentRepository', () => {

View file

@ -6,7 +6,6 @@ import { LearningObject } from '../../../src/entities/content/learning-object.en
import { expectToBeCorrectEntity } from '../../test-utils/expectations.js';
import { testLearningObject01, testLearningObject02, testLearningObject03 } from '../../test_assets/content/learning-objects.testdata';
import { v4 } from 'uuid';
import { wrap } from '@mikro-orm/core';
describe('LearningObjectRepository', () => {
let learningObjectRepository: LearningObjectRepository;
@ -38,7 +37,7 @@ describe('LearningObjectRepository', () => {
let newerExample: LearningObject;
it('should allow a learning object with the same id except a different version to be added', async () => {
// structeredClone failed on teacher, this copies all fields to a json object
// StructeredClone failed on teacher, this copies all fields to a json object
const testLearningObject01Newer = { ...testLearningObject01 };
testLearningObject01Newer.version = 10;
testLearningObject01Newer.title += ' (nieuw)';
@ -49,12 +48,10 @@ describe('LearningObjectRepository', () => {
});
it('should return the newest version of the learning object when queried by only hruid and language', async () => {
const result = await learningObjectRepository.findLatestByHruidAndLanguage(newerExample.hruid, newerExample.language);
// expect(result).toBeInstanceOf(LearningObject);
// expect(result?.version).toBe(10);
// expect(result?.title).toContain('(nieuw)');
expect(result).toBeInstanceOf(LearningObject);
expect(result?.version).toBe(10);
expect(result?.title).toContain('(nieuw)');
});
it('should return null when queried by non-existing hruid or language', async () => {

View file

@ -1,15 +1,10 @@
import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests';
import { AnswerRepository } from '../../../src/data/questions/answer-repository';
import { getAnswerRepository, getQuestionRepository, getTeacherRepository } from '../../../src/data/repositories';
import { QuestionRepository } from '../../../src/data/questions/question-repository';
import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier';
import { Language } from '@dwengo-1/common/util/language';
import { TeacherRepository } from '../../../src/data/users/teacher-repository';
import { getQuestion01, getQuestion02, getQuestion04, getQuestion05, getQuestion06 } from '../../test_assets/questions/questions.testdata';
import { getAnswerRepository } from '../../../src/data/repositories';
import { getQuestion01, getQuestion02 } from '../../test_assets/questions/questions.testdata';
import { getAnswer01, getAnswer02, getAnswer03 } from '../../test_assets/questions/answers.testdata';
import { getFooFighters } from '../../test_assets/users/teachers.testdata';
import { testLearningObject05 } from '../../test_assets/content/learning-objects.testdata';
describe('AnswerRepository', () => {
let answerRepository: AnswerRepository;
@ -24,7 +19,7 @@ describe('AnswerRepository', () => {
const a1 = getAnswer01();
const a2 = getAnswer02();
const answers = await answerRepository.findAllAnswersToQuestion(question!);
const answers = await answerRepository.findAllAnswersToQuestion(question);
expect(answers).toBeTruthy();
expect(answers).toHaveLength(2);
@ -38,7 +33,7 @@ describe('AnswerRepository', () => {
await answerRepository.createAnswer({
toQuestion: question,
author: teacher!,
author: teacher,
content: 'created answer',
});

View file

@ -48,8 +48,8 @@ describe('QuestionRepository', () => {
const group = getTestGroup01();
await questionRepository.createQuestion({
loId: id,
inGroup: group!,
author: student!,
inGroup: group,
author: student,
content: 'question?',
});
const question = await questionRepository.findAllQuestionsAboutLearningObject(id);
@ -66,7 +66,7 @@ describe('QuestionRepository', () => {
language: testLearningObject05.language,
version: testLearningObject05.version,
};
const result = await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!);
const result = await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment);
sortQuestions(result);
expect(result).toHaveLength(3);
@ -94,7 +94,7 @@ describe('QuestionRepository', () => {
};
const assignment = getAssignment01();
const result = await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!, getTool().username);
const result = await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment, getTool().username);
// (student Tool is in group #2)
expect(result).toHaveLength(1);

View file

@ -2,7 +2,6 @@ import { setupTestApp } from '../../setup-tests.js';
import { describe, it, expect, beforeAll } from 'vitest';
import { StudentRepository } from '../../../src/data/users/student-repository.js';
import { getStudentRepository } from '../../../src/data/repositories.js';
import { getNameOfJSDocTypedef } from 'typescript';
import { getNoordkaap } from '../../test_assets/users/students.testdata.js';
const username = 'teststudent';

View file

@ -5,6 +5,12 @@ import { testLearningPath01, testLearningPath02, testLearningPathWithConditions
import { getClass01, getClass02, getClassWithTestleerlingAndTestleerkracht } from '../classes/classes.testdata';
export function makeTestAssignemnts(em: EntityManager): Assignment[] {
const futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 7);
const pastDate = new Date();
pastDate.setDate(pastDate.getDate() - 7);
const today = new Date();
today.setHours(23, 59);
assignment01 = em.create(Assignment, {
id: 21000,
within: getClass01(),
@ -12,6 +18,7 @@ export function makeTestAssignemnts(em: EntityManager): Assignment[] {
description: 'reading',
learningPathHruid: testLearningPath02.hruid,
learningPathLanguage: testLearningPath02.language as Language,
deadline: today,
groups: [],
});
@ -22,6 +29,7 @@ export function makeTestAssignemnts(em: EntityManager): Assignment[] {
description: 'reading',
learningPathHruid: testLearningPath01.hruid,
learningPathLanguage: testLearningPath01.language as Language,
deadline: futureDate,
groups: [],
});
@ -32,6 +40,7 @@ export function makeTestAssignemnts(em: EntityManager): Assignment[] {
description: 'will be deleted',
learningPathHruid: testLearningPath02.hruid,
learningPathLanguage: testLearningPath02.language as Language,
deadline: pastDate,
groups: [],
});
@ -42,6 +51,7 @@ export function makeTestAssignemnts(em: EntityManager): Assignment[] {
description: 'with a description',
learningPathHruid: testLearningPath01.hruid,
learningPathLanguage: testLearningPath01.language as Language,
deadline: pastDate,
groups: [],
});
@ -52,6 +62,7 @@ export function makeTestAssignemnts(em: EntityManager): Assignment[] {
description: 'You have to do the testing learning path with a condition.',
learningPathHruid: testLearningPathWithConditions.hruid,
learningPathLanguage: testLearningPathWithConditions.language as Language,
deadline: futureDate,
groups: [],
});

View file

@ -8,7 +8,7 @@ export function makeTestGroups(em: EntityManager): Group[] {
* Group #1 for Assignment #1 in class 'id01'
* => Assigned to do learning path 'id02'
*/
// gets deleted
// Gets deleted
group01 = em.create(Group, {
assignment: getAssignment01(),
groupNumber: 21001,

View file

@ -71,7 +71,7 @@ export function makeTestSubmissions(em: EntityManager): Submission[] {
content: '',
});
// gets deleted
// Gets deleted
submission07 = em.create(Submission, {
learningObjectHruid: testLearningObject01.hruid,
learningObjectLanguage: testLearningObject01.language,
@ -106,34 +106,34 @@ let submission06: Submission;
let submission07: Submission;
let submission08: Submission;
export function getSubmission01(): Submission{
export function getSubmission01(): Submission {
return submission01;
}
export function getSubmission02(): Submission{
export function getSubmission02(): Submission {
return submission02;
}
export function getSubmission03(): Submission{
export function getSubmission03(): Submission {
return submission03;
}
export function getSubmission04(): Submission{
export function getSubmission04(): Submission {
return submission04;
}
export function getSubmission05(): Submission{
export function getSubmission05(): Submission {
return submission05;
}
export function getSubmission06(): Submission{
export function getSubmission06(): Submission {
return submission06;
}
export function getSubmission07(): Submission{
export function getSubmission07(): Submission {
return submission07;
}
export function getSubmission08(): Submission{
export function getSubmission08(): Submission {
return submission08;
}
}

View file

@ -37,18 +37,18 @@ let classJoinRequest02: ClassJoinRequest;
let classJoinRequest03: ClassJoinRequest;
let classJoinRequest04: ClassJoinRequest;
export function getClassJoinRequest01(): ClassJoinRequest{
export function getClassJoinRequest01(): ClassJoinRequest {
return classJoinRequest01;
}
export function getClassJoinRequest02(): ClassJoinRequest{
export function getClassJoinRequest02(): ClassJoinRequest {
return classJoinRequest02;
}
export function getClassJoinRequest03(): ClassJoinRequest{
export function getClassJoinRequest03(): ClassJoinRequest {
return classJoinRequest03;
}
export function getClassJoinRequest04(): ClassJoinRequest{
export function getClassJoinRequest04(): ClassJoinRequest {
return classJoinRequest04;
}
}

View file

@ -10,7 +10,7 @@ export function makeTestClasses(em: EntityManager): Class[] {
const teacherClass01: Teacher[] = [getTestleerkracht1()];
class01 = em.create(Class, {
classId: '8764b861-90a6-42e5-9732-c0d9eb2f55f9',
classId: 'X2J9QT', // 8764b861-90a6-42e5-9732-c0d9eb2f55f9
displayName: 'class01',
teachers: teacherClass01,
students: studentsClass01,
@ -20,7 +20,7 @@ export function makeTestClasses(em: EntityManager): Class[] {
const teacherClass02: Teacher[] = [getLimpBizkit()];
class02 = em.create(Class, {
classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89',
classId: '7KLPMA', // 34d484a1-295f-4e9f-bfdc-3e7a23d86a89
displayName: 'class02',
teachers: teacherClass02,
students: studentsClass02,
@ -30,7 +30,7 @@ export function makeTestClasses(em: EntityManager): Class[] {
const teacherClass03: Teacher[] = [getStaind()];
class03 = em.create(Class, {
classId: '80dcc3e0-1811-4091-9361-42c0eee91cfa',
classId: 'R0D3UZ', // 80dcc3e0-1811-4091-9361-42c0eee91cfa
displayName: 'class03',
teachers: teacherClass03,
students: studentsClass03,
@ -39,16 +39,16 @@ export function makeTestClasses(em: EntityManager): Class[] {
const studentsClass04: Student[] = [getNoordkaap(), getDireStraits()];
const teacherClass04: Teacher[] = [getStaind()];
// gets deleted in test
// Gets deleted in test
class04 = em.create(Class, {
classId: '33d03536-83b8-4880-9982-9bbf2f908ddf',
classId: 'Q8N5YC', // 33d03536-83b8-4880-9982-9bbf2f908ddf
displayName: 'class04',
teachers: teacherClass04,
students: studentsClass04,
});
classWithTestleerlingAndTestleerkracht = em.create(Class, {
classId: 'a75298b5-18aa-471d-8eeb-5d77eb989393',
classId: 'ZAV71B', // Was a75298b5-18aa-471d-8eeb-5d77eb989393
displayName: 'Testklasse',
teachers: [getTestleerkracht1()],
students: [getTestleerling1()],

View file

@ -26,7 +26,7 @@ export function makeTestTeacherInvitations(em: EntityManager): TeacherInvitation
status: ClassStatus.Open,
});
// gets deleted in test
// Gets deleted in test
teacherInvitation04 = em.create(TeacherInvitation, {
sender: getFooFighters(),
receiver: getLimpBizkit(),
@ -56,4 +56,4 @@ export function getTeacherInvitation03(): TeacherInvitation {
export function getTeacherInvitation04(): TeacherInvitation {
return teacherInvitation04;
}
}

View file

@ -4,7 +4,7 @@ import { testLearningObject01 } from './learning-objects.testdata';
import { LearningObject } from '../../../src/entities/content/learning-object.entity';
export function makeTestAttachments(em: EntityManager): Attachment[] {
// prevent duplicate insertion
// Prevent duplicate insertion
const lo = em.merge(LearningObject, testLearningObject01);
attachment01 = em.create(Attachment, {
@ -19,6 +19,6 @@ export function makeTestAttachments(em: EntityManager): Attachment[] {
let attachment01: Attachment;
export function getAttachment01(): Attachment{
export function getAttachment01(): Attachment {
return attachment01;
}

View file

@ -20,7 +20,7 @@ export function makeTestAnswers(em: EntityManager): Answer[] {
content: 'answer2',
});
// gets deleted
// Gets deleted
answer03 = em.create(Answer, {
author: getLimpBizkit(),
toQuestion: getQuestion04(),
@ -72,4 +72,4 @@ export function getAnswer04(): Answer {
export function getAnswer05(): Answer {
return answer05;
}
}

View file

@ -1,7 +1,12 @@
import { EntityManager } from '@mikro-orm/core';
import { Question } from '../../../src/entities/questions/question.entity';
import { getDireStraits, getNoordkaap, getTestleerling1, getTool } from '../users/students.testdata';
import { testLearningObject01, testLearningObject04, testLearningObject05, testLearningObjectMultipleChoice } from '../content/learning-objects.testdata';
import {
testLearningObject01,
testLearningObject04,
testLearningObject05,
testLearningObjectMultipleChoice,
} from '../content/learning-objects.testdata';
import { getGroup1ConditionalLearningPath, getTestGroup01, getTestGroup02 } from '../assignments/groups.testdata';
export function makeTestQuestions(em: EntityManager): Question[] {
@ -27,7 +32,7 @@ export function makeTestQuestions(em: EntityManager): Question[] {
content: 'question',
});
//gets deleted
//Gets deleted
question03 = em.create(Question, {
learningObjectLanguage: testLearningObject04.language,
learningObjectVersion: testLearningObject04.version,
@ -130,7 +135,6 @@ export function getQuestion06(): Question {
return question06;
}
export function getQuestion07(): Question {
return question07;
}