From 3a78710059923a078e344343909e1fbd8c9d659e Mon Sep 17 00:00:00 2001 From: Gabriellvl Date: Sat, 10 May 2025 20:06:20 +0200 Subject: [PATCH] fix: lint --- backend/tests/controllers/assignments.test.ts | 15 ++++++------- backend/tests/controllers/groups.test.ts | 21 +++++++++---------- backend/tests/controllers/qol.ts | 16 -------------- backend/tests/controllers/submissions.test.ts | 15 +++++++------ 4 files changed, 25 insertions(+), 42 deletions(-) delete mode 100644 backend/tests/controllers/qol.ts diff --git a/backend/tests/controllers/assignments.test.ts b/backend/tests/controllers/assignments.test.ts index 2921b72e..81138ce3 100644 --- a/backend/tests/controllers/assignments.test.ts +++ b/backend/tests/controllers/assignments.test.ts @@ -2,13 +2,14 @@ import { setupTestApp } from '../setup-tests.js'; import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest'; import { Request, Response } from 'express'; import { getAssignmentHandler, getAllAssignmentsHandler, getAssignmentsSubmissionsHandler } from '../../src/controllers/assignments.js'; -import { checkReturn404, checkReturnList } from './qol.js' -import {getAnswerHandler} from "../../src/controllers/answers"; -import {NotFoundException} from "../../src/exceptions/not-found-exception"; -import {getClass01, getClass02, getClass03} from "../test_assets/classes/classes.testdata"; -import {getAssignment01} from "../test_assets/assignments/assignments.testdata"; +import { NotFoundException } from "../../src/exceptions/not-found-exception"; +import { getClass01 } from "../test_assets/classes/classes.testdata"; +import { getAssignment01 } from "../test_assets/assignments/assignments.testdata"; -function createRequestObject(classid: string, assignmentid: string) { +function createRequestObject(classid: string, assignmentid: string): { + query: {}; + params: { classid: string; id: string } +} { return { params: { classid: classid, @@ -40,7 +41,7 @@ describe('Assignment controllers', () => { }); it('return error non-existing assignment', async () => { - req = createRequestObject('doesnotexist', '43000'); // should not exist + req = createRequestObject('doesnotexist', '43000'); // Should not exist await expect(async () => getAssignmentHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException); }); diff --git a/backend/tests/controllers/groups.test.ts b/backend/tests/controllers/groups.test.ts index 356a4924..3888fef5 100644 --- a/backend/tests/controllers/groups.test.ts +++ b/backend/tests/controllers/groups.test.ts @@ -8,11 +8,10 @@ import { getGroupHandler, getGroupSubmissionsHandler } from '../../src/controllers/groups.js'; -import {getAnswerHandler} from "../../src/controllers/answers"; -import {NotFoundException} from "../../src/exceptions/not-found-exception"; -import {getClass01} from "../test_assets/classes/classes.testdata"; -import {getAssignment01, getAssignment02} from "../test_assets/assignments/assignments.testdata"; -import {getTestGroup01} from "../test_assets/assignments/groups.testdata"; +import { NotFoundException } from "../../src/exceptions/not-found-exception"; +import { getClass01 } from "../test_assets/classes/classes.testdata"; +import { getAssignment01, getAssignment02 } from "../test_assets/assignments/assignments.testdata"; +import { getTestGroup01 } from "../test_assets/assignments/groups.testdata"; function createRequestObject(classid: string, assignmentid: string, groupNumber: string) { return { @@ -51,7 +50,7 @@ describe('Group controllers', () => { params: { classid: 'id01', assignmentid: '1', - groupid: '154981', // should not exist + groupid: '154981', // Should not exist }, query: {}, }; @@ -64,8 +63,8 @@ describe('Group controllers', () => { req = { params: { classid: 'id01', - assignmentid: '1000', // should not exist - groupid: '42000', // should not exist + assignmentid: '1000', // Should not exist + groupid: '42000', // Should not exist }, query: {}, }; @@ -76,9 +75,9 @@ describe('Group controllers', () => { it('should return 404 not found ont a non-existing class', async () => { req = { params: { - classid: 'doesnotexist', // should not exist - assignmentid: '1000', // should not exist - groupid: '42000', // should not exist + classid: 'doesnotexist', // Should not exist + assignmentid: '1000', // Should not exist + groupid: '42000', // Should not exist }, query: {}, }; diff --git a/backend/tests/controllers/qol.ts b/backend/tests/controllers/qol.ts deleted file mode 100644 index 08f73f79..00000000 --- a/backend/tests/controllers/qol.ts +++ /dev/null @@ -1,16 +0,0 @@ -export function checkReturnList(jsonMock: Mock, listName: string, length?: number) { - expect(jsonMock).toHaveBeenCalled(); - - const result = jsonMock.mock.lastCall![0]; - - expect(listName in result).toBeTruthy(); - - if (length) { - expect(result[listName].length).toBe(length); - } -} - -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 index eefceb70..c246ab38 100644 --- a/backend/tests/controllers/submissions.test.ts +++ b/backend/tests/controllers/submissions.test.ts @@ -1,16 +1,15 @@ import { setupTestApp } from '../setup-tests.js'; import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest'; -import { - getSubmissionHandler, - getAllSubmissionsHandler, - deleteSubmissionHandler, createSubmissionHandler -} from '../../src/controllers/submissions.js'; +import { getSubmissionHandler, getAllSubmissionsHandler } from '../../src/controllers/submissions.js'; import { Request, Response } from 'express'; -import {NotFoundException} from "../../src/exceptions/not-found-exception"; -import {getClass01, getClass02} from "../test_assets/classes/classes.testdata"; +import { NotFoundException } from "../../src/exceptions/not-found-exception"; +import { getClass02 } from "../test_assets/classes/classes.testdata"; -function createRequestObject(hruid: string, submissionNumber: string) { +function createRequestObject(hruid: string, submissionNumber: string): { + query: { language: string; version: string }; + params: { hruid: string; id: string } +} { return { params: { hruid: hruid,