v1.0.0 #28

Merged
bizcochito merged 147 commits from develop into main 2024-01-14 19:49:34 +00:00
3 changed files with 9 additions and 9 deletions
Showing only changes of commit 730b8368cd - Show all commits

View File

@ -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 });
}
}
}

View File

@ -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);

View File

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