test: add comprehensive unit tests for core services
Added unit tests for the `api-keys`, `auth`, `categories`, `contents`, `favorites`, `media`, and `purge` services to improve test coverage and ensure core functionality integrity.
This commit is contained in:
42
backend/src/health.controller.spec.ts
Normal file
42
backend/src/health.controller.spec.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user