feat(backend): Testen voor nieuwe functie in QuestionRepository toegevoegd.
This commit is contained in:
parent
c863dc627f
commit
d21377cda4
2 changed files with 86 additions and 6 deletions
|
@ -10,6 +10,9 @@ import {
|
|||
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';
|
||||
import {Question} from "../../../src/entities/questions/question.entity";
|
||||
import {Class} from "../../../src/entities/classes/class.entity";
|
||||
import {Assignment} from "../../../src/entities/assignments/assignment.entity";
|
||||
|
||||
describe('QuestionRepository', () => {
|
||||
let questionRepository: QuestionRepository;
|
||||
|
@ -26,7 +29,7 @@ describe('QuestionRepository', () => {
|
|||
const questions = await questionRepository.findAllQuestionsAboutLearningObject(id);
|
||||
|
||||
expect(questions).toBeTruthy();
|
||||
expect(questions).toHaveLength(2);
|
||||
expect(questions).toHaveLength(4);
|
||||
});
|
||||
|
||||
it('should create new question', async () => {
|
||||
|
@ -48,6 +51,53 @@ describe('QuestionRepository', () => {
|
|||
expect(question).toHaveLength(1);
|
||||
});
|
||||
|
||||
let clazz: Class | null;
|
||||
let assignment: Assignment | null;
|
||||
let loId: LearningObjectIdentifier;
|
||||
it('should find all questions for a certain learning object and assignment', async () => {
|
||||
clazz = await getClassRepository().findById('id01');
|
||||
assignment = await getAssignmentRepository().findByClassAndId(clazz!, 1);
|
||||
loId = {
|
||||
hruid: "id05",
|
||||
language: Language.English,
|
||||
version: 1
|
||||
};
|
||||
const result = await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!);
|
||||
sortQuestions(result);
|
||||
|
||||
expect(result).toHaveLength(3);
|
||||
|
||||
// question01: About learning object 'id05', in group #1 for Assignment #1 in class 'id01'
|
||||
expect(result[0].learningObjectHruid).toEqual(loId.hruid);
|
||||
expect(result[0].sequenceNumber).toEqual(1);
|
||||
|
||||
// question02: About learning object 'id05', in group #1 for Assignment #1 in class 'id01'
|
||||
expect(result[1].learningObjectHruid).toEqual(loId.hruid);
|
||||
expect(result[1].sequenceNumber).toEqual(2);
|
||||
|
||||
// question05: About learning object 'id05', in group #2 for Assignment #1 in class 'id01'
|
||||
expect(result[2].learningObjectHruid).toEqual(loId.hruid);
|
||||
expect(result[2].sequenceNumber).toEqual(3);
|
||||
|
||||
// question06: About learning object 'id05', but for Assignment #2 in class 'id01' => not expected.
|
||||
});
|
||||
|
||||
it("should find only the questions for a certain learning object and assignment asked by the user's group", async () => {
|
||||
const result =
|
||||
await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!, "Tool");
|
||||
// (student Tool is in group #2)
|
||||
|
||||
expect(result).toHaveLength(1);
|
||||
|
||||
// question01 and question02 are in group #1 => not displayed.
|
||||
|
||||
// question05: About learning object 'id05', in group #2 for Assignment #1 in class 'id01'
|
||||
expect(result[0].learningObjectHruid).toEqual(loId.hruid);
|
||||
expect(result[0].sequenceNumber).toEqual(3);
|
||||
|
||||
// question06: About learning object 'id05', but for Assignment #2 in class 'id01' => not expected.
|
||||
});
|
||||
|
||||
it('should not find removed question', async () => {
|
||||
const id = new LearningObjectIdentifier('id04', Language.English, 1);
|
||||
await questionRepository.removeQuestionByLearningObjectAndSequenceNumber(id, 1);
|
||||
|
@ -57,3 +107,11 @@ describe('QuestionRepository', () => {
|
|||
expect(question).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
function sortQuestions(questions: Question[]) {
|
||||
questions.sort((a, b) => {
|
||||
if (a.learningObjectHruid < b.learningObjectHruid) return -1
|
||||
else if (a.learningObjectHruid > b.learningObjectHruid) return 1
|
||||
else return a.sequenceNumber! - b.sequenceNumber!
|
||||
});
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ export function makeTestQuestions(em: EntityManager, students: Student[], groups
|
|||
learningObjectLanguage: Language.English,
|
||||
learningObjectVersion: 1,
|
||||
learningObjectHruid: 'id05',
|
||||
inGroup: groups[0],
|
||||
inGroup: groups[0], // Group #1 for Assignment #1 in class 'id01'
|
||||
sequenceNumber: 1,
|
||||
author: students[0],
|
||||
timestamp: new Date(),
|
||||
|
@ -20,7 +20,7 @@ export function makeTestQuestions(em: EntityManager, students: Student[], groups
|
|||
learningObjectLanguage: Language.English,
|
||||
learningObjectVersion: 1,
|
||||
learningObjectHruid: 'id05',
|
||||
inGroup: groups[0],
|
||||
inGroup: groups[0], // Group #1 for Assignment #1 in class 'id01'
|
||||
sequenceNumber: 2,
|
||||
author: students[2],
|
||||
timestamp: new Date(),
|
||||
|
@ -33,7 +33,7 @@ export function makeTestQuestions(em: EntityManager, students: Student[], groups
|
|||
learningObjectHruid: 'id04',
|
||||
sequenceNumber: 1,
|
||||
author: students[0],
|
||||
inGroup: groups[0],
|
||||
inGroup: groups[0], // Group #1 for Assignment #1 in class 'id01'
|
||||
timestamp: new Date(),
|
||||
content: 'question',
|
||||
});
|
||||
|
@ -44,10 +44,32 @@ export function makeTestQuestions(em: EntityManager, students: Student[], groups
|
|||
learningObjectHruid: 'id01',
|
||||
sequenceNumber: 1,
|
||||
author: students[1],
|
||||
inGroup: groups[1],
|
||||
inGroup: groups[1], // Group #2 for Assignment #1 in class 'id01'
|
||||
timestamp: new Date(),
|
||||
content: 'question',
|
||||
});
|
||||
|
||||
return [question01, question02, question03, question04];
|
||||
const question05 = em.create(Question, {
|
||||
learningObjectLanguage: Language.English,
|
||||
learningObjectVersion: 1,
|
||||
learningObjectHruid: 'id05',
|
||||
sequenceNumber: 3,
|
||||
author: students[1],
|
||||
inGroup: groups[1], // Group #2 for Assignment #1 in class 'id01'
|
||||
timestamp: new Date(),
|
||||
content: 'question',
|
||||
});
|
||||
|
||||
const question06 = em.create(Question, {
|
||||
learningObjectLanguage: Language.English,
|
||||
learningObjectVersion: 1,
|
||||
learningObjectHruid: 'id05',
|
||||
sequenceNumber: 4,
|
||||
author: students[2],
|
||||
inGroup: groups[3], // Group #4 for Assignment #2 in class 'id02'
|
||||
timestamp: new Date(),
|
||||
content: 'question',
|
||||
});
|
||||
|
||||
return [question01, question02, question03, question04, question05, question06];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue