fix(backend): Workaround voor autoincrement-problemen bij SQLite

SQLite (die we voor de automatische tests gebruiken) ondersteunt geen autoincrement op kolommen die deel uitmaken van een composite primary key. Hiervoor heb ik een workaround geïmplementeerd.
This commit is contained in:
Gerald Schmittinger 2025-03-13 02:20:01 +01:00
parent 678ced55ba
commit 4dcd4671ca
9 changed files with 94 additions and 42 deletions

View file

@ -9,7 +9,6 @@ import {
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', () => {
@ -40,27 +39,27 @@ describe('AnswerRepository', () => {
expect(answers[1].content).toBeOneOf(['answer', 'answer2']);
});
// 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);
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);
// const question = questions[0];
const question = questions[0];
// await answerRepository.createAnswer({
// toQuestion: question,
// author: teacher!,
// content: 'created answer',
// });
await answerRepository.createAnswer({
toQuestion: question,
author: teacher!,
content: 'created answer',
});
// const answers =
// await answerRepository.findAllAnswersToQuestion(question);
const answers =
await answerRepository.findAllAnswersToQuestion(question);
// expect(answers).toBeTruthy();
// expect(answers).toHaveLength(1);
// expect(answers[0].content).toBe('created answer');
// });
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');

View file

@ -10,7 +10,6 @@ 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;
@ -33,20 +32,20 @@ describe('QuestionRepository', () => {
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);
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);
// });
expect(question).toBeTruthy();
expect(question).toHaveLength(1);
});
it('should not find removed question', async () => {
const id = new LearningObjectIdentifier('id04', Language.English, '1');