37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { afterEach, describe, expect, it, mock } from "bun:test";
|
|
import app from "src/app";
|
|
import ImageService from "src/services/ImageService";
|
|
import request from "supertest";
|
|
|
|
const imageServiceOriginal = ImageService;
|
|
|
|
afterEach(() => {
|
|
mock.restore();
|
|
mock.module("src/services/ImageService", () => ({
|
|
default: imageServiceOriginal,
|
|
}));
|
|
});
|
|
|
|
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 () => {
|
|
mock.module("src/services/ImageService", () => {
|
|
return {
|
|
default: {
|
|
get: () => {
|
|
throw new Error("Controlled error");
|
|
},
|
|
},
|
|
};
|
|
});
|
|
const res = await request(app).get("/image");
|
|
expect(res.status).toBe(500);
|
|
});
|
|
});
|