test: teacher invitation repo is getest
This commit is contained in:
parent
fb4dadcb18
commit
9b4250e72c
2 changed files with 89 additions and 21 deletions
64
backend/tests/data/teacher-invitation.test.ts
Normal file
64
backend/tests/data/teacher-invitation.test.ts
Normal file
|
@ -0,0 +1,64 @@
|
|||
import { beforeAll, describe, expect, it } from 'vitest';
|
||||
import { setupTestApp } from '../setup-tests';
|
||||
import {
|
||||
getClassRepository,
|
||||
getTeacherInvitationRepository,
|
||||
getTeacherRepository,
|
||||
} from '../../src/data/repositories';
|
||||
import { TeacherInvitationRepository } from '../../src/data/classes/teacher-invitation-repository';
|
||||
import { TeacherRepository } from '../../src/data/users/teacher-repository';
|
||||
import { ClassRepository } from '../../src/data/classes/class-repository';
|
||||
|
||||
describe('ClassRepository', () => {
|
||||
let TeacherInvitationRepository: TeacherInvitationRepository;
|
||||
let TeacherRepository: TeacherRepository;
|
||||
let ClassRepository: ClassRepository;
|
||||
|
||||
beforeAll(async () => {
|
||||
await setupTestApp();
|
||||
TeacherInvitationRepository = getTeacherInvitationRepository();
|
||||
TeacherRepository = getTeacherRepository();
|
||||
ClassRepository = getClassRepository();
|
||||
});
|
||||
|
||||
it('should return all invitations from a teacher', async () => {
|
||||
const teacher = await TeacherRepository.findByUsername('LimpBizkit');
|
||||
const invitations =
|
||||
await TeacherInvitationRepository.findAllInvitationsBy(teacher!);
|
||||
|
||||
expect(invitations).toBeTruthy();
|
||||
expect(invitations).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('should return all invitations for a teacher', async () => {
|
||||
const teacher = await TeacherRepository.findByUsername('FooFighters');
|
||||
const invitations =
|
||||
await TeacherInvitationRepository.findAllInvitationsFor(teacher!);
|
||||
|
||||
expect(invitations).toBeTruthy();
|
||||
expect(invitations).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('should return all invitations for a class', async () => {
|
||||
const class_ = await ClassRepository.findById('id02');
|
||||
const invitations =
|
||||
await TeacherInvitationRepository.findAllInvitationsForClass(
|
||||
class_!
|
||||
);
|
||||
|
||||
expect(invitations).toBeTruthy();
|
||||
expect(invitations).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('should not find a removed invitation', async () => {
|
||||
const class_ = await ClassRepository.findById('id01');
|
||||
const sender = await TeacherRepository.findByUsername('FooFighters');
|
||||
const receiver = await TeacherRepository.findByUsername('LimpBizkit');
|
||||
await TeacherInvitationRepository.deleteBy(class_!, sender!, receiver!);
|
||||
|
||||
const invitation =
|
||||
await TeacherInvitationRepository.findAllInvitationsBy(sender!);
|
||||
|
||||
expect(invitation).toHaveLength(0);
|
||||
});
|
||||
});
|
|
@ -81,7 +81,7 @@ export async function setupTestApp() {
|
|||
});
|
||||
|
||||
const teacher02 = em.create(Teacher, {
|
||||
username: 'LimppBizkit',
|
||||
username: 'LimpBizkit',
|
||||
firstName: 'Fred',
|
||||
lastName: 'Durst',
|
||||
});
|
||||
|
@ -421,29 +421,29 @@ export async function setupTestApp() {
|
|||
// assignment01.groups.push(group03);
|
||||
// assignment02.groups.push(group04);
|
||||
|
||||
// const teacher_invitation01 = em.create(TeacherInvitation, {
|
||||
// sender: teacher02,
|
||||
// receiver: teacher01,
|
||||
// class: class02,
|
||||
// });
|
||||
const teacherInvitation01 = em.create(TeacherInvitation, {
|
||||
sender: teacher02,
|
||||
receiver: teacher01,
|
||||
class: class02,
|
||||
});
|
||||
|
||||
// const teacher_invitation02 = em.create(TeacherInvitation, {
|
||||
// sender: teacher02,
|
||||
// receiver: teacher03,
|
||||
// class: class02,
|
||||
// });
|
||||
const teacherInvitation02 = em.create(TeacherInvitation, {
|
||||
sender: teacher02,
|
||||
receiver: teacher03,
|
||||
class: class02,
|
||||
});
|
||||
|
||||
// const teacher_invitation03 = em.create(TeacherInvitation, {
|
||||
// sender: teacher03,
|
||||
// receiver: teacher01,
|
||||
// class: class03,
|
||||
// });
|
||||
const teacherInvitation03 = em.create(TeacherInvitation, {
|
||||
sender: teacher03,
|
||||
receiver: teacher01,
|
||||
class: class03,
|
||||
});
|
||||
|
||||
// const teacher_invitation04 = em.create(TeacherInvitation, {
|
||||
// sender: teacher01,
|
||||
// receiver: teacher02,
|
||||
// class: class01,
|
||||
// });
|
||||
const teacherInvitation04 = em.create(TeacherInvitation, {
|
||||
sender: teacher01,
|
||||
receiver: teacher02,
|
||||
class: class01,
|
||||
});
|
||||
|
||||
const classJoinRequest01 = em.create(ClassJoinRequest, {
|
||||
requester: student05,
|
||||
|
@ -622,5 +622,9 @@ export async function setupTestApp() {
|
|||
classJoinRequest02,
|
||||
classJoinRequest03,
|
||||
classJoinRequest04,
|
||||
teacherInvitation01,
|
||||
teacherInvitation02,
|
||||
teacherInvitation03,
|
||||
teacherInvitation04,
|
||||
]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue