feat: status teacher invite
This commit is contained in:
parent
783c91b2e3
commit
f3d2b3313c
16 changed files with 184 additions and 79 deletions
|
@ -1,9 +1,15 @@
|
|||
import { beforeAll, beforeEach, describe, expect, it, Mock, vi } from 'vitest';
|
||||
import { Request, Response } from 'express';
|
||||
import { setupTestApp } from '../setup-tests.js';
|
||||
import { createInvitationHandler, deleteInvitationForHandler, getAllInvitationsHandler } from '../../src/controllers/teacher-invitations';
|
||||
import {
|
||||
createInvitationHandler,
|
||||
deleteInvitationHandler,
|
||||
getAllInvitationsHandler,
|
||||
getInvitationHandler
|
||||
} from '../../src/controllers/teacher-invitations';
|
||||
import { TeacherInvitationData } from '@dwengo-1/common/interfaces/teacher-invitation';
|
||||
import { getClassHandler } from '../../src/controllers/classes';
|
||||
import {BadRequestException} from "../../src/exceptions/bad-request-exception";
|
||||
|
||||
describe('Teacher controllers', () => {
|
||||
let req: Partial<Request>;
|
||||
|
@ -23,13 +29,14 @@ describe('Teacher controllers', () => {
|
|||
});
|
||||
|
||||
it('Get teacher invitations by', async () => {
|
||||
req = { params: { username: 'LimpBizkit' }, query: { by: 'true' } };
|
||||
req = { params: { username: 'LimpBizkit' }, query: { sent: 'true' } };
|
||||
|
||||
await getAllInvitationsHandler(req as Request, res as Response);
|
||||
|
||||
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ invitations: expect.anything() }));
|
||||
|
||||
const result = jsonMock.mock.lastCall?.[0];
|
||||
console.log(result.invitations);
|
||||
expect(result.invitations).to.have.length.greaterThan(0);
|
||||
});
|
||||
|
||||
|
@ -63,9 +70,33 @@ describe('Teacher controllers', () => {
|
|||
body: { accepted: 'false' },
|
||||
};
|
||||
|
||||
await deleteInvitationForHandler(req as Request, res as Response);
|
||||
await deleteInvitationHandler(req as Request, res as Response);
|
||||
});
|
||||
|
||||
it('Get invitation', async () => {
|
||||
req = {
|
||||
params: {
|
||||
sender: 'LimpBizkit',
|
||||
receiver: 'FooFighters',
|
||||
classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89',
|
||||
},
|
||||
};
|
||||
await getInvitationHandler(req as Request, res as Response);
|
||||
|
||||
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ invitation: expect.anything() }));
|
||||
});
|
||||
|
||||
it('Get invitation error', async () => {
|
||||
req = {
|
||||
params: { no: 'no params' },
|
||||
};
|
||||
|
||||
await expect( async () => getInvitationHandler(req as Request, res as Response))
|
||||
.rejects.toThrowError(BadRequestException);
|
||||
});
|
||||
|
||||
/*
|
||||
|
||||
it('Create and accept invitation', async () => {
|
||||
const body = {
|
||||
sender: 'LimpBizkit',
|
||||
|
@ -85,7 +116,7 @@ describe('Teacher controllers', () => {
|
|||
body: { accepted: 'true' },
|
||||
};
|
||||
|
||||
await deleteInvitationForHandler(req as Request, res as Response);
|
||||
await deleteInvitationHandler(req as Request, res as Response);
|
||||
|
||||
req = {
|
||||
params: {
|
||||
|
@ -98,4 +129,6 @@ describe('Teacher controllers', () => {
|
|||
const result = jsonMock.mock.lastCall?.[0];
|
||||
expect(result.class.teachers).toContain('testleerkracht1');
|
||||
});
|
||||
|
||||
*/
|
||||
});
|
||||
|
|
|
@ -2,31 +2,31 @@ import { EntityManager } from '@mikro-orm/core';
|
|||
import { ClassJoinRequest } from '../../../src/entities/classes/class-join-request.entity';
|
||||
import { Student } from '../../../src/entities/users/student.entity';
|
||||
import { Class } from '../../../src/entities/classes/class.entity';
|
||||
import { ClassJoinRequestStatus } from '@dwengo-1/common/util/class-join-request';
|
||||
import { ClassStatus } from '@dwengo-1/common/util/class-join-request';
|
||||
|
||||
export function makeTestClassJoinRequests(em: EntityManager, students: Student[], classes: Class[]): ClassJoinRequest[] {
|
||||
const classJoinRequest01 = em.create(ClassJoinRequest, {
|
||||
requester: students[4],
|
||||
class: classes[1],
|
||||
status: ClassJoinRequestStatus.Open,
|
||||
status: ClassStatus.Open,
|
||||
});
|
||||
|
||||
const classJoinRequest02 = em.create(ClassJoinRequest, {
|
||||
requester: students[2],
|
||||
class: classes[1],
|
||||
status: ClassJoinRequestStatus.Open,
|
||||
status: ClassStatus.Open,
|
||||
});
|
||||
|
||||
const classJoinRequest03 = em.create(ClassJoinRequest, {
|
||||
requester: students[4],
|
||||
class: classes[2],
|
||||
status: ClassJoinRequestStatus.Open,
|
||||
status: ClassStatus.Open,
|
||||
});
|
||||
|
||||
const classJoinRequest04 = em.create(ClassJoinRequest, {
|
||||
requester: students[3],
|
||||
class: classes[2],
|
||||
status: ClassJoinRequestStatus.Open,
|
||||
status: ClassStatus.Open,
|
||||
});
|
||||
|
||||
return [classJoinRequest01, classJoinRequest02, classJoinRequest03, classJoinRequest04];
|
||||
|
|
|
@ -1,31 +1,36 @@
|
|||
import { EntityManager } from '@mikro-orm/core';
|
||||
import { TeacherInvitation } from '../../../src/entities/classes/teacher-invitation.entity';
|
||||
import { Teacher } from '../../../src/entities/users/teacher.entity';
|
||||
import { Class } from '../../../src/entities/classes/class.entity';
|
||||
import {EntityManager} from '@mikro-orm/core';
|
||||
import {TeacherInvitation} from '../../../src/entities/classes/teacher-invitation.entity';
|
||||
import {Teacher} from '../../../src/entities/users/teacher.entity';
|
||||
import {Class} from '../../../src/entities/classes/class.entity';
|
||||
import {ClassStatus} from "@dwengo-1/common/util/class-join-request";
|
||||
|
||||
export function makeTestTeacherInvitations(em: EntityManager, teachers: Teacher[], classes: Class[]): TeacherInvitation[] {
|
||||
const teacherInvitation01 = em.create(TeacherInvitation, {
|
||||
sender: teachers[1],
|
||||
receiver: teachers[0],
|
||||
class: classes[1],
|
||||
status: ClassStatus.Open
|
||||
});
|
||||
|
||||
const teacherInvitation02 = em.create(TeacherInvitation, {
|
||||
sender: teachers[1],
|
||||
receiver: teachers[2],
|
||||
class: classes[1],
|
||||
status: ClassStatus.Open
|
||||
});
|
||||
|
||||
const teacherInvitation03 = em.create(TeacherInvitation, {
|
||||
sender: teachers[2],
|
||||
receiver: teachers[0],
|
||||
class: classes[2],
|
||||
status: ClassStatus.Open
|
||||
});
|
||||
|
||||
const teacherInvitation04 = em.create(TeacherInvitation, {
|
||||
sender: teachers[0],
|
||||
receiver: teachers[1],
|
||||
class: classes[0],
|
||||
status: ClassStatus.Open
|
||||
});
|
||||
|
||||
return [teacherInvitation01, teacherInvitation02, teacherInvitation03, teacherInvitation04];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue