added test coverage to image controler
Unit Tests with docker compose / unit-test (pull_request) Failing after 7m32s Details

This commit is contained in:
Alie 2023-12-29 19:47:35 +01:00
parent 9cd61c101c
commit 76d5764616
2 changed files with 16 additions and 1 deletions

View File

@ -3,7 +3,7 @@ import imageService from "../services/ImageService";
import mongoose, { mongo } from "mongoose";
class ImageController {
async getAllImages(req: Request, res: Response): Promise<void> {
async getAllImages(_: Request, res: Response): Promise<void> {
try {
const images = await imageService.findAll();
res.json({ images });

View File

@ -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", () => {