diff --git a/src/controllers/ImageController.ts b/src/controllers/ImageController.ts index 1b24a08..58c2a92 100644 --- a/src/controllers/ImageController.ts +++ b/src/controllers/ImageController.ts @@ -5,10 +5,10 @@ class ImageController { async getAllImages(req: Request, res: Response): Promise { try { const images = await imageService.findAll(); - res.json({ message: images }); + res.json({ images }); } catch (error) { console.error(error); - res.status(500).json({ message: "Internal Server Error" }); + res.status(500).json({ error: "Internal Server Error" }); } } @@ -18,14 +18,14 @@ class ImageController { // Thowing a 401 if not auth provided // Throwing a 403 for incorrect auth const image = await imageService.add(req.body); - res.status(201).json({ message: image }); + res.status(201).json({ image }); } catch (error: any) { if (error.code === 11000) { // Should return 409 Conflict for existing urls - res.status(409).json({ message: "Existing URL" }); + res.status(409).json({ error: "Existing URL" }); } // Should return 400 Bad request for invalid requests - res.status(400).json({ message: error }); + res.status(400).json({ error: error }); } } } diff --git a/src/index.ts b/src/index.ts index 8113fb9..9dff064 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,7 +9,7 @@ app.use(express.json()); app.get("/", (_, res) => { const endpoints = listEndpoints(app); - res.json({ message: endpoints }); + res.json({ endpoints }); }); app.get("/images", imageController.getAllImages); diff --git a/tests/app.test.ts b/tests/app.test.ts index 895542c..f8ec9f4 100644 --- a/tests/app.test.ts +++ b/tests/app.test.ts @@ -6,11 +6,11 @@ describe("GET / shows all of the endpoints", async () => { const res = await request(app).get("/"); it("should be", async () => { - expect(res.body).toHaveProperty("message"); + expect(res.body).toHaveProperty("endpoints"); }); it("should be an array", () => { - expect(Array.isArray(res.body.message)).toBeTrue(); + expect(Array.isArray(res.body.endpoints)).toBeTrue(); }) }) @@ -18,7 +18,7 @@ describe("GET /images works properly", async () => { const res = await request(app).get("/images"); it("should be an array", () => { - expect(Array.isArray(res.body.message)).toBeTrue(); + expect(Array.isArray(res.body.images)).toBeTrue(); }); it("should return a 200", async () => {