Deleted "message" attribute that was on all JSON responses
This commit is contained in:
parent
c026657e2f
commit
730b8368cd
|
@ -5,10 +5,10 @@ class ImageController {
|
|||
async getAllImages(req: Request, res: Response): Promise<void> {
|
||||
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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 () => {
|
||||
|
|
Loading…
Reference in New Issue