Merge branch 'redisTest' into 'main'
improve redis tests See merge request v3/service/territory!18
This commit is contained in:
commit
15e0e32e2e
12
package.json
12
package.json
|
@ -91,6 +91,9 @@
|
||||||
".controller.ts",
|
".controller.ts",
|
||||||
".module.ts",
|
".module.ts",
|
||||||
".request.ts",
|
".request.ts",
|
||||||
|
".presenter.ts",
|
||||||
|
".profile.ts",
|
||||||
|
".exception.ts",
|
||||||
"main.ts"
|
"main.ts"
|
||||||
],
|
],
|
||||||
"rootDir": "src",
|
"rootDir": "src",
|
||||||
|
@ -101,6 +104,15 @@
|
||||||
"collectCoverageFrom": [
|
"collectCoverageFrom": [
|
||||||
"**/*.(t|j)s"
|
"**/*.(t|j)s"
|
||||||
],
|
],
|
||||||
|
"coveragePathIgnorePatterns": [
|
||||||
|
".controller.ts",
|
||||||
|
".module.ts",
|
||||||
|
".request.ts",
|
||||||
|
".presenter.ts",
|
||||||
|
".profile.ts",
|
||||||
|
".exception.ts",
|
||||||
|
"main.ts"
|
||||||
|
],
|
||||||
"coverageDirectory": "../coverage",
|
"coverageDirectory": "../coverage",
|
||||||
"testEnvironment": "node"
|
"testEnvironment": "node"
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { RedisConfigurationRepository } from '../../adapters/secondaries/redis-configuration.repository';
|
||||||
|
import { getRedisToken } from '@liaoliaots/nestjs-redis';
|
||||||
|
|
||||||
|
const mockRedis = {
|
||||||
|
get: jest.fn().mockResolvedValue('myValue'),
|
||||||
|
set: jest.fn().mockImplementation(),
|
||||||
|
del: jest.fn().mockImplementation(),
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('RedisConfigurationRepository', () => {
|
||||||
|
let redisConfigurationRepository: RedisConfigurationRepository;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: getRedisToken('default'),
|
||||||
|
useValue: mockRedis,
|
||||||
|
},
|
||||||
|
RedisConfigurationRepository,
|
||||||
|
],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
redisConfigurationRepository = module.get<RedisConfigurationRepository>(
|
||||||
|
RedisConfigurationRepository,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(redisConfigurationRepository).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('interact', () => {
|
||||||
|
it('should get a value', async () => {
|
||||||
|
expect(await redisConfigurationRepository.get('myKey')).toBe('myValue');
|
||||||
|
});
|
||||||
|
it('should set a value', async () => {
|
||||||
|
expect(
|
||||||
|
await redisConfigurationRepository.set('myKey', 'myValue'),
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
|
it('should delete a value', async () => {
|
||||||
|
expect(await redisConfigurationRepository.del('myKey')).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue