NestJS 11 + Fastify 统一错误体与 trace_id,/health 真实探活 DB/Redis,OpenAPI 3.1 契约含 20 个错误码;shared 包提供错误码、权限点、ULID、分页与通用 schema;worker 完成队列进程骨架。
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import { testConfig } from '../testing/test-app';
|
|
import { PrismaService } from './prisma/prisma.service';
|
|
import { RedisService } from './redis/redis.service';
|
|
|
|
describe('PrismaService', () => {
|
|
it('关闭应用时断开 Prisma 连接', async () => {
|
|
const service = new PrismaService(testConfig);
|
|
const disconnect = vi.spyOn(service, '$disconnect').mockResolvedValue();
|
|
await service.onModuleDestroy();
|
|
expect(disconnect).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|
|
|
|
describe('RedisService', () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it('ping 返回 PONG', async () => {
|
|
const service = new RedisService(testConfig);
|
|
const client = service.getClient();
|
|
vi.spyOn(client, 'connect').mockResolvedValue(undefined);
|
|
vi.spyOn(client, 'ping').mockResolvedValue('PONG');
|
|
await expect(service.ping()).resolves.toBe('PONG');
|
|
});
|
|
|
|
it('关闭应用时断开 Redis 连接', () => {
|
|
const service = new RedisService(testConfig);
|
|
const client = service.getClient();
|
|
const disconnect = vi.spyOn(client, 'disconnect').mockReturnValue(undefined);
|
|
service.onModuleDestroy();
|
|
expect(disconnect).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|