From 85c5a30789224fc115b2d379977302ac8f6171b6 Mon Sep 17 00:00:00 2001 From: sbriat Date: Wed, 12 Apr 2023 12:05:40 +0200 Subject: [PATCH] improve redis tests --- package.json | 9 ++++ .../redis-configuration.repository.spec.ts | 47 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/modules/configuration/tests/unit/redis-configuration.repository.spec.ts diff --git a/package.json b/package.json index f792b4e..f8a34d6 100644 --- a/package.json +++ b/package.json @@ -101,6 +101,15 @@ "collectCoverageFrom": [ "**/*.(t|j)s" ], + "coveragePathIgnorePatterns": [ + ".controller.ts", + ".module.ts", + ".request.ts", + ".presenter.ts", + ".profile.ts", + ".exception.ts", + "main.ts" + ], "coverageDirectory": "../coverage", "testEnvironment": "node" } diff --git a/src/modules/configuration/tests/unit/redis-configuration.repository.spec.ts b/src/modules/configuration/tests/unit/redis-configuration.repository.spec.ts new file mode 100644 index 0000000..8efa436 --- /dev/null +++ b/src/modules/configuration/tests/unit/redis-configuration.repository.spec.ts @@ -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, + ); + }); + + 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(); + }); + }); +});