2024-04-21 10:53:04 +00:00
|
|
|
import { afterEach, describe, expect, it, jest, spyOn } from "bun:test";
|
2024-04-17 17:23:39 +00:00
|
|
|
import app from "src/app";
|
2024-04-21 09:49:55 +00:00
|
|
|
import * as imageService from "src/services/imageService";
|
2024-04-21 10:53:04 +00:00
|
|
|
import request from "supertest";
|
2024-04-15 08:54:01 +00:00
|
|
|
|
2024-04-21 10:49:38 +00:00
|
|
|
afterEach(() => {
|
2024-04-21 09:49:55 +00:00
|
|
|
jest.restoreAllMocks();
|
|
|
|
})
|
2024-04-15 08:54:01 +00:00
|
|
|
|
|
|
|
describe("endpoint returns the correct status codes", () => {
|
2024-04-17 18:04:43 +00:00
|
|
|
it("should return 200 if successful", async () => {
|
|
|
|
const res = await request(app).get("/image");
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
});
|
2024-04-15 08:54:01 +00:00
|
|
|
|
2024-04-17 18:04:43 +00:00
|
|
|
it("should return 500 if any error happens", async () => {
|
2024-04-21 09:49:55 +00:00
|
|
|
spyOn(imageService, "get").mockImplementation(() => { throw new Error("Controlled error") });
|
|
|
|
|
2024-04-17 18:04:43 +00:00
|
|
|
const res = await request(app).get("/image");
|
2024-04-21 09:49:55 +00:00
|
|
|
|
2024-04-17 18:04:43 +00:00
|
|
|
expect(res.status).toBe(500);
|
|
|
|
});
|
|
|
|
});
|