From 76d576461624d18c233b4fa5a9d1914f26339aa9 Mon Sep 17 00:00:00 2001 From: Alie Date: Fri, 29 Dec 2023 19:47:35 +0100 Subject: [PATCH] added test coverage to image controler --- src/controllers/ImageController.ts | 2 +- tests/app.test.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/controllers/ImageController.ts b/src/controllers/ImageController.ts index e60bfea..8c78e99 100644 --- a/src/controllers/ImageController.ts +++ b/src/controllers/ImageController.ts @@ -3,7 +3,7 @@ import imageService from "../services/ImageService"; import mongoose, { mongo } from "mongoose"; class ImageController { - async getAllImages(req: Request, res: Response): Promise { + async getAllImages(_: Request, res: Response): Promise { try { const images = await imageService.findAll(); res.json({ images }); diff --git a/tests/app.test.ts b/tests/app.test.ts index 0e8fbda..7d8fbb9 100644 --- a/tests/app.test.ts +++ b/tests/app.test.ts @@ -83,6 +83,21 @@ describe("GET /images works properly", async () => { it("should return a 200", async () => { expect(res.statusCode).toBe(200); }); + + it("should return 500 for an error on the service", async () => { + mock.module("../src/services/ImageService", () => ({ + default: { + add: () => { + throw new Error("This is an expected testing error"); + }, + }, + })); + + const res = await request(app) + .get("/images"); + + expect(res.status).toBe(500); + }); }); describe("POST /images works properly", () => {