From 946c233a529010d4c28a9536094376b49c865eb6 Mon Sep 17 00:00:00 2001 From: Laure Jablonski Date: Mon, 10 Mar 2025 19:36:19 +0100 Subject: [PATCH] test: de antwoorden die teruggegeven worden zijn de juiste --- backend/tests/data/answers.test.ts | 28 ++++++++++++---------------- backend/tests/setup-tests.ts | 2 +- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/backend/tests/data/answers.test.ts b/backend/tests/data/answers.test.ts index 54ffa592..52956b6e 100644 --- a/backend/tests/data/answers.test.ts +++ b/backend/tests/data/answers.test.ts @@ -28,38 +28,34 @@ describe('AnswerRepository', () => { const id = new LearningObjectIdentifier('id05', Language.English, '1'); const questions = await questionRepository.findAllQuestionsAboutLearningObject(id); - let question: Question; - if (questions[0].sequenceNumber == 2) { - question = questions[0]; - } else { - question = questions[1]; - } + + const question = questions.filter((it) => it.sequenceNumber == 2)[0]; + const answers = await answerRepository.findAllAnswersToQuestion(question); expect(answers).toBeTruthy(); expect(answers).toHaveLength(2); + expect(answers[0].content).toBeOneOf(['answer', 'answer2']); + expect(answers[1].content).toBeOneOf(['answer', 'answer2']); }); // it('should create an answer to a question', async () => { - // const teacher = await TeacherRepository.findByUsername('FooFighters'); + // const teacher = await teacherRepository.findByUsername('FooFighters'); // const id = new LearningObjectIdentifier('id05', Language.English, '1'); // const questions = - // await QuestionRepository.findAllQuestionsAboutLearningObject(id); - // let question: Question; - // if (questions[0].sequenceNumber == 1) { - // question = questions[0]; - // } else { - // question = questions[1]; - // } - // await AnswerRepository.createAnswer({ + // await questionRepository.findAllQuestionsAboutLearningObject(id); + + // const question = questions[0]; + + // await answerRepository.createAnswer({ // toQuestion: question, // author: teacher!, // content: 'created answer', // }); // const answers = - // await AnswerRepository.findAllAnswersToQuestion(question); + // await answerRepository.findAllAnswersToQuestion(question); // expect(answers).toBeTruthy(); // expect(answers).toHaveLength(1); diff --git a/backend/tests/setup-tests.ts b/backend/tests/setup-tests.ts index 2f497ece..92e886bf 100644 --- a/backend/tests/setup-tests.ts +++ b/backend/tests/setup-tests.ts @@ -537,7 +537,7 @@ export async function setupTestApp() { toQuestion: question04, sequenceNumber: 1, timestamp: new Date(), - content: 'answer', + content: 'answer3', }); const submission01 = em.create(Submission, {