style: fix linting issues met Prettier

This commit is contained in:
Lint Action 2025-03-13 14:30:15 +00:00
parent e58835aa17
commit e73d5c21c3
34 changed files with 103 additions and 296 deletions

View file

@ -62,7 +62,9 @@ De tech-stack bestaat uit:
Voor meer informatie over de keuze van deze tech-stack, zie [designkeuzes](https://github.com/SELab-2/Dwengo-1/wiki/Developer:-Design-keuzes). Voor meer informatie over de keuze van deze tech-stack, zie [designkeuzes](https://github.com/SELab-2/Dwengo-1/wiki/Developer:-Design-keuzes).
## Testen ## Testen
Voer volgende commando's uit om de <frontend/backend> te testen: Voer volgende commando's uit om de <frontend/backend> te testen:
``` ```
npm run test:unit npm run test:unit
``` ```

View file

@ -22,7 +22,9 @@ npm run start
``` ```
### Tests ### Tests
Voer volgend commando uit om de unit tests uit te voeren: Voer volgend commando uit om de unit tests uit te voeren:
``` ```
npm run test:unit npm run test:unit
``` ```

View file

@ -4,19 +4,13 @@ import { Question } from '../../entities/questions/question.entity.js';
import { Teacher } from '../../entities/users/teacher.entity.js'; import { Teacher } from '../../entities/users/teacher.entity.js';
export class AnswerRepository extends DwengoEntityRepository<Answer> { export class AnswerRepository extends DwengoEntityRepository<Answer> {
public createAnswer(answer: { public createAnswer(answer: { toQuestion: Question; author: Teacher; content: string }): Promise<Answer> {
toQuestion: Question; const answerEntity = this.create({
author: Teacher; toQuestion: answer.toQuestion,
content: string; author: answer.author,
}): Promise<Answer> { content: answer.content,
const answerEntity = this.create( timestamp: new Date(),
{ });
toQuestion: answer.toQuestion,
author: answer.author,
content: answer.content,
timestamp: new Date()
}
);
return this.insert(answerEntity); return this.insert(answerEntity);
} }
public findAllAnswersToQuestion(question: Question): Promise<Answer[]> { public findAllAnswersToQuestion(question: Question): Promise<Answer[]> {

View file

@ -11,7 +11,7 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
learningObjectVersion: question.loId.version, learningObjectVersion: question.loId.version,
author: question.author, author: question.author,
content: question.content, content: question.content,
timestamp: new Date() timestamp: new Date(),
}); });
questionEntity.learningObjectHruid = question.loId.hruid; questionEntity.learningObjectHruid = question.loId.hruid;
questionEntity.learningObjectLanguage = question.loId.language; questionEntity.learningObjectLanguage = question.loId.language;

View file

@ -24,7 +24,7 @@ import { LearningPath } from './entities/content/learning-path.entity.js';
import { Answer } from './entities/questions/answer.entity.js'; import { Answer } from './entities/questions/answer.entity.js';
import { Question } from './entities/questions/question.entity.js'; import { Question } from './entities/questions/question.entity.js';
import {SqliteAutoincrementSubscriber} from "./sqlite-autoincrement-workaround.js"; import { SqliteAutoincrementSubscriber } from './sqlite-autoincrement-workaround.js';
const entities = [ const entities = [
User, User,

View file

@ -1,4 +1,4 @@
import {EntityManager, MikroORM} from '@mikro-orm/core'; import { EntityManager, MikroORM } from '@mikro-orm/core';
import config from './mikro-orm.config.js'; import config from './mikro-orm.config.js';
import { EnvVars, getEnvVar } from './util/envvars.js'; import { EnvVars, getEnvVar } from './util/envvars.js';
import { getLogger, Logger } from './logging/initalize.js'; import { getLogger, Logger } from './logging/initalize.js';

View file

@ -1,4 +1,4 @@
import {EntityProperty, EventArgs, EventSubscriber} from "@mikro-orm/core"; import { EntityProperty, EventArgs, EventSubscriber } from '@mikro-orm/core';
/** /**
* The tests are ran on an in-memory SQLite database. However, SQLite does not allow fields which are part of composite * The tests are ran on an in-memory SQLite database. However, SQLite does not allow fields which are part of composite
@ -29,7 +29,7 @@ export class SqliteAutoincrementSubscriber implements EventSubscriber {
const property = prop as EntityProperty<T>; const property = prop as EntityProperty<T>;
if (property.primary && property.autoincrement && !(args.entity as Record<string, any>)[property.name]) { if (property.primary && property.autoincrement && !(args.entity as Record<string, any>)[property.name]) {
// Obtain and increment sequence number of this entity. // Obtain and increment sequence number of this entity.
const propertyKey = args.meta.class.name + "." + property.name; const propertyKey = args.meta.class.name + '.' + property.name;
const nextSeqNumber = this.sequenceNumbersForEntityType.get(propertyKey) || 0; const nextSeqNumber = this.sequenceNumbersForEntityType.get(propertyKey) || 0;
this.sequenceNumbersForEntityType.set(propertyKey, nextSeqNumber + 1); this.sequenceNumbersForEntityType.set(propertyKey, nextSeqNumber + 1);

View file

@ -1,10 +1,7 @@
import { beforeAll, describe, expect, it } from 'vitest'; import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests'; import { setupTestApp } from '../../setup-tests';
import { AssignmentRepository } from '../../../src/data/assignments/assignment-repository'; import { AssignmentRepository } from '../../../src/data/assignments/assignment-repository';
import { import { getAssignmentRepository, getClassRepository } from '../../../src/data/repositories';
getAssignmentRepository,
getClassRepository,
} from '../../../src/data/repositories';
import { ClassRepository } from '../../../src/data/classes/class-repository'; import { ClassRepository } from '../../../src/data/classes/class-repository';
describe('AssignmentRepository', () => { describe('AssignmentRepository', () => {
@ -19,10 +16,7 @@ describe('AssignmentRepository', () => {
it('should return the requested assignment', async () => { it('should return the requested assignment', async () => {
const class_ = await classRepository.findById('id02'); const class_ = await classRepository.findById('id02');
const assignment = await assignmentRepository.findByClassAndId( const assignment = await assignmentRepository.findByClassAndId(class_!, 2);
class_!,
2
);
expect(assignment).toBeTruthy(); expect(assignment).toBeTruthy();
expect(assignment!.title).toBe('tool'); expect(assignment!.title).toBe('tool');
@ -30,8 +24,7 @@ describe('AssignmentRepository', () => {
it('should return all assignments for a class', async () => { it('should return all assignments for a class', async () => {
const class_ = await classRepository.findById('id02'); const class_ = await classRepository.findById('id02');
const assignments = const assignments = await assignmentRepository.findAllAssignmentsInClass(class_!);
await assignmentRepository.findAllAssignmentsInClass(class_!);
expect(assignments).toBeTruthy(); expect(assignments).toBeTruthy();
expect(assignments).toHaveLength(1); expect(assignments).toHaveLength(1);
@ -42,10 +35,7 @@ describe('AssignmentRepository', () => {
const class_ = await classRepository.findById('id01'); const class_ = await classRepository.findById('id01');
await assignmentRepository.deleteByClassAndId(class_!, 3); await assignmentRepository.deleteByClassAndId(class_!, 3);
const assignment = await assignmentRepository.findByClassAndId( const assignment = await assignmentRepository.findByClassAndId(class_!, 3);
class_!,
3
);
expect(assignment).toBeNull(); expect(assignment).toBeNull();
}); });

View file

@ -1,11 +1,7 @@
import { beforeAll, describe, expect, it } from 'vitest'; import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests'; import { setupTestApp } from '../../setup-tests';
import { GroupRepository } from '../../../src/data/assignments/group-repository'; import { GroupRepository } from '../../../src/data/assignments/group-repository';
import { import { getAssignmentRepository, getClassRepository, getGroupRepository } from '../../../src/data/repositories';
getAssignmentRepository,
getClassRepository,
getGroupRepository,
} from '../../../src/data/repositories';
import { AssignmentRepository } from '../../../src/data/assignments/assignment-repository'; import { AssignmentRepository } from '../../../src/data/assignments/assignment-repository';
import { ClassRepository } from '../../../src/data/classes/class-repository'; import { ClassRepository } from '../../../src/data/classes/class-repository';
@ -23,29 +19,18 @@ describe('GroupRepository', () => {
it('should return the requested group', async () => { it('should return the requested group', async () => {
const class_ = await classRepository.findById('id01'); const class_ = await classRepository.findById('id01');
const assignment = await assignmentRepository.findByClassAndId( const assignment = await assignmentRepository.findByClassAndId(class_!, 1);
class_!,
1
);
const group = await groupRepository.findByAssignmentAndGroupNumber( const group = await groupRepository.findByAssignmentAndGroupNumber(assignment!, 1);
assignment!,
1
);
expect(group).toBeTruthy(); expect(group).toBeTruthy();
}); });
it('should return all groups for assignment', async () => { it('should return all groups for assignment', async () => {
const class_ = await classRepository.findById('id01'); const class_ = await classRepository.findById('id01');
const assignment = await assignmentRepository.findByClassAndId( const assignment = await assignmentRepository.findByClassAndId(class_!, 1);
class_!,
1
);
const groups = await groupRepository.findAllGroupsForAssignment( const groups = await groupRepository.findAllGroupsForAssignment(assignment!);
assignment!
);
expect(groups).toBeTruthy(); expect(groups).toBeTruthy();
expect(groups).toHaveLength(3); expect(groups).toHaveLength(3);
@ -53,17 +38,11 @@ describe('GroupRepository', () => {
it('should not find removed group', async () => { it('should not find removed group', async () => {
const class_ = await classRepository.findById('id02'); const class_ = await classRepository.findById('id02');
const assignment = await assignmentRepository.findByClassAndId( const assignment = await assignmentRepository.findByClassAndId(class_!, 2);
class_!,
2
);
await groupRepository.deleteByAssignmentAndGroupNumber(assignment!, 1); await groupRepository.deleteByAssignmentAndGroupNumber(assignment!, 1);
const group = await groupRepository.findByAssignmentAndGroupNumber( const group = await groupRepository.findByAssignmentAndGroupNumber(assignment!, 1);
assignment!,
1
);
expect(group).toBeNull(); expect(group).toBeNull();
}); });

View file

@ -33,11 +33,7 @@ describe('SubmissionRepository', () => {
it('should find the requested submission', async () => { it('should find the requested submission', async () => {
const id = new LearningObjectIdentifier('id03', Language.English, '1'); const id = new LearningObjectIdentifier('id03', Language.English, '1');
const submission = const submission = await submissionRepository.findSubmissionByLearningObjectAndSubmissionNumber(id, 1);
await submissionRepository.findSubmissionByLearningObjectAndSubmissionNumber(
id,
1
);
expect(submission).toBeTruthy(); expect(submission).toBeTruthy();
expect(submission?.content).toBe('sub1'); expect(submission?.content).toBe('sub1');
@ -46,11 +42,7 @@ describe('SubmissionRepository', () => {
it('should find the most recent submission for a student', async () => { it('should find the most recent submission for a student', async () => {
const id = new LearningObjectIdentifier('id02', Language.English, '1'); const id = new LearningObjectIdentifier('id02', Language.English, '1');
const student = await studentRepository.findByUsername('Noordkaap'); const student = await studentRepository.findByUsername('Noordkaap');
const submission = const submission = await submissionRepository.findMostRecentSubmissionForStudent(id, student!);
await submissionRepository.findMostRecentSubmissionForStudent(
id,
student!
);
expect(submission).toBeTruthy(); expect(submission).toBeTruthy();
expect(submission?.submissionTime.getDate()).toBe(25); expect(submission?.submissionTime.getDate()).toBe(25);
@ -59,19 +51,9 @@ describe('SubmissionRepository', () => {
it('should find the most recent submission for a group', async () => { it('should find the most recent submission for a group', async () => {
const id = new LearningObjectIdentifier('id03', Language.English, '1'); const id = new LearningObjectIdentifier('id03', Language.English, '1');
const class_ = await classRepository.findById('id01'); const class_ = await classRepository.findById('id01');
const assignment = await assignmentRepository.findByClassAndId( const assignment = await assignmentRepository.findByClassAndId(class_!, 1);
class_!, const group = await groupRepository.findByAssignmentAndGroupNumber(assignment!, 1);
1 const submission = await submissionRepository.findMostRecentSubmissionForGroup(id, group!);
);
const group = await groupRepository.findByAssignmentAndGroupNumber(
assignment!,
1
);
const submission =
await submissionRepository.findMostRecentSubmissionForGroup(
id,
group!
);
expect(submission).toBeTruthy(); expect(submission).toBeTruthy();
expect(submission?.submissionTime.getDate()).toBe(25); expect(submission?.submissionTime.getDate()).toBe(25);
@ -79,16 +61,9 @@ describe('SubmissionRepository', () => {
it('should not find a deleted submission', async () => { it('should not find a deleted submission', async () => {
const id = new LearningObjectIdentifier('id01', Language.English, '1'); const id = new LearningObjectIdentifier('id01', Language.English, '1');
await submissionRepository.deleteSubmissionByLearningObjectAndSubmissionNumber( await submissionRepository.deleteSubmissionByLearningObjectAndSubmissionNumber(id, 1);
id,
1
);
const submission = const submission = await submissionRepository.findSubmissionByLearningObjectAndSubmissionNumber(id, 1);
await submissionRepository.findSubmissionByLearningObjectAndSubmissionNumber(
id,
1
);
expect(submission).toBeNull(); expect(submission).toBeNull();
}); });

View file

@ -1,11 +1,7 @@
import { beforeAll, describe, expect, it } from 'vitest'; import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests'; import { setupTestApp } from '../../setup-tests';
import { ClassJoinRequestRepository } from '../../../src/data/classes/class-join-request-repository'; import { ClassJoinRequestRepository } from '../../../src/data/classes/class-join-request-repository';
import { import { getClassJoinRequestRepository, getClassRepository, getStudentRepository } from '../../../src/data/repositories';
getClassJoinRequestRepository,
getClassRepository,
getStudentRepository,
} from '../../../src/data/repositories';
import { StudentRepository } from '../../../src/data/users/student-repository'; import { StudentRepository } from '../../../src/data/users/student-repository';
import { Class } from '../../../src/entities/classes/class.entity'; import { Class } from '../../../src/entities/classes/class.entity';
import { ClassRepository } from '../../../src/data/classes/class-repository'; import { ClassRepository } from '../../../src/data/classes/class-repository';
@ -25,9 +21,7 @@ describe('ClassJoinRequestRepository', () => {
it('should list all requests from student to join classes', async () => { it('should list all requests from student to join classes', async () => {
const student = await studentRepository.findByUsername('PinkFloyd'); const student = await studentRepository.findByUsername('PinkFloyd');
const requests = await classJoinRequestRepository.findAllRequestsBy( const requests = await classJoinRequestRepository.findAllRequestsBy(student!);
student!
);
expect(requests).toBeTruthy(); expect(requests).toBeTruthy();
expect(requests).toHaveLength(2); expect(requests).toHaveLength(2);
@ -35,23 +29,18 @@ describe('ClassJoinRequestRepository', () => {
it('should list all requests to a single class', async () => { it('should list all requests to a single class', async () => {
const class_ = await cassRepository.findById('id02'); const class_ = await cassRepository.findById('id02');
const requests = await classJoinRequestRepository.findAllOpenRequestsTo( const requests = await classJoinRequestRepository.findAllOpenRequestsTo(class_!);
class_!
);
expect(requests).toBeTruthy(); expect(requests).toBeTruthy();
expect(requests).toHaveLength(2); expect(requests).toHaveLength(2);
}); });
it('should not find a removed request', async () => { it('should not find a removed request', async () => {
const student = const student = await studentRepository.findByUsername('SmashingPumpkins');
await studentRepository.findByUsername('SmashingPumpkins');
const class_ = await cassRepository.findById('id03'); const class_ = await cassRepository.findById('id03');
await classJoinRequestRepository.deleteBy(student!, class_!); await classJoinRequestRepository.deleteBy(student!, class_!);
const request = await classJoinRequestRepository.findAllRequestsBy( const request = await classJoinRequestRepository.findAllRequestsBy(student!);
student!
);
expect(request).toHaveLength(0); expect(request).toHaveLength(0);
}); });

View file

@ -1,10 +1,6 @@
import { beforeAll, describe, expect, it } from 'vitest'; import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests'; import { setupTestApp } from '../../setup-tests';
import { import { getClassRepository, getTeacherInvitationRepository, getTeacherRepository } from '../../../src/data/repositories';
getClassRepository,
getTeacherInvitationRepository,
getTeacherRepository,
} from '../../../src/data/repositories';
import { TeacherInvitationRepository } from '../../../src/data/classes/teacher-invitation-repository'; import { TeacherInvitationRepository } from '../../../src/data/classes/teacher-invitation-repository';
import { TeacherRepository } from '../../../src/data/users/teacher-repository'; import { TeacherRepository } from '../../../src/data/users/teacher-repository';
import { ClassRepository } from '../../../src/data/classes/class-repository'; import { ClassRepository } from '../../../src/data/classes/class-repository';
@ -23,8 +19,7 @@ describe('ClassRepository', () => {
it('should return all invitations from a teacher', async () => { it('should return all invitations from a teacher', async () => {
const teacher = await teacherRepository.findByUsername('LimpBizkit'); const teacher = await teacherRepository.findByUsername('LimpBizkit');
const invitations = const invitations = await teacherInvitationRepository.findAllInvitationsBy(teacher!);
await teacherInvitationRepository.findAllInvitationsBy(teacher!);
expect(invitations).toBeTruthy(); expect(invitations).toBeTruthy();
expect(invitations).toHaveLength(2); expect(invitations).toHaveLength(2);
@ -32,8 +27,7 @@ describe('ClassRepository', () => {
it('should return all invitations for a teacher', async () => { it('should return all invitations for a teacher', async () => {
const teacher = await teacherRepository.findByUsername('FooFighters'); const teacher = await teacherRepository.findByUsername('FooFighters');
const invitations = const invitations = await teacherInvitationRepository.findAllInvitationsFor(teacher!);
await teacherInvitationRepository.findAllInvitationsFor(teacher!);
expect(invitations).toBeTruthy(); expect(invitations).toBeTruthy();
expect(invitations).toHaveLength(2); expect(invitations).toHaveLength(2);
@ -41,10 +35,7 @@ describe('ClassRepository', () => {
it('should return all invitations for a class', async () => { it('should return all invitations for a class', async () => {
const class_ = await classRepository.findById('id02'); const class_ = await classRepository.findById('id02');
const invitations = const invitations = await teacherInvitationRepository.findAllInvitationsForClass(class_!);
await teacherInvitationRepository.findAllInvitationsForClass(
class_!
);
expect(invitations).toBeTruthy(); expect(invitations).toBeTruthy();
expect(invitations).toHaveLength(2); expect(invitations).toHaveLength(2);
@ -56,8 +47,7 @@ describe('ClassRepository', () => {
const receiver = await teacherRepository.findByUsername('LimpBizkit'); const receiver = await teacherRepository.findByUsername('LimpBizkit');
await teacherInvitationRepository.deleteBy(class_!, sender!, receiver!); await teacherInvitationRepository.deleteBy(class_!, sender!, receiver!);
const invitation = const invitation = await teacherInvitationRepository.findAllInvitationsBy(sender!);
await teacherInvitationRepository.findAllInvitationsBy(sender!);
expect(invitation).toHaveLength(0); expect(invitation).toHaveLength(0);
}); });

View file

@ -1,9 +1,6 @@
import { beforeAll, describe, expect, it } from 'vitest'; import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests.js'; import { setupTestApp } from '../../setup-tests.js';
import { import { getAttachmentRepository, getLearningObjectRepository } from '../../../src/data/repositories.js';
getAttachmentRepository,
getLearningObjectRepository,
} from '../../../src/data/repositories.js';
import { AttachmentRepository } from '../../../src/data/content/attachment-repository.js'; import { AttachmentRepository } from '../../../src/data/content/attachment-repository.js';
import { LearningObjectRepository } from '../../../src/data/content/learning-object-repository.js'; import { LearningObjectRepository } from '../../../src/data/content/learning-object-repository.js';
import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier.js'; import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier.js';
@ -21,15 +18,13 @@ describe('AttachmentRepository', () => {
it('should return the requested attachment', async () => { it('should return the requested attachment', async () => {
const id = new LearningObjectIdentifier('id02', Language.English, '1'); const id = new LearningObjectIdentifier('id02', Language.English, '1');
const learningObject = const learningObject = await learningObjectRepository.findByIdentifier(id);
await learningObjectRepository.findByIdentifier(id);
const attachment = const attachment = await attachmentRepository.findByMostRecentVersionOfLearningObjectAndName(
await attachmentRepository.findByMostRecentVersionOfLearningObjectAndName( learningObject!,
learningObject!, Language.English,
Language.English, 'attachment01'
'attachment01' );
);
expect(attachment).toBeTruthy(); expect(attachment).toBeTruthy();
}); });

View file

@ -17,8 +17,7 @@ describe('LearningObjectRepository', () => {
const id02 = new LearningObjectIdentifier('test_id', Language.English, '1'); const id02 = new LearningObjectIdentifier('test_id', Language.English, '1');
it('should return the learning object that matches identifier 1', async () => { it('should return the learning object that matches identifier 1', async () => {
const learningObject = const learningObject = await learningObjectRepository.findByIdentifier(id01);
await learningObjectRepository.findByIdentifier(id01);
expect(learningObject).toBeTruthy(); expect(learningObject).toBeTruthy();
expect(learningObject?.title).toBe('Undertow'); expect(learningObject?.title).toBe('Undertow');
@ -26,8 +25,7 @@ describe('LearningObjectRepository', () => {
}); });
it('should return nothing because the identifier does not exist in the database', async () => { it('should return nothing because the identifier does not exist in the database', async () => {
const learningObject = const learningObject = await learningObjectRepository.findByIdentifier(id02);
await learningObjectRepository.findByIdentifier(id02);
expect(learningObject).toBeNull(); expect(learningObject).toBeNull();
}); });

View file

@ -13,21 +13,13 @@ describe('LearningPathRepository', () => {
}); });
it('should return nothing because no match for hruid and language', async () => { it('should return nothing because no match for hruid and language', async () => {
const learningPath = const learningPath = await learningPathRepository.findByHruidAndLanguage('test_id', Language.Dutch);
await learningPathRepository.findByHruidAndLanguage(
'test_id',
Language.Dutch
);
expect(learningPath).toBeNull(); expect(learningPath).toBeNull();
}); });
it('should return requested learning path', async () => { it('should return requested learning path', async () => {
const learningPath = const learningPath = await learningPathRepository.findByHruidAndLanguage('id01', Language.English);
await learningPathRepository.findByHruidAndLanguage(
'id01',
Language.English
);
expect(learningPath).toBeTruthy(); expect(learningPath).toBeTruthy();
expect(learningPath?.title).toBe('repertoire Tool'); expect(learningPath?.title).toBe('repertoire Tool');

View file

@ -1,11 +1,7 @@
import { beforeAll, describe, expect, it } from 'vitest'; import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests'; import { setupTestApp } from '../../setup-tests';
import { AnswerRepository } from '../../../src/data/questions/answer-repository'; import { AnswerRepository } from '../../../src/data/questions/answer-repository';
import { import { getAnswerRepository, getQuestionRepository, getTeacherRepository } from '../../../src/data/repositories';
getAnswerRepository,
getQuestionRepository,
getTeacherRepository,
} from '../../../src/data/repositories';
import { QuestionRepository } from '../../../src/data/questions/question-repository'; import { QuestionRepository } from '../../../src/data/questions/question-repository';
import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier'; import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier';
import { Language } from '../../../src/entities/content/language'; import { Language } from '../../../src/entities/content/language';
@ -25,13 +21,11 @@ describe('AnswerRepository', () => {
it('should find all answers to a question', async () => { it('should find all answers to a question', async () => {
const id = new LearningObjectIdentifier('id05', Language.English, '1'); const id = new LearningObjectIdentifier('id05', Language.English, '1');
const questions = const questions = await questionRepository.findAllQuestionsAboutLearningObject(id);
await questionRepository.findAllQuestionsAboutLearningObject(id);
const question = questions.filter((it) => it.sequenceNumber == 2)[0]; const question = questions.filter((it) => it.sequenceNumber == 2)[0];
const answers = const answers = await answerRepository.findAllAnswersToQuestion(question);
await answerRepository.findAllAnswersToQuestion(question);
expect(answers).toBeTruthy(); expect(answers).toBeTruthy();
expect(answers).toHaveLength(2); expect(answers).toHaveLength(2);
@ -42,8 +36,7 @@ describe('AnswerRepository', () => {
it('should create an answer to a question', async () => { 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 id = new LearningObjectIdentifier('id05', Language.English, '1');
const questions = const questions = await questionRepository.findAllQuestionsAboutLearningObject(id);
await questionRepository.findAllQuestionsAboutLearningObject(id);
const question = questions[0]; const question = questions[0];
@ -53,8 +46,7 @@ describe('AnswerRepository', () => {
content: 'created answer', content: 'created answer',
}); });
const answers = const answers = await answerRepository.findAllAnswersToQuestion(question);
await answerRepository.findAllAnswersToQuestion(question);
expect(answers).toBeTruthy(); expect(answers).toBeTruthy();
expect(answers).toHaveLength(1); expect(answers).toHaveLength(1);
@ -63,17 +55,11 @@ describe('AnswerRepository', () => {
it('should not find a removed answer', async () => { it('should not find a removed answer', async () => {
const id = new LearningObjectIdentifier('id04', Language.English, '1'); const id = new LearningObjectIdentifier('id04', Language.English, '1');
const questions = const questions = await questionRepository.findAllQuestionsAboutLearningObject(id);
await questionRepository.findAllQuestionsAboutLearningObject(id);
await answerRepository.removeAnswerByQuestionAndSequenceNumber( await answerRepository.removeAnswerByQuestionAndSequenceNumber(questions[0], 1);
questions[0],
1
);
const emptyList = await answerRepository.findAllAnswersToQuestion( const emptyList = await answerRepository.findAllAnswersToQuestion(questions[0]);
questions[0]
);
expect(emptyList).toHaveLength(0); expect(emptyList).toHaveLength(0);
}); });

View file

@ -1,11 +1,7 @@
import { beforeAll, describe, expect, it } from 'vitest'; import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests'; import { setupTestApp } from '../../setup-tests';
import { QuestionRepository } from '../../../src/data/questions/question-repository'; import { QuestionRepository } from '../../../src/data/questions/question-repository';
import { import { getLearningObjectRepository, getQuestionRepository, getStudentRepository } from '../../../src/data/repositories';
getLearningObjectRepository,
getQuestionRepository,
getStudentRepository,
} from '../../../src/data/repositories';
import { StudentRepository } from '../../../src/data/users/student-repository'; import { StudentRepository } from '../../../src/data/users/student-repository';
import { LearningObjectRepository } from '../../../src/data/content/learning-object-repository'; import { LearningObjectRepository } from '../../../src/data/content/learning-object-repository';
import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier'; import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier';
@ -25,8 +21,7 @@ describe('QuestionRepository', () => {
it('should return all questions part of the given learning object', async () => { it('should return all questions part of the given learning object', async () => {
const id = new LearningObjectIdentifier('id05', Language.English, '1'); const id = new LearningObjectIdentifier('id05', Language.English, '1');
const questions = const questions = await questionRepository.findAllQuestionsAboutLearningObject(id);
await questionRepository.findAllQuestionsAboutLearningObject(id);
expect(questions).toBeTruthy(); expect(questions).toBeTruthy();
expect(questions).toHaveLength(2); expect(questions).toHaveLength(2);
@ -40,8 +35,7 @@ describe('QuestionRepository', () => {
author: student!, author: student!,
content: 'question?', content: 'question?',
}); });
const question = const question = await questionRepository.findAllQuestionsAboutLearningObject(id);
await questionRepository.findAllQuestionsAboutLearningObject(id);
expect(question).toBeTruthy(); expect(question).toBeTruthy();
expect(question).toHaveLength(1); expect(question).toHaveLength(1);
@ -49,13 +43,9 @@ describe('QuestionRepository', () => {
it('should not find removed question', async () => { it('should not find removed question', async () => {
const id = new LearningObjectIdentifier('id04', Language.English, '1'); const id = new LearningObjectIdentifier('id04', Language.English, '1');
await questionRepository.removeQuestionByLearningObjectAndSequenceNumber( await questionRepository.removeQuestionByLearningObjectAndSequenceNumber(id, 1);
id,
1
);
const question = const question = await questionRepository.findAllQuestionsAboutLearningObject(id);
await questionRepository.findAllQuestionsAboutLearningObject(id);
expect(question).toHaveLength(0); expect(question).toHaveLength(0);
}); });

View file

@ -30,12 +30,9 @@ describe('TeacherRepository', () => {
}); });
it('should return the queried teacher after he was added', async () => { it('should return the queried teacher after he was added', async () => {
await teacherRepository.insert( await teacherRepository.insert(new Teacher(username, firstName, lastName));
new Teacher(username, firstName, lastName)
);
const retrievedTeacher = const retrievedTeacher = await teacherRepository.findByUsername(username);
await teacherRepository.findByUsername(username);
expect(retrievedTeacher).toBeTruthy(); expect(retrievedTeacher).toBeTruthy();
expect(retrievedTeacher?.firstName).toBe(firstName); expect(retrievedTeacher?.firstName).toBe(firstName);
expect(retrievedTeacher?.lastName).toBe(lastName); expect(retrievedTeacher?.lastName).toBe(lastName);
@ -44,8 +41,7 @@ describe('TeacherRepository', () => {
it('should no longer return the queried teacher after he was removed again', async () => { it('should no longer return the queried teacher after he was removed again', async () => {
await teacherRepository.deleteByUsername('ZesdeMetaal'); await teacherRepository.deleteByUsername('ZesdeMetaal');
const retrievedTeacher = const retrievedTeacher = await teacherRepository.findByUsername('ZesdeMetaal');
await teacherRepository.findByUsername('ZesdeMetaal');
expect(retrievedTeacher).toBeNull(); expect(retrievedTeacher).toBeNull();
}); });
}); });

View file

@ -31,11 +31,7 @@ export async function setupTestApp() {
assignments[0].groups = groups.slice(0, 3); assignments[0].groups = groups.slice(0, 3);
assignments[1].groups = groups.slice(3, 4); assignments[1].groups = groups.slice(3, 4);
const teacherInvitations = makeTestTeacherInvitations( const teacherInvitations = makeTestTeacherInvitations(em, teachers, classes);
em,
teachers,
classes
);
const classJoinRequests = makeTestClassJoinRequests(em, students, classes); const classJoinRequests = makeTestClassJoinRequests(em, students, classes);
const attachments = makeTestAttachments(em, learningObjects); const attachments = makeTestAttachments(em, learningObjects);

View file

@ -3,10 +3,7 @@ import { Assignment } from '../../../src/entities/assignments/assignment.entity'
import { Class } from '../../../src/entities/classes/class.entity'; import { Class } from '../../../src/entities/classes/class.entity';
import { Language } from '../../../src/entities/content/language'; import { Language } from '../../../src/entities/content/language';
export function makeTestAssignemnts( export function makeTestAssignemnts(em: EntityManager<IDatabaseDriver<Connection>>, classes: Array<Class>): Array<Assignment> {
em: EntityManager<IDatabaseDriver<Connection>>,
classes: Array<Class>
): Array<Assignment> {
const assignment01 = em.create(Assignment, { const assignment01 = em.create(Assignment, {
within: classes[0], within: classes[0],
id: 1, id: 1,

View file

@ -61,11 +61,5 @@ export function makeTestSubmissions(
content: '', content: '',
}); });
return [ return [submission01, submission02, submission03, submission04, submission05];
submission01,
submission02,
submission03,
submission04,
submission05,
];
} }

View file

@ -1,8 +1,5 @@
import { Connection, EntityManager, IDatabaseDriver } from '@mikro-orm/core'; import { Connection, EntityManager, IDatabaseDriver } from '@mikro-orm/core';
import { import { ClassJoinRequest, ClassJoinRequestStatus } from '../../../src/entities/classes/class-join-request.entity';
ClassJoinRequest,
ClassJoinRequestStatus,
} from '../../../src/entities/classes/class-join-request.entity';
import { Student } from '../../../src/entities/users/student.entity'; import { Student } from '../../../src/entities/users/student.entity';
import { Class } from '../../../src/entities/classes/class.entity'; import { Class } from '../../../src/entities/classes/class.entity';
@ -35,10 +32,5 @@ export function makeTestClassJoinRequests(
status: ClassJoinRequestStatus.Open, status: ClassJoinRequestStatus.Open,
}); });
return [ return [classJoinRequest01, classJoinRequest02, classJoinRequest03, classJoinRequest04];
classJoinRequest01,
classJoinRequest02,
classJoinRequest03,
classJoinRequest04,
];
} }

View file

@ -3,11 +3,7 @@ import { Class } from '../../../src/entities/classes/class.entity';
import { Student } from '../../../src/entities/users/student.entity'; import { Student } from '../../../src/entities/users/student.entity';
import { Teacher } from '../../../src/entities/users/teacher.entity'; import { Teacher } from '../../../src/entities/users/teacher.entity';
export function makeTestClasses( export function makeTestClasses(em: EntityManager<IDatabaseDriver<Connection>>, students: Array<Student>, teachers: Array<Teacher>): Array<Class> {
em: EntityManager<IDatabaseDriver<Connection>>,
students: Array<Student>,
teachers: Array<Teacher>
): Array<Class> {
const studentsClass01 = students.slice(0, 7); const studentsClass01 = students.slice(0, 7);
const teacherClass01: Array<Teacher> = teachers.slice(0, 1); const teacherClass01: Array<Teacher> = teachers.slice(0, 1);
@ -18,9 +14,7 @@ export function makeTestClasses(
students: studentsClass01, students: studentsClass01,
}); });
const studentsClass02: Array<Student> = students const studentsClass02: Array<Student> = students.slice(0, 2).concat(students.slice(3, 4));
.slice(0, 2)
.concat(students.slice(3, 4));
const teacherClass02: Array<Teacher> = teachers.slice(1, 2); const teacherClass02: Array<Teacher> = teachers.slice(1, 2);
const class02 = em.create(Class, { const class02 = em.create(Class, {

View file

@ -32,10 +32,5 @@ export function makeTestTeacherInvitations(
class: classes[0], class: classes[0],
}); });
return [ return [teacherInvitation01, teacherInvitation02, teacherInvitation03, teacherInvitation04];
teacherInvitation01,
teacherInvitation02,
teacherInvitation03,
teacherInvitation04,
];
} }

View file

@ -2,10 +2,7 @@ import { Connection, EntityManager, IDatabaseDriver } from '@mikro-orm/core';
import { Attachment } from '../../../src/entities/content/attachment.entity'; import { Attachment } from '../../../src/entities/content/attachment.entity';
import { LearningObject } from '../../../src/entities/content/learning-object.entity'; import { LearningObject } from '../../../src/entities/content/learning-object.entity';
export function makeTestAttachments( export function makeTestAttachments(em: EntityManager<IDatabaseDriver<Connection>>, learningObjects: Array<LearningObject>): Array<Attachment> {
em: EntityManager<IDatabaseDriver<Connection>>,
learningObjects: Array<LearningObject>
): Array<Attachment> {
const attachment01 = em.create(Attachment, { const attachment01 = em.create(Attachment, {
learningObject: learningObjects[1], learningObject: learningObjects[1],
name: 'attachment01', name: 'attachment01',

View file

@ -3,9 +3,7 @@ import { LearningObject, ReturnValue } from '../../../src/entities/content/learn
import { Language } from '../../../src/entities/content/language'; import { Language } from '../../../src/entities/content/language';
import { DwengoContentType } from '../../../src/services/learning-objects/processing/content-type'; import { DwengoContentType } from '../../../src/services/learning-objects/processing/content-type';
export function makeTestLearningObjects( export function makeTestLearningObjects(em: EntityManager<IDatabaseDriver<Connection>>): Array<LearningObject> {
em: EntityManager<IDatabaseDriver<Connection>>
): Array<LearningObject> {
const returnValue: ReturnValue = new ReturnValue(); const returnValue: ReturnValue = new ReturnValue();
returnValue.callbackSchema = ''; returnValue.callbackSchema = '';
returnValue.callbackUrl = ''; returnValue.callbackUrl = '';
@ -29,9 +27,7 @@ export function makeTestLearningObjects(
available: true, available: true,
contentLocation: '', contentLocation: '',
attachments: [], attachments: [],
content: Buffer.from( content: Buffer.from("there's a shadow just behind me, shrouding every step i take, making every promise empty pointing every finger at me"),
"there's a shadow just behind me, shrouding every step i take, making every promise empty pointing every finger at me"
)
}); });
const learningObject02 = em.create(LearningObject, { const learningObject02 = em.create(LearningObject, {
@ -131,16 +127,8 @@ export function makeTestLearningObjects(
available: true, available: true,
contentLocation: '', contentLocation: '',
attachments: [], attachments: [],
content: Buffer.from( content: Buffer.from('calling Elvis, is anybody home, calling elvis, I am here all alone'),
'calling Elvis, is anybody home, calling elvis, I am here all alone'
),
}); });
return [ return [learningObject01, learningObject02, learningObject03, learningObject04, learningObject05];
learningObject01,
learningObject02,
learningObject03,
learningObject04,
learningObject05,
];
} }

View file

@ -1,14 +1,10 @@
import { Connection, EntityManager, IDatabaseDriver } from '@mikro-orm/core'; import { Connection, EntityManager, IDatabaseDriver } from '@mikro-orm/core';
import { import { LearningPath } from '../../../src/entities/content/learning-path.entity';
LearningPath,
} from '../../../src/entities/content/learning-path.entity';
import { Language } from '../../../src/entities/content/language'; import { Language } from '../../../src/entities/content/language';
import { LearningPathTransition } from '../../../src/entities/content/learning-path-transition.entity'; import { LearningPathTransition } from '../../../src/entities/content/learning-path-transition.entity';
import { LearningPathNode } from '../../../src/entities/content/learning-path-node.entity'; import { LearningPathNode } from '../../../src/entities/content/learning-path-node.entity';
export function makeTestLearningPaths( export function makeTestLearningPaths(em: EntityManager<IDatabaseDriver<Connection>>): Array<LearningPath> {
em: EntityManager<IDatabaseDriver<Connection>>
): Array<LearningPath> {
const learningPathNode01: LearningPathNode = new LearningPathNode(); const learningPathNode01: LearningPathNode = new LearningPathNode();
const learningPathNode02: LearningPathNode = new LearningPathNode(); const learningPathNode02: LearningPathNode = new LearningPathNode();
const learningPathNode03: LearningPathNode = new LearningPathNode(); const learningPathNode03: LearningPathNode = new LearningPathNode();

View file

@ -3,11 +3,7 @@ import { Answer } from '../../../src/entities/questions/answer.entity';
import { Teacher } from '../../../src/entities/users/teacher.entity'; import { Teacher } from '../../../src/entities/users/teacher.entity';
import { Question } from '../../../src/entities/questions/question.entity'; import { Question } from '../../../src/entities/questions/question.entity';
export function makeTestAnswers( export function makeTestAnswers(em: EntityManager<IDatabaseDriver<Connection>>, teachers: Array<Teacher>, questions: Array<Question>): Array<Answer> {
em: EntityManager<IDatabaseDriver<Connection>>,
teachers: Array<Teacher>,
questions: Array<Question>
): Array<Answer> {
const answer01 = em.create(Answer, { const answer01 = em.create(Answer, {
author: teachers[0], author: teachers[0],
toQuestion: questions[1], toQuestion: questions[1],

View file

@ -3,10 +3,7 @@ import { Question } from '../../../src/entities/questions/question.entity';
import { Language } from '../../../src/entities/content/language'; import { Language } from '../../../src/entities/content/language';
import { Student } from '../../../src/entities/users/student.entity'; import { Student } from '../../../src/entities/users/student.entity';
export function makeTestQuestions( export function makeTestQuestions(em: EntityManager<IDatabaseDriver<Connection>>, students: Array<Student>): Array<Question> {
em: EntityManager<IDatabaseDriver<Connection>>,
students: Array<Student>
): Array<Question> {
const question01 = em.create(Question, { const question01 = em.create(Question, {
learningObjectLanguage: Language.English, learningObjectLanguage: Language.English,
learningObjectVersion: '1', learningObjectVersion: '1',

View file

@ -1,9 +1,7 @@
import { Connection, EntityManager, IDatabaseDriver } from '@mikro-orm/core'; import { Connection, EntityManager, IDatabaseDriver } from '@mikro-orm/core';
import { Student } from '../../../src/entities/users/student.entity'; import { Student } from '../../../src/entities/users/student.entity';
export function makeTestStudents( export function makeTestStudents(em: EntityManager<IDatabaseDriver<Connection>>): Array<Student> {
em: EntityManager<IDatabaseDriver<Connection>>
): Array<Student> {
const student01 = em.create(Student, { const student01 = em.create(Student, {
username: 'Noordkaap', username: 'Noordkaap',
firstName: 'Stijn', firstName: 'Stijn',
@ -47,13 +45,5 @@ export function makeTestStudents(
lastName: 'Cobain', lastName: 'Cobain',
}); });
return [ return [student01, student02, student03, student04, student05, student06, student07];
student01,
student02,
student03,
student04,
student05,
student06,
student07,
];
} }

View file

@ -1,9 +1,7 @@
import { Teacher } from '../../../src/entities/users/teacher.entity'; import { Teacher } from '../../../src/entities/users/teacher.entity';
import { Connection, EntityManager, IDatabaseDriver } from '@mikro-orm/core'; import { Connection, EntityManager, IDatabaseDriver } from '@mikro-orm/core';
export function makeTestTeachers( export function makeTestTeachers(em: EntityManager<IDatabaseDriver<Connection>>): Array<Teacher> {
em: EntityManager<IDatabaseDriver<Connection>>
): Array<Teacher> {
const teacher01 = em.create(Teacher, { const teacher01 = em.create(Teacher, {
username: 'FooFighters', username: 'FooFighters',
firstName: 'Dave', firstName: 'Dave',

View file

@ -2,10 +2,10 @@
import { ref } from "vue"; import { ref } from "vue";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
import dwengoLogo from "../../../assets/img/dwengo-groen-zwart.svg"; import dwengoLogo from "../../../assets/img/dwengo-groen-zwart.svg";
import {useI18n} from "vue-i18n"; import { useI18n } from "vue-i18n";
const route = useRoute(); const route = useRoute();
const { t, locale } = useI18n() const { t, locale } = useI18n();
// Instantiate variables to use in html to render right // Instantiate variables to use in html to render right
// Links and content dependent on the role (student or teacher) // Links and content dependent on the role (student or teacher)
@ -30,7 +30,7 @@
// Logic to change the language of the website to the selected language // Logic to change the language of the website to the selected language
const changeLanguage = (langCode: string) => { const changeLanguage = (langCode: string) => {
locale.value = langCode; locale.value = langCode;
localStorage.setItem('user-lang', langCode); localStorage.setItem("user-lang", langCode);
console.log(langCode); console.log(langCode);
}; };
</script> </script>
@ -59,22 +59,22 @@
:to="`/${role}/${userId}/assignment`" :to="`/${role}/${userId}/assignment`"
class="menu_item" class="menu_item"
> >
{{ t('assignments') }} {{ t("assignments") }}
</router-link> </router-link>
</li> </li>
<li> <li>
<router-link <router-link
:to="`/${role}/${userId}/class`" :to="`/${role}/${userId}/class`"
class="menu_item" class="menu_item"
>{{ t('classes') }}</router-link >{{ t("classes") }}</router-link
> >
</li> </li>
<li> <li>
<router-link <router-link
:to="`/${role}/${userId}/discussion`" :to="`/${role}/${userId}/discussion`"
class="menu_item" class="menu_item"
>{{ t('discussions') }} </router-link >{{ t("discussions") }}
> </router-link>
</li> </li>
<li> <li>
<v-menu open-on-hover> <v-menu open-on-hover>

View file

@ -1,4 +1,4 @@
import { createI18n } from 'vue-i18n'; import { createI18n } from "vue-i18n";
// Import translations // Import translations
import en from "@/i18n/locale/en.json"; import en from "@/i18n/locale/en.json";
@ -6,11 +6,11 @@ import nl from "@/i18n/locale/nl.json";
import fr from "@/i18n/locale/fr.json"; import fr from "@/i18n/locale/fr.json";
import de from "@/i18n/locale/de.json"; import de from "@/i18n/locale/de.json";
const savedLocale = localStorage.getItem('user-lang') || 'en'; const savedLocale = localStorage.getItem("user-lang") || "en";
const i18n = createI18n({ const i18n = createI18n({
locale: savedLocale, locale: savedLocale,
fallbackLocale: 'en', fallbackLocale: "en",
messages: { messages: {
en: en, en: en,
nl: nl, nl: nl,

View file

@ -1,8 +1,8 @@
import {createApp} from "vue"; import { createApp } from "vue";
// Vuetify // Vuetify
import "vuetify/styles"; import "vuetify/styles";
import {createVuetify} from "vuetify"; import { createVuetify } from "vuetify";
import * as components from "vuetify/components"; import * as components from "vuetify/components";
import * as directives from "vuetify/directives"; import * as directives from "vuetify/directives";
import i18n from "./i18n/i18n.ts"; import i18n from "./i18n/i18n.ts";
@ -11,7 +11,6 @@ import i18n from "./i18n/i18n.ts";
import App from "./App.vue"; import App from "./App.vue";
import router from "./router"; import router from "./router";
const app = createApp(App); const app = createApp(App);
app.use(router); app.use(router);