From b3fbcb17af0cee8fd37ec9beb1b475bc55b11fb8 Mon Sep 17 00:00:00 2001 From: Laure Jablonski Date: Sat, 8 Mar 2025 22:11:49 +0100 Subject: [PATCH] test: testen staan klaar voor questions repo, probleem met creeren, sequence nummer wordt niet meegegeven --- backend/tests/data/questions.test.ts | 63 +++++++++++++++++++++++ backend/tests/setup-tests.ts | 76 +++++++++++++++------------- 2 files changed, 103 insertions(+), 36 deletions(-) create mode 100644 backend/tests/data/questions.test.ts diff --git a/backend/tests/data/questions.test.ts b/backend/tests/data/questions.test.ts new file mode 100644 index 00000000..41185d47 --- /dev/null +++ b/backend/tests/data/questions.test.ts @@ -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); + }); +}); diff --git a/backend/tests/setup-tests.ts b/backend/tests/setup-tests.ts index c1e30c1c..6eeda030 100644 --- a/backend/tests/setup-tests.ts +++ b/backend/tests/setup-tests.ts @@ -476,45 +476,45 @@ export async function setupTestApp() { learningObject02.attachments = [attachment01]; - // const question01 = em.create(Question, { - // learningObjectLanguage: Language.English, - // learningObjectVersion: '1', - // learningObjectHruid: 'id05', - // sequenceNumber: 1, - // author: student01, - // timestamp: new Date(), - // content: 'question', - // }); + const question01 = em.create(Question, { + learningObjectLanguage: Language.English, + learningObjectVersion: '1', + learningObjectHruid: 'id05', + sequenceNumber: 1, + author: student01, + timestamp: new Date(), + content: 'question', + }); - // const question02 = em.create(Question, { - // learningObjectLanguage: Language.English, - // learningObjectVersion: '1', - // learningObjectHruid: 'id05', - // sequenceNumber: 2, - // author: student03, - // timestamp: new Date(), - // content: 'question', - // }); + const question02 = em.create(Question, { + learningObjectLanguage: Language.English, + learningObjectVersion: '1', + learningObjectHruid: 'id05', + sequenceNumber: 2, + author: student03, + timestamp: new Date(), + content: 'question', + }); - // const question03 = em.create(Question, { - // learningObjectLanguage: Language.English, - // learningObjectVersion: '1', - // learningObjectHruid: 'id04', - // sequenceNumber: 1, - // author: student01, - // timestamp: new Date(), - // content: 'question', - // }); + const question03 = em.create(Question, { + learningObjectLanguage: Language.English, + learningObjectVersion: '1', + learningObjectHruid: 'id04', + sequenceNumber: 1, + author: student01, + timestamp: new Date(), + content: 'question', + }); - // const question04 = em.create(Question, { - // learningObjectLanguage: Language.English, - // learningObjectVersion: '1', - // learningObjectHruid: 'id01', - // sequenceNumber: 1, - // author: student02, - // timestamp: new Date(), - // content: 'question', - // }); + const question04 = em.create(Question, { + learningObjectLanguage: Language.English, + learningObjectVersion: '1', + learningObjectHruid: 'id01', + sequenceNumber: 1, + author: student02, + timestamp: new Date(), + content: 'question', + }); // const answer01 = em.create(Answer, { // author: teacher01, @@ -631,5 +631,9 @@ export async function setupTestApp() { group02, group03, group04, + question01, + question02, + question03, + question04, ]); }