test: assignments data

This commit is contained in:
laurejablonski 2025-04-27 11:42:25 +02:00
parent a452b9fc4f
commit 1f5fce3529

View file

@ -1,48 +1,60 @@
import { beforeAll, describe, expect, it } from 'vitest'; import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests'; import { setupTestApp } from '../../setup-tests';
import { AssignmentRepository } from '../../../src/data/assignments/assignment-repository'; import { AssignmentRepository } from '../../../src/data/assignments/assignment-repository';
import { getAssignmentRepository, getClassRepository } from '../../../src/data/repositories'; import { getAssignmentRepository } from '../../../src/data/repositories';
import { ClassRepository } from '../../../src/data/classes/class-repository'; import { getClass01, getClass02 } from '../../test_assets/classes/classes.testdata';
import { getAssignment02, getAssignment03 } from '../../test_assets/assignments/assignments.testdata';
import { getTestleerkracht1 } from '../../test_assets/users/teachers.testdata';
describe('AssignmentRepository', () => { describe('AssignmentRepository', () => {
let assignmentRepository: AssignmentRepository; let assignmentRepository: AssignmentRepository;
let classRepository: ClassRepository;
beforeAll(async () => { beforeAll(async () => {
await setupTestApp(); await setupTestApp();
assignmentRepository = getAssignmentRepository(); assignmentRepository = getAssignmentRepository();
classRepository = getClassRepository();
}); });
it('should return the requested assignment', async () => { it('should return the requested assignment', async () => {
const class_ = await classRepository.findById('34d484a1-295f-4e9f-bfdc-3e7a23d86a89'); 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).toBeTruthy();
expect(assignment!.title).toBe('tool'); expect(assignment!.description).toBe(usedAssignment.description);
expect(assignment!.id).toBe(usedAssignment.id);
expect(assignment!.learningPathHruid).toBe(usedAssignment.learningPathHruid);
expect(assignment!.within.classId).toBe(usedAssignment.within.classId);
expect(assignment!.title).toBe(usedAssignment.title);
}); });
it('should return all assignments for a class', async () => { it('should return all assignments for a class', async () => {
const class_ = await classRepository.findById('34d484a1-295f-4e9f-bfdc-3e7a23d86a89'); const class_ = getClass02();
const usedAssignment = getAssignment02();
const assignments = await assignmentRepository.findAllAssignmentsInClass(class_!); const assignments = await assignmentRepository.findAllAssignmentsInClass(class_!);
expect(assignments).toBeTruthy(); expect(assignments).toBeTruthy();
expect(assignments).toHaveLength(1); expect(assignments).toHaveLength(1);
expect(assignments[0].title).toBe('tool'); const assignment = assignments[0];
expect(assignment.description).toBe(usedAssignment.description);
expect(assignment.id).toBe(usedAssignment.id);
expect(assignment.learningPathHruid).toBe(usedAssignment.learningPathHruid);
expect(assignment.within.classId).toBe(usedAssignment.within.classId);
expect(assignment.title).toBe(usedAssignment.title);
}); });
it('should find all by username of the responsible teacher', async () => { it('should find all by username of the responsible teacher', async () => {
const result = await assignmentRepository.findAllByResponsibleTeacher('testleerkracht1'); const teacher = getTestleerkracht1();
const result = await assignmentRepository.findAllByResponsibleTeacher(teacher.username);
const resultIds = result.map((it) => it.id).sort((a, b) => (a ?? 0) - (b ?? 0)); const resultIds = result.map((it) => it.id).sort((a, b) => (a ?? 0) - (b ?? 0));
expect(resultIds).toEqual([21000, 21002, 21003, 21004]); expect(resultIds).toEqual([21000, 21002, 21003, 21004]);
}); });
it('should not find removed assignment', async () => { it('should not find removed assignment', async () => {
const class_ = await classRepository.findById('id01'); const deleted = getAssignment03();
await assignmentRepository.deleteByClassAndId(class_!, 3); await assignmentRepository.deleteByClassAndId(deleted.within, deleted.id!);
const assignment = await assignmentRepository.findByClassAndId(class_!, 3); const assignment = await assignmentRepository.findByClassAndId(deleted.within, deleted.id!);
expect(assignment).toBeNull(); expect(assignment).toBeNull();
}); });