fix(backend): Fouten in de testen resulterend uit de aanpassingen opgelost.

This commit is contained in:
Gerald Schmittinger 2025-04-07 15:59:07 +02:00
parent 7b79348985
commit 03fa7c7b14
4 changed files with 80 additions and 13 deletions

View file

@ -42,11 +42,21 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
}
public async findAllSubmissionsForGroup(group: Group): Promise<Submission[]> {
return this.find({ onBehalfOf: group });
return this.find(
{ onBehalfOf: group },
{
populate: ["onBehalfOf.members"]
}
);
}
public async findAllSubmissionsForStudent(student: Student): Promise<Submission[]> {
return this.find({ submitter: student });
return this.find(
{ submitter: student },
{
populate: ["onBehalfOf.members"]
}
);
}
public async deleteSubmissionByLearningObjectAndSubmissionNumber(loId: LearningObjectIdentifier, submissionNumber: number): Promise<void> {

View file

@ -1,4 +1,4 @@
import { Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
import {Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property} from '@mikro-orm/core';
import { Class } from '../classes/class.entity.js';
import { Group } from './group.entity.js';
import { Language } from '@dwengo-1/common/util/language';
@ -35,5 +35,5 @@ export class Assignment {
entity: () => Group,
mappedBy: 'assignment',
})
groups!: Group[];
groups!: Collection<Group>;
}

View file

@ -1,7 +1,12 @@
import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests';
import { QuestionRepository } from '../../../src/data/questions/question-repository';
import { getQuestionRepository, getStudentRepository } from '../../../src/data/repositories';
import {
getAssignmentRepository, getClassRepository,
getGroupRepository,
getQuestionRepository,
getStudentRepository
} from '../../../src/data/repositories';
import { StudentRepository } from '../../../src/data/users/student-repository';
import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier';
import { Language } from '@dwengo-1/common/util/language';
@ -27,8 +32,13 @@ describe('QuestionRepository', () => {
it('should create new question', async () => {
const id = new LearningObjectIdentifier('id03', Language.English, 1);
const student = await studentRepository.findByUsername('Noordkaap');
const clazz = await getClassRepository().findById("id01");
const assignment = await getAssignmentRepository().findByClassAndId(clazz!, 1);
const group = await getGroupRepository().findByAssignmentAndGroupNumber(assignment!, 1);
await questionRepository.createQuestion({
loId: id,
inGroup: group!,
author: student!,
content: 'question?',
});

View file

@ -3,6 +3,9 @@ import { LearningObject } from '../../../src/entities/content/learning-object.en
import { setupTestApp } from '../../setup-tests.js';
import { LearningPath } from '../../../src/entities/content/learning-path.entity.js';
import {
getAssignmentRepository,
getClassRepository,
getGroupRepository,
getLearningObjectRepository,
getLearningPathRepository,
getStudentRepository,
@ -22,6 +25,10 @@ import { Student } from '../../../src/entities/users/student.entity.js';
import { LearningObjectNode, LearningPathResponse } from '@dwengo-1/common/interfaces/learning-content';
const STUDENT_A_USERNAME = "student_a";
const STUDENT_B_USERNAME = "student_b";
const CLASS_NAME = "test_class"
async function initExampleData(): Promise<{ learningObject: LearningObject; learningPath: LearningPath }> {
const learningObjectRepo = getLearningObjectRepository();
const learningPathRepo = getLearningPathRepository();
@ -37,7 +44,10 @@ async function initPersonalizationTestData(): Promise<{
studentA: Student;
studentB: Student;
}> {
const studentRepo = getStudentRepository();
const studentRepo = getStudentRepository()
const classRepo = getClassRepository();
const assignmentRepo = getAssignmentRepository();
const groupRepo = getGroupRepository();
const submissionRepo = getSubmissionRepository();
const learningPathRepo = getLearningPathRepository();
const learningObjectRepo = getLearningObjectRepository();
@ -47,32 +57,69 @@ async function initPersonalizationTestData(): Promise<{
await learningObjectRepo.save(learningContent.extraExerciseObject);
await learningPathRepo.save(learningContent.learningPath);
// Create students
const studentA = studentRepo.create({
username: 'student_a',
username: STUDENT_A_USERNAME,
firstName: 'Aron',
lastName: 'Student',
});
await studentRepo.save(studentA);
const studentB = studentRepo.create({
username: STUDENT_B_USERNAME,
firstName: 'Bill',
lastName: 'Student',
});
await studentRepo.save(studentB);
// Create class for students
const testClass = classRepo.create({
classId: CLASS_NAME,
displayName: "Test class"
});
await classRepo.save(testClass);
// Create assignment for students and assign them to different groups
const assignment = assignmentRepo.create({
id: 0,
title: "Test assignment",
description: "Test description",
learningPathHruid: learningContent.learningPath.hruid,
learningPathLanguage: learningContent.learningPath.language,
within: testClass
})
const groupA = groupRepo.create({
groupNumber: 0,
members: [studentA],
assignment
});
await groupRepo.save(groupA);
const groupB = groupRepo.create({
groupNumber: 1,
members: [studentB],
assignment
});
await groupRepo.save(groupB);
// Let each of the students make a submission in his own group.
const submissionA = submissionRepo.create({
learningObjectHruid: learningContent.branchingObject.hruid,
learningObjectLanguage: learningContent.branchingObject.language,
learningObjectVersion: learningContent.branchingObject.version,
onBehalfOf: groupA,
submitter: studentA,
submissionTime: new Date(),
content: '[0]',
});
await submissionRepo.save(submissionA);
const studentB = studentRepo.create({
username: 'student_b',
firstName: 'Bill',
lastName: 'Student',
});
await studentRepo.save(studentB);
const submissionB = submissionRepo.create({
learningObjectHruid: learningContent.branchingObject.hruid,
learningObjectLanguage: learningContent.branchingObject.language,
learningObjectVersion: learningContent.branchingObject.version,
onBehalfOf: groupA,
submitter: studentB,
submissionTime: new Date(),
content: '[1]',