fix(backend): Fouten in de testen resulterend uit de aanpassingen opgelost.
This commit is contained in:
parent
7b79348985
commit
03fa7c7b14
4 changed files with 80 additions and 13 deletions
|
@ -42,11 +42,21 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async findAllSubmissionsForGroup(group: Group): Promise<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[]> {
|
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> {
|
public async deleteSubmissionByLearningObjectAndSubmissionNumber(loId: LearningObjectIdentifier, submissionNumber: number): Promise<void> {
|
||||||
|
|
|
@ -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 { Class } from '../classes/class.entity.js';
|
||||||
import { Group } from './group.entity.js';
|
import { Group } from './group.entity.js';
|
||||||
import { Language } from '@dwengo-1/common/util/language';
|
import { Language } from '@dwengo-1/common/util/language';
|
||||||
|
@ -35,5 +35,5 @@ export class Assignment {
|
||||||
entity: () => Group,
|
entity: () => Group,
|
||||||
mappedBy: 'assignment',
|
mappedBy: 'assignment',
|
||||||
})
|
})
|
||||||
groups!: Group[];
|
groups!: Collection<Group>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
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 { QuestionRepository } from '../../../src/data/questions/question-repository';
|
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 { StudentRepository } from '../../../src/data/users/student-repository';
|
||||||
import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier';
|
import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier';
|
||||||
import { Language } from '@dwengo-1/common/util/language';
|
import { Language } from '@dwengo-1/common/util/language';
|
||||||
|
@ -27,8 +32,13 @@ describe('QuestionRepository', () => {
|
||||||
it('should create new question', async () => {
|
it('should create new question', async () => {
|
||||||
const id = new LearningObjectIdentifier('id03', Language.English, 1);
|
const id = new LearningObjectIdentifier('id03', Language.English, 1);
|
||||||
const student = await studentRepository.findByUsername('Noordkaap');
|
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({
|
await questionRepository.createQuestion({
|
||||||
loId: id,
|
loId: id,
|
||||||
|
inGroup: group!,
|
||||||
author: student!,
|
author: student!,
|
||||||
content: 'question?',
|
content: 'question?',
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,6 +3,9 @@ import { LearningObject } from '../../../src/entities/content/learning-object.en
|
||||||
import { setupTestApp } from '../../setup-tests.js';
|
import { setupTestApp } from '../../setup-tests.js';
|
||||||
import { LearningPath } from '../../../src/entities/content/learning-path.entity.js';
|
import { LearningPath } from '../../../src/entities/content/learning-path.entity.js';
|
||||||
import {
|
import {
|
||||||
|
getAssignmentRepository,
|
||||||
|
getClassRepository,
|
||||||
|
getGroupRepository,
|
||||||
getLearningObjectRepository,
|
getLearningObjectRepository,
|
||||||
getLearningPathRepository,
|
getLearningPathRepository,
|
||||||
getStudentRepository,
|
getStudentRepository,
|
||||||
|
@ -22,6 +25,10 @@ import { Student } from '../../../src/entities/users/student.entity.js';
|
||||||
|
|
||||||
import { LearningObjectNode, LearningPathResponse } from '@dwengo-1/common/interfaces/learning-content';
|
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 }> {
|
async function initExampleData(): Promise<{ learningObject: LearningObject; learningPath: LearningPath }> {
|
||||||
const learningObjectRepo = getLearningObjectRepository();
|
const learningObjectRepo = getLearningObjectRepository();
|
||||||
const learningPathRepo = getLearningPathRepository();
|
const learningPathRepo = getLearningPathRepository();
|
||||||
|
@ -37,7 +44,10 @@ async function initPersonalizationTestData(): Promise<{
|
||||||
studentA: Student;
|
studentA: Student;
|
||||||
studentB: Student;
|
studentB: Student;
|
||||||
}> {
|
}> {
|
||||||
const studentRepo = getStudentRepository();
|
const studentRepo = getStudentRepository()
|
||||||
|
const classRepo = getClassRepository();
|
||||||
|
const assignmentRepo = getAssignmentRepository();
|
||||||
|
const groupRepo = getGroupRepository();
|
||||||
const submissionRepo = getSubmissionRepository();
|
const submissionRepo = getSubmissionRepository();
|
||||||
const learningPathRepo = getLearningPathRepository();
|
const learningPathRepo = getLearningPathRepository();
|
||||||
const learningObjectRepo = getLearningObjectRepository();
|
const learningObjectRepo = getLearningObjectRepository();
|
||||||
|
@ -47,32 +57,69 @@ async function initPersonalizationTestData(): Promise<{
|
||||||
await learningObjectRepo.save(learningContent.extraExerciseObject);
|
await learningObjectRepo.save(learningContent.extraExerciseObject);
|
||||||
await learningPathRepo.save(learningContent.learningPath);
|
await learningPathRepo.save(learningContent.learningPath);
|
||||||
|
|
||||||
|
// Create students
|
||||||
const studentA = studentRepo.create({
|
const studentA = studentRepo.create({
|
||||||
username: 'student_a',
|
username: STUDENT_A_USERNAME,
|
||||||
firstName: 'Aron',
|
firstName: 'Aron',
|
||||||
lastName: 'Student',
|
lastName: 'Student',
|
||||||
});
|
});
|
||||||
await studentRepo.save(studentA);
|
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({
|
const submissionA = submissionRepo.create({
|
||||||
learningObjectHruid: learningContent.branchingObject.hruid,
|
learningObjectHruid: learningContent.branchingObject.hruid,
|
||||||
learningObjectLanguage: learningContent.branchingObject.language,
|
learningObjectLanguage: learningContent.branchingObject.language,
|
||||||
learningObjectVersion: learningContent.branchingObject.version,
|
learningObjectVersion: learningContent.branchingObject.version,
|
||||||
|
onBehalfOf: groupA,
|
||||||
submitter: studentA,
|
submitter: studentA,
|
||||||
submissionTime: new Date(),
|
submissionTime: new Date(),
|
||||||
content: '[0]',
|
content: '[0]',
|
||||||
});
|
});
|
||||||
await submissionRepo.save(submissionA);
|
await submissionRepo.save(submissionA);
|
||||||
|
|
||||||
const studentB = studentRepo.create({
|
|
||||||
username: 'student_b',
|
|
||||||
firstName: 'Bill',
|
|
||||||
lastName: 'Student',
|
|
||||||
});
|
|
||||||
await studentRepo.save(studentB);
|
|
||||||
const submissionB = submissionRepo.create({
|
const submissionB = submissionRepo.create({
|
||||||
learningObjectHruid: learningContent.branchingObject.hruid,
|
learningObjectHruid: learningContent.branchingObject.hruid,
|
||||||
learningObjectLanguage: learningContent.branchingObject.language,
|
learningObjectLanguage: learningContent.branchingObject.language,
|
||||||
learningObjectVersion: learningContent.branchingObject.version,
|
learningObjectVersion: learningContent.branchingObject.version,
|
||||||
|
onBehalfOf: groupA,
|
||||||
submitter: studentB,
|
submitter: studentB,
|
||||||
submissionTime: new Date(),
|
submissionTime: new Date(),
|
||||||
content: '[1]',
|
content: '[1]',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue