Added unit tests for the `api-keys`, `auth`, `categories`, `contents`, `favorites`, `media`, and `purge` services to improve test coverage and ensure core functionality integrity.
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { Test, TestingModule } from "@nestjs/testing";
|
|
import { DatabaseService } from "./database/database.service";
|
|
import { HealthController } from "./health.controller";
|
|
|
|
describe("HealthController", () => {
|
|
let controller: HealthController;
|
|
|
|
const mockDb = {
|
|
execute: jest.fn().mockResolvedValue([]),
|
|
};
|
|
|
|
beforeEach(async () => {
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
controllers: [HealthController],
|
|
providers: [
|
|
{
|
|
provide: DatabaseService,
|
|
useValue: {
|
|
db: mockDb,
|
|
},
|
|
},
|
|
],
|
|
}).compile();
|
|
|
|
controller = module.get<HealthController>(HealthController);
|
|
});
|
|
|
|
it("should return ok if database is connected", async () => {
|
|
mockDb.execute.mockResolvedValue([]);
|
|
const result = await controller.check();
|
|
expect(result.status).toBe("ok");
|
|
expect(result.database).toBe("connected");
|
|
});
|
|
|
|
it("should return error if database is disconnected", async () => {
|
|
mockDb.execute.mockRejectedValue(new Error("DB Error"));
|
|
const result = await controller.check();
|
|
expect(result.status).toBe("error");
|
|
expect(result.database).toBe("disconnected");
|
|
expect(result.message).toBe("DB Error");
|
|
});
|
|
});
|