Files
canina/backend/src/redis/redis.service.spec.ts
T
devops ddbf1ca026
Deploy Canina / deploy (push) Successful in 4m1s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 7s
test: comprehensive test suites and quality gates pass across backend, storefront and admin
- 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.
2026-10-13 16:01:00 +00:00

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