fe-middleware/test/ImageController/ImageController.test.ts

26 lines
861 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 () => {
// Can't mock ImageService partially because of bun incomplete implementation of testing :(
// It goes to the network directly to test
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);
});
});