Skip to content

Commit a3e3294

Browse files
committed
test(add): redis service mocks to test files
1 parent 12de6ab commit a3e3294

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

core-api/src/modules/root/root.service.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { RedisService } from '@/services/redis/redis.service';
2+
import { ConfigService } from '@nestjs/config';
13
import type { TestingModule } from '@nestjs/testing';
24
import { Test } from '@nestjs/testing';
35
import { AiAssistantService } from '../ai-assistant/ai-assistant.service';
@@ -36,6 +38,28 @@ describe('RootService', () => {
3638
}),
3739
},
3840
},
41+
{
42+
provide: ConfigService,
43+
useValue: {
44+
get: jest.fn((key: string) => {
45+
if (key === 'APP_VERSION') return '1.0.0';
46+
if (key === 'NODE_ENV') return 'test';
47+
return null;
48+
}),
49+
},
50+
},
51+
{
52+
provide: RedisService,
53+
useValue: {
54+
get: jest.fn().mockResolvedValue(
55+
JSON.stringify({
56+
tag_name: 'v1.0.0',
57+
body: 'Test release notes',
58+
published_at: '2024-01-01T00:00:00Z',
59+
}),
60+
),
61+
},
62+
},
3963
],
4064
}).compile();
4165

core-api/src/modules/system-configs/system-configs.service.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { RedisService } from '@/services/redis/redis.service';
12
import type { TestingModule } from '@nestjs/testing';
23
import { Test } from '@nestjs/testing';
34
import { getRepositoryToken } from '@nestjs/typeorm';
@@ -22,6 +23,11 @@ describe('SystemConfigsService', () => {
2223
deleteFile: jest.fn(),
2324
};
2425

26+
const mockRedisService = {
27+
get: jest.fn(),
28+
set: jest.fn(),
29+
};
30+
2531
const module: TestingModule = await Test.createTestingModule({
2632
providers: [
2733
SystemConfigsService,
@@ -33,6 +39,10 @@ describe('SystemConfigsService', () => {
3339
provide: StorageService,
3440
useValue: mockStorageService,
3541
},
42+
{
43+
provide: RedisService,
44+
useValue: mockRedisService,
45+
},
3646
],
3747
}).compile();
3848

0 commit comments

Comments
 (0)