unit testing #7

Merged
Suguivy merged 67 commits from testing into develop 2023-12-31 11:11:23 +00:00
2 changed files with 16 additions and 1 deletions
Showing only changes of commit 76d5764616 - Show all commits

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