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:
Mathis HERRIOT
2026-01-08 16:22:23 +01:00
parent cc2823db7d
commit 399bdab86c
13 changed files with 1502 additions and 0 deletions

View 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");
});
});