v1.0.0 #28
|
@ -166,7 +166,6 @@ describe("POST /images works properly", () => {
|
|||
});
|
||||
|
||||
it("should return 400 for malformed requests", async () => {
|
||||
mock.restore();
|
||||
const res = await request(app)
|
||||
.post("/images")
|
||||
.set("authorization", `Bearer ${token}`)
|
||||
|
@ -180,17 +179,22 @@ describe("POST /images works properly", () => {
|
|||
});
|
||||
|
||||
describe("GET /images/<id> works properly", () => {
|
||||
let id: string;
|
||||
let list: Image[];
|
||||
beforeAll(async () => {
|
||||
const res = await request(app).get("/images");
|
||||
list = res.body.images;
|
||||
id = list[0]._id;
|
||||
});
|
||||
|
||||
it("should return 200 for existing ids", async () => {
|
||||
const list = await request(app).get("/images");
|
||||
const id = list.body.images[0]._id;
|
||||
const res = await request(app).get(`/images/${id}`);
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
|
||||
it("should return 404 for non-existing ids", async () => {
|
||||
const list = await request(app).get("/images");
|
||||
const id = "000000000000000000000000"; // this was the least posible to exist ID
|
||||
if (!(id in list.body.images)) {
|
||||
if (!(id in list)) {
|
||||
const res = await request(app).get(`/images/${id}`);
|
||||
expect(res.status).toBe(404);
|
||||
}
|
||||
|
@ -286,4 +290,23 @@ describe("PUT /images/<id> works properly", () => {
|
|||
.send({ status: "available" });
|
||||
expect(res.status).toBe(403);
|
||||
});
|
||||
|
||||
it("should have its changes be reflected onto the DB", async () => {
|
||||
const image = await request(app)
|
||||
.post("/images")
|
||||
.set("authorization", `Bearer ${token}`)
|
||||
.send({
|
||||
url: "https://test.url.com/5",
|
||||
status: "available",
|
||||
tags: ["2girls", "touhou"],
|
||||
});
|
||||
const id = image.body.image._id;
|
||||
await request(app)
|
||||
.put(`/images/${id}`)
|
||||
.set("authorization", `Bearer ${token}`)
|
||||
.send({ status: "consumed" });
|
||||
|
||||
const res = await request(app).get(`/images/${id}`);
|
||||
expect(res.body.image).toHaveProperty("status", "consumed");
|
||||
})
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue