test: testen staan klaar voor questions repo, probleem met creeren, sequence nummer wordt niet meegegeven
This commit is contained in:
parent
c603bb142a
commit
b3fbcb17af
2 changed files with 103 additions and 36 deletions
63
backend/tests/data/questions.test.ts
Normal file
63
backend/tests/data/questions.test.ts
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
import { beforeAll, describe, expect, it } from 'vitest';
|
||||||
|
import { setupTestApp } from '../setup-tests';
|
||||||
|
import { QuestionRepository } from '../../src/data/questions/question-repository';
|
||||||
|
import {
|
||||||
|
getLearningObjectRepository,
|
||||||
|
getQuestionRepository,
|
||||||
|
getStudentRepository,
|
||||||
|
} from '../../src/data/repositories';
|
||||||
|
import { StudentRepository } from '../../src/data/users/student-repository';
|
||||||
|
import { LearningObjectRepository } from '../../src/data/content/learning-object-repository';
|
||||||
|
import { LearningObjectIdentifier } from '../../src/entities/content/learning-object-identifier';
|
||||||
|
import { Language } from '../../src/entities/content/language';
|
||||||
|
import { Question } from '../../src/entities/questions/question.entity';
|
||||||
|
|
||||||
|
describe('QuestionRepository', () => {
|
||||||
|
let QuestionRepository: QuestionRepository;
|
||||||
|
let StudentRepository: StudentRepository;
|
||||||
|
let LearningObjectRepository: LearningObjectRepository;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await setupTestApp();
|
||||||
|
QuestionRepository = getQuestionRepository();
|
||||||
|
StudentRepository = getStudentRepository();
|
||||||
|
LearningObjectRepository = getLearningObjectRepository();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return all questions part of the given learning object', async () => {
|
||||||
|
const id = new LearningObjectIdentifier('id05', Language.English, '1');
|
||||||
|
const questions =
|
||||||
|
await QuestionRepository.findAllQuestionsAboutLearningObject(id);
|
||||||
|
|
||||||
|
expect(questions).toBeTruthy();
|
||||||
|
expect(questions).toHaveLength(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
// it('should create new question', async () => {
|
||||||
|
// const id = new LearningObjectIdentifier('id03', Language.English, '1');
|
||||||
|
// const student = await StudentRepository.findByUsername('Noordkaap');
|
||||||
|
// await QuestionRepository.createQuestion({
|
||||||
|
// loId: id,
|
||||||
|
// author: student!,
|
||||||
|
// content: 'question?',
|
||||||
|
// });
|
||||||
|
// const question =
|
||||||
|
// await QuestionRepository.findAllQuestionsAboutLearningObject(id);
|
||||||
|
|
||||||
|
// expect(question).toBeTruthy();
|
||||||
|
// expect(question).toHaveLength(1);
|
||||||
|
// });
|
||||||
|
|
||||||
|
it('should not find removed question', async () => {
|
||||||
|
const id = new LearningObjectIdentifier('id04', Language.English, '1');
|
||||||
|
await QuestionRepository.removeQuestionByLearningObjectAndSequenceNumber(
|
||||||
|
id,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
|
||||||
|
const question =
|
||||||
|
await QuestionRepository.findAllQuestionsAboutLearningObject(id);
|
||||||
|
|
||||||
|
expect(question).toHaveLength(0);
|
||||||
|
});
|
||||||
|
});
|
|
@ -476,45 +476,45 @@ export async function setupTestApp() {
|
||||||
|
|
||||||
learningObject02.attachments = [attachment01];
|
learningObject02.attachments = [attachment01];
|
||||||
|
|
||||||
// const question01 = em.create(Question, {
|
const question01 = em.create(Question, {
|
||||||
// learningObjectLanguage: Language.English,
|
learningObjectLanguage: Language.English,
|
||||||
// learningObjectVersion: '1',
|
learningObjectVersion: '1',
|
||||||
// learningObjectHruid: 'id05',
|
learningObjectHruid: 'id05',
|
||||||
// sequenceNumber: 1,
|
sequenceNumber: 1,
|
||||||
// author: student01,
|
author: student01,
|
||||||
// timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
// content: 'question',
|
content: 'question',
|
||||||
// });
|
});
|
||||||
|
|
||||||
// const question02 = em.create(Question, {
|
const question02 = em.create(Question, {
|
||||||
// learningObjectLanguage: Language.English,
|
learningObjectLanguage: Language.English,
|
||||||
// learningObjectVersion: '1',
|
learningObjectVersion: '1',
|
||||||
// learningObjectHruid: 'id05',
|
learningObjectHruid: 'id05',
|
||||||
// sequenceNumber: 2,
|
sequenceNumber: 2,
|
||||||
// author: student03,
|
author: student03,
|
||||||
// timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
// content: 'question',
|
content: 'question',
|
||||||
// });
|
});
|
||||||
|
|
||||||
// const question03 = em.create(Question, {
|
const question03 = em.create(Question, {
|
||||||
// learningObjectLanguage: Language.English,
|
learningObjectLanguage: Language.English,
|
||||||
// learningObjectVersion: '1',
|
learningObjectVersion: '1',
|
||||||
// learningObjectHruid: 'id04',
|
learningObjectHruid: 'id04',
|
||||||
// sequenceNumber: 1,
|
sequenceNumber: 1,
|
||||||
// author: student01,
|
author: student01,
|
||||||
// timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
// content: 'question',
|
content: 'question',
|
||||||
// });
|
});
|
||||||
|
|
||||||
// const question04 = em.create(Question, {
|
const question04 = em.create(Question, {
|
||||||
// learningObjectLanguage: Language.English,
|
learningObjectLanguage: Language.English,
|
||||||
// learningObjectVersion: '1',
|
learningObjectVersion: '1',
|
||||||
// learningObjectHruid: 'id01',
|
learningObjectHruid: 'id01',
|
||||||
// sequenceNumber: 1,
|
sequenceNumber: 1,
|
||||||
// author: student02,
|
author: student02,
|
||||||
// timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
// content: 'question',
|
content: 'question',
|
||||||
// });
|
});
|
||||||
|
|
||||||
// const answer01 = em.create(Answer, {
|
// const answer01 = em.create(Answer, {
|
||||||
// author: teacher01,
|
// author: teacher01,
|
||||||
|
@ -631,5 +631,9 @@ export async function setupTestApp() {
|
||||||
group02,
|
group02,
|
||||||
group03,
|
group03,
|
||||||
group04,
|
group04,
|
||||||
|
question01,
|
||||||
|
question02,
|
||||||
|
question03,
|
||||||
|
question04,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue