test: teacher invitation data
This commit is contained in:
parent
cc1a281d52
commit
a452b9fc4f
2 changed files with 24 additions and 13 deletions
|
@ -1,50 +1,60 @@
|
|||
import { beforeAll, describe, expect, it } from 'vitest';
|
||||
import { setupTestApp } from '../../setup-tests';
|
||||
import { getClassRepository, getTeacherInvitationRepository, getTeacherRepository } from '../../../src/data/repositories';
|
||||
import { 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';
|
||||
import { getFooFighters, getLimpBizkit } from '../../test_assets/users/teachers.testdata';
|
||||
import { getTeacherInvitation01, getTeacherInvitation02, getTeacherInvitation03 } from '../../test_assets/classes/teacher-invitations.testdata';
|
||||
import { getClass01, getClass02 } from '../../test_assets/classes/classes.testdata';
|
||||
|
||||
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 teacher = getLimpBizkit();
|
||||
const ti1 = getTeacherInvitation01();
|
||||
const ti2 = getTeacherInvitation02();
|
||||
const invitations = await teacherInvitationRepository.findAllInvitationsBy(teacher!);
|
||||
|
||||
expect(invitations).toBeTruthy();
|
||||
expect(invitations).toHaveLength(2);
|
||||
expect(invitations[0].class.classId).toBeOneOf([ti1.class.classId, ti2.class.classId]);
|
||||
expect(invitations[1].class.classId).toBeOneOf([ti1.class.classId, ti2.class.classId]);
|
||||
});
|
||||
|
||||
it('should return all invitations for a teacher', async () => {
|
||||
const teacher = await teacherRepository.findByUsername('FooFighters');
|
||||
const teacher = getFooFighters();
|
||||
const ti1 = getTeacherInvitation01();
|
||||
const ti2 = getTeacherInvitation03();
|
||||
const invitations = await teacherInvitationRepository.findAllInvitationsFor(teacher!);
|
||||
|
||||
expect(invitations).toBeTruthy();
|
||||
expect(invitations).toHaveLength(2);
|
||||
expect(invitations[0].class.classId).toBeOneOf([ti1.class.classId, ti2.class.classId]);
|
||||
expect(invitations[1].class.classId).toBeOneOf([ti1.class.classId, ti2.class.classId]);
|
||||
});
|
||||
|
||||
it('should return all invitations for a class', async () => {
|
||||
const class_ = await classRepository.findById('34d484a1-295f-4e9f-bfdc-3e7a23d86a89');
|
||||
const class_ = getClass02();
|
||||
const ti1 = getTeacherInvitation01();
|
||||
const ti2 = getTeacherInvitation02();
|
||||
const invitations = await teacherInvitationRepository.findAllInvitationsForClass(class_!);
|
||||
|
||||
expect(invitations).toBeTruthy();
|
||||
expect(invitations).toHaveLength(2);
|
||||
expect(invitations[0].class.classId).toBeOneOf([ti1.class.classId, ti2.class.classId]);
|
||||
expect(invitations[1].class.classId).toBeOneOf([ti1.class.classId, ti2.class.classId]);
|
||||
|
||||
});
|
||||
|
||||
it('should not find a removed invitation', async () => {
|
||||
const class_ = await classRepository.findById('8764b861-90a6-42e5-9732-c0d9eb2f55f9');
|
||||
const sender = await teacherRepository.findByUsername('FooFighters');
|
||||
const receiver = await teacherRepository.findByUsername('LimpBizkit');
|
||||
const class_ = getClass01();
|
||||
const sender = getFooFighters();
|
||||
const receiver = getLimpBizkit();
|
||||
await teacherInvitationRepository.deleteBy(class_!, sender!, receiver!);
|
||||
|
||||
const invitation = await teacherInvitationRepository.findAllInvitationsBy(sender!);
|
||||
|
|
|
@ -26,6 +26,7 @@ export function makeTestTeacherInvitations(em: EntityManager): TeacherInvitation
|
|||
status: ClassStatus.Open,
|
||||
});
|
||||
|
||||
// gets deleted in test
|
||||
teacherInvitation04 = em.create(TeacherInvitation, {
|
||||
sender: getFooFighters(),
|
||||
receiver: getLimpBizkit(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue