Skip to content

Commit caecaa0

Browse files
committed
Create static.factory.spec.ts
1 parent 829c03f commit caecaa0

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/static/static.factory.spec.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { ConfigService } from '@nestjs/config';
3+
import { StaticFactoryService } from './static.factory';
4+
import { HddService } from './hdd/hdd.service';
5+
import { AWSS3Service } from './aws/s3.service';
6+
7+
describe('StaticFactoryService', () => {
8+
let service: StaticFactoryService;
9+
let configService: ConfigService;
10+
11+
beforeEach(async () => {
12+
const module: TestingModule = await Test.createTestingModule({
13+
providers: [
14+
StaticFactoryService,
15+
{
16+
provide: ConfigService,
17+
useValue: {
18+
get: jest.fn(),
19+
},
20+
},
21+
],
22+
}).compile();
23+
24+
service = module.get<StaticFactoryService>(StaticFactoryService);
25+
configService = module.get<ConfigService>(ConfigService);
26+
});
27+
28+
it('should be defined', () => {
29+
expect(service).toBeDefined();
30+
});
31+
32+
it('should return HddService when STATIC_SERVICE is hdd', () => {
33+
jest.spyOn(configService, 'get').mockReturnValue('hdd');
34+
const result = service.getStaticService();
35+
expect(result).toBeInstanceOf(HddService);
36+
});
37+
38+
it('should return AWSS3Service when STATIC_SERVICE is s3', () => {
39+
jest.spyOn(configService, 'get').mockReturnValue('s3');
40+
const result = service.getStaticService();
41+
expect(result).toBeInstanceOf(AWSS3Service);
42+
});
43+
44+
it('should return HddService by default when STATIC_SERVICE is not set', () => {
45+
jest.spyOn(configService, 'get').mockReturnValue(undefined);
46+
const result = service.getStaticService();
47+
expect(result).toBeInstanceOf(HddService);
48+
});
49+
});

0 commit comments

Comments
 (0)