v1.0.0 #28
|
@ -3,7 +3,7 @@ import imageService from "../services/ImageService";
|
||||||
import mongoose, { mongo } from "mongoose";
|
import mongoose, { mongo } from "mongoose";
|
||||||
|
|
||||||
class ImageController {
|
class ImageController {
|
||||||
async getAllImages(req: Request, res: Response): Promise<void> {
|
async getAllImages(_: Request, res: Response): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const images = await imageService.findAll();
|
const images = await imageService.findAll();
|
||||||
res.json({ images });
|
res.json({ images });
|
||||||
|
|
|
@ -83,6 +83,21 @@ describe("GET /images works properly", async () => {
|
||||||
it("should return a 200", async () => {
|
it("should return a 200", async () => {
|
||||||
expect(res.statusCode).toBe(200);
|
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", () => {
|
describe("POST /images works properly", () => {
|
||||||
|
|
Loading…
Reference in New Issue