test: testen voor answer repo staan klaar, creatie werkt niet omdat geen sequence number meegegeven kan worden

This commit is contained in:
Laure Jablonski 2025-03-09 09:43:29 +01:00
parent a697138c6a
commit c96ccfbfdd
2 changed files with 109 additions and 21 deletions

View file

@ -0,0 +1,85 @@
import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../setup-tests';
import { AnswerRepository } from '../../src/data/questions/answer-repository';
import {
getAnswerRepository,
getQuestionRepository,
getTeacherRepository,
} from '../../src/data/repositories';
import { QuestionRepository } from '../../src/data/questions/question-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';
import { TeacherRepository } from '../../src/data/users/teacher-repository';
describe('AnswerRepository', () => {
let AnswerRepository: AnswerRepository;
let QuestionRepository: QuestionRepository;
let TeacherRepository: TeacherRepository;
beforeAll(async () => {
await setupTestApp();
AnswerRepository = getAnswerRepository();
QuestionRepository = getQuestionRepository();
TeacherRepository = getTeacherRepository();
});
it('should find all answers to a question', async () => {
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 answers =
await AnswerRepository.findAllAnswersToQuestion(question);
expect(answers).toBeTruthy();
expect(answers).toHaveLength(2);
});
// it('should create an answer to a question', async () => {
// 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({
// toQuestion: question,
// author: teacher!,
// content: 'created answer',
// });
// const answers =
// await AnswerRepository.findAllAnswersToQuestion(question);
// expect(answers).toBeTruthy();
// expect(answers).toHaveLength(1);
// expect(answers[0].content).toBe('created answer');
// });
it('should not find a removed answer', async () => {
const id = new LearningObjectIdentifier('id04', Language.English, '1');
const questions =
await QuestionRepository.findAllQuestionsAboutLearningObject(id);
await AnswerRepository.removeAnswerByQuestionAndSequenceNumber(
questions[0],
1
);
const emptyList = await AnswerRepository.findAllAnswersToQuestion(
questions[0]
);
expect(emptyList).toHaveLength(0);
});
});

View file

@ -516,29 +516,29 @@ export async function setupTestApp() {
content: 'question', content: 'question',
}); });
// const answer01 = em.create(Answer, { const answer01 = em.create(Answer, {
// author: teacher01, author: teacher01,
// toQuestion: question02, toQuestion: question02,
// sequenceNumber: 1, sequenceNumber: 1,
// timestamp: new Date(), timestamp: new Date(),
// content: 'answer', content: 'answer',
// }); });
// const answer02 = em.create(Answer, { const answer02 = em.create(Answer, {
// author: teacher01, author: teacher01,
// toQuestion: question02, toQuestion: question02,
// sequenceNumber: 2, sequenceNumber: 2,
// timestamp: new Date(), timestamp: new Date(),
// content: 'answer2', content: 'answer2',
// }); });
// const answer03 = em.create(Answer, { const answer03 = em.create(Answer, {
// author: teacher02, author: teacher02,
// toQuestion: question04, toQuestion: question04,
// sequenceNumber: 1, sequenceNumber: 1,
// timestamp: new Date(), timestamp: new Date(),
// content: 'answer', content: 'answer',
// }); });
// const submission01 = em.create(Submission, { // const submission01 = em.create(Submission, {
// learningObjectHruid: 'id03', // learningObjectHruid: 'id03',
@ -635,5 +635,8 @@ export async function setupTestApp() {
question02, question02,
question03, question03,
question04, question04,
answer01,
answer02,
answer03,
]); ]);
} }