test: assignment repo getest
This commit is contained in:
parent
9b4250e72c
commit
73f14a4074
2 changed files with 80 additions and 27 deletions
51
backend/tests/data/assignments.test.ts
Normal file
51
backend/tests/data/assignments.test.ts
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
import { beforeAll, describe, expect, it } from 'vitest';
|
||||||
|
import { setupTestApp } from '../setup-tests';
|
||||||
|
import { AssignmentRepository } from '../../src/data/assignments/assignment-repository';
|
||||||
|
import {
|
||||||
|
getAssignmentRepository,
|
||||||
|
getClassRepository,
|
||||||
|
} from '../../src/data/repositories';
|
||||||
|
import { ClassRepository } from '../../src/data/classes/class-repository';
|
||||||
|
|
||||||
|
describe('AssignmentRepository', () => {
|
||||||
|
let AssignmentRepository: AssignmentRepository;
|
||||||
|
let ClassRepository: ClassRepository;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await setupTestApp();
|
||||||
|
AssignmentRepository = getAssignmentRepository();
|
||||||
|
ClassRepository = getClassRepository();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the requested assignment', async () => {
|
||||||
|
const class_ = await ClassRepository.findById('id02');
|
||||||
|
const assignment = await AssignmentRepository.findByClassAndId(
|
||||||
|
class_!,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(assignment).toBeTruthy();
|
||||||
|
expect(assignment!.title).toBe('tool');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return all assignments for a class', async () => {
|
||||||
|
const class_ = await ClassRepository.findById('id02');
|
||||||
|
const assignments =
|
||||||
|
await AssignmentRepository.findAllAssignmentsInClass(class_!);
|
||||||
|
|
||||||
|
expect(assignments).toBeTruthy();
|
||||||
|
expect(assignments).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not find removed assignment', async () => {
|
||||||
|
const class_ = await ClassRepository.findById('id01');
|
||||||
|
await AssignmentRepository.deleteByClassAndId(class_!, 3);
|
||||||
|
|
||||||
|
const assignment = await AssignmentRepository.findByClassAndId(
|
||||||
|
class_!,
|
||||||
|
3
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(assignment).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
|
@ -362,35 +362,35 @@ export async function setupTestApp() {
|
||||||
students: studentsClass04,
|
students: studentsClass04,
|
||||||
});
|
});
|
||||||
|
|
||||||
// const assignment01 = em.create(Assignment, {
|
const assignment01 = em.create(Assignment, {
|
||||||
// within: class01,
|
within: class01,
|
||||||
// id: 1,
|
id: 1,
|
||||||
// title: 'dire straits',
|
title: 'dire straits',
|
||||||
// description: 'reading',
|
description: 'reading',
|
||||||
// learningPathHruid: 'id02',
|
learningPathHruid: 'id02',
|
||||||
// learningPathLanguage: Language.English,
|
learningPathLanguage: Language.English,
|
||||||
// groups: [],
|
groups: [],
|
||||||
// });
|
});
|
||||||
|
|
||||||
// const assignment02 = em.create(Assignment, {
|
const assignment02 = em.create(Assignment, {
|
||||||
// within: class02,
|
within: class02,
|
||||||
// id: 2,
|
id: 2,
|
||||||
// title: 'tool',
|
title: 'tool',
|
||||||
// description: 'reading',
|
description: 'reading',
|
||||||
// learningPathHruid: 'id01',
|
learningPathHruid: 'id01',
|
||||||
// learningPathLanguage: Language.English,
|
learningPathLanguage: Language.English,
|
||||||
// groups: [],
|
groups: [],
|
||||||
// });
|
});
|
||||||
|
|
||||||
// const assignment03 = em.create(Assignment, {
|
const assignment03 = em.create(Assignment, {
|
||||||
// within: class01,
|
within: class01,
|
||||||
// id: 3,
|
id: 3,
|
||||||
// title: 'delete',
|
title: 'delete',
|
||||||
// description: 'will be deleted',
|
description: 'will be deleted',
|
||||||
// learningPathHruid: 'id02',
|
learningPathHruid: 'id02',
|
||||||
// learningPathLanguage: Language.English,
|
learningPathLanguage: Language.English,
|
||||||
// groups: [],
|
groups: [],
|
||||||
// });
|
});
|
||||||
|
|
||||||
// const group01 = em.create(Group, {
|
// const group01 = em.create(Group, {
|
||||||
// assignment: assignment01,
|
// assignment: assignment01,
|
||||||
|
@ -626,5 +626,7 @@ export async function setupTestApp() {
|
||||||
teacherInvitation02,
|
teacherInvitation02,
|
||||||
teacherInvitation03,
|
teacherInvitation03,
|
||||||
teacherInvitation04,
|
teacherInvitation04,
|
||||||
|
assignment01,
|
||||||
|
assignment03,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue