diff --git a/backend/tests/controllers/qol.ts b/backend/tests/controllers/qol.ts new file mode 100644 index 00000000..984b7c58 --- /dev/null +++ b/backend/tests/controllers/qol.ts @@ -0,0 +1,12 @@ +export function checkReturnList(jsonMock: Mock, listName: string) { + expect(jsonMock).toHaveBeenCalled(); + + const result = jsonMock.mock.lastCall![0]; + + expect(listName in result).toBeTruthy(); +} + +export function checkReturn404(jsonMock: Mock, statusMock: Mock) { + expect(statusMock).toHaveBeenCalledWith(404); + expect(jsonMock).toHaveBeenCalled(); +} diff --git a/backend/tests/controllers/submissions.test.ts b/backend/tests/controllers/submissions.test.ts new file mode 100644 index 00000000..442f81c5 --- /dev/null +++ b/backend/tests/controllers/submissions.test.ts @@ -0,0 +1,72 @@ +import { setupTestApp } from '../setup-tests.js'; +import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest'; +import { getSubmissionHandler } from '../../src/controllers/submissions.js'; +import { Request, Response } from 'express'; +import { checkReturn404, checkReturnList } from './qol.js'; + + +function createRequestObject(hruid: string, submissionNumber: string) { + return { + params: { + hruid: hruid, + id: submissionNumber, + }, + query: { + language: 'nl', + version: '1', + }, + } +} + +describe('Submission controllers', () => { + let req: Partial; + let res: Partial; + + let jsonMock: Mock; + let statusMock: Mock; + + beforeAll(async () => { + await setupTestApp(); + }); + + beforeEach(async () => { + jsonMock = vi.fn(); + statusMock = vi.fn().mockReturnThis(); + + res = { + json: jsonMock, + status: statusMock, + }; + }); + + it('should return a 404 and error if submission is not found', async () => { + req = createRequestObject('id01', '1000000'); + + await getSubmissionHandler(req as Request, res as Response); + + checkReturn404(jsonMock, statusMock); + }); + + it('should return a 404 and error if learningobject is not found', async () => { + req = createRequestObject('doesnotexist', '1000000'); + + await getSubmissionHandler(req as Request, res as Response); + + checkReturn404(jsonMock, statusMock); + }); + + it('should return an existing submission', async () => { + req = createRequestObject('id01', '1'); + + await getSubmissionHandler(req as Request, res as Response); + + console.log(jsonMock.mock.lastCall![0]); + // TODO + }); + + it('should return a list of submissions for a learning object', async () => { + req = createRequestObject('id01', 'irrelevant'); + + }); +}); +