24 lines
718 B
TypeScript
24 lines
718 B
TypeScript
|
import { afterAll, afterEach, describe, expect, it, jest, mock, spyOn } from "bun:test";
|
||
|
import app from "src/app";
|
||
|
import request from "supertest";
|
||
|
import * as imageService from "src/services/imageService";
|
||
|
|
||
|
afterAll(() => {
|
||
|
jest.restoreAllMocks();
|
||
|
})
|
||
|
|
||
|
describe("endpoint returns the correct status codes", () => {
|
||
|
it("should return 200 if successful", async () => {
|
||
|
const res = await request(app).get("/image");
|
||
|
expect(res.status).toBe(200);
|
||
|
});
|
||
|
|
||
|
it("should return 500 if any error happens", async () => {
|
||
|
spyOn(imageService, "get").mockImplementation(() => { throw new Error("Controlled error") });
|
||
|
|
||
|
const res = await request(app).get("/image");
|
||
|
|
||
|
expect(res.status).toBe(500);
|
||
|
});
|
||
|
});
|