- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation. - Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings. - Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors. - Fixed unmount lifecycle guards, promise error handling, and component edge cases.
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import { Test, TestingModule } from "@nestjs/testing";
|
|
import { RedisService } from "./redis.service";
|
|
|
|
jest.mock("ioredis", () => {
|
|
return jest.fn().mockImplementation(() => {
|
|
return {
|
|
set: jest.fn(),
|
|
get: jest.fn().mockResolvedValue("mock-value"),
|
|
del: jest.fn(),
|
|
disconnect: jest.fn(),
|
|
};
|
|
});
|
|
});
|
|
|
|
describe("RedisService", () => {
|
|
let service: RedisService;
|
|
|
|
beforeEach(async () => {
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
providers: [RedisService],
|
|
}).compile();
|
|
|
|
service = module.get<RedisService>(RedisService);
|
|
service.onModuleInit();
|
|
});
|
|
|
|
afterEach(() => {
|
|
service.onModuleDestroy();
|
|
});
|
|
|
|
it("should be defined", () => {
|
|
expect(service).toBeDefined();
|
|
});
|
|
|
|
it("should call set with or without ttl", async () => {
|
|
const setSpy = jest.spyOn((service as any).client, "set");
|
|
await service.set("key", "val");
|
|
expect(setSpy).toHaveBeenCalledWith("key", "val");
|
|
|
|
await service.set("key", "val", 60);
|
|
expect(setSpy).toHaveBeenCalledWith("key", "val", "EX", 60);
|
|
});
|
|
|
|
it("should call get", async () => {
|
|
const getSpy = jest.spyOn((service as any).client, "get");
|
|
const result = await service.get("key");
|
|
expect(getSpy).toHaveBeenCalledWith("key");
|
|
expect(result).toBe("mock-value");
|
|
});
|
|
|
|
it("should call del", async () => {
|
|
const delSpy = jest.spyOn((service as any).client, "del");
|
|
await service.del("key");
|
|
expect(delSpy).toHaveBeenCalledWith("key");
|
|
});
|
|
});
|