Skip to content

Commit

Permalink
Remove more FakeCacheService usages
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorgomezv committed Oct 14, 2024
1 parent f30a76d commit ad5c33e
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/__tests__/redis-client.factory.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import type { RedisClientType } from 'redis';
import { createClient } from 'redis';

export async function redisClientFactory(): Promise<RedisClientType> {
export async function redisClientFactory(
database?: number,
): Promise<RedisClientType> {
const { REDIS_HOST = 'localhost', REDIS_PORT = 6379 } = process.env;
const client: RedisClientType = createClient({
url: `redis://${REDIS_HOST}:${REDIS_PORT}`,
...(database ? { database: database } : {}),
});
await client.connect();
return client;
Expand Down
4 changes: 3 additions & 1 deletion src/datasources/accounts/accounts.datasource.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ describe('AccountsDatasource tests', () => {
const testDbFactory = new TestDbFactory();

beforeAll(async () => {
redisClient = await redisClientFactory();
redisClient = await redisClientFactory(
faker.number.int({ min: 1, max: 10 }),
);
redisCacheService = new RedisCacheService(
redisClient,
mockLoggingService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ describe('CounterfactualSafesDatasource tests', () => {
const testDbFactory = new TestDbFactory();

beforeAll(async () => {
redisClient = await redisClientFactory();
redisClient = await redisClientFactory(
faker.number.int({ min: 1, max: 10 }),
);
redisCacheService = new RedisCacheService(
redisClient,
mockLoggingService,
Expand Down
4 changes: 3 additions & 1 deletion src/datasources/blockchain/blockchain-api.manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ describe('BlockchainApiManager', () => {
const expirationTimeInSeconds = faker.number.int();

beforeAll(async () => {
redisClient = await redisClientFactory();
redisClient = await redisClientFactory(
faker.number.int({ min: 1, max: 10 }),
);
redisCacheService = new RedisCacheService(
redisClient,
mockLoggingService,
Expand Down
5 changes: 3 additions & 2 deletions src/datasources/cache/redis.cache.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ describe('RedisCacheService', () => {
let defaultExpirationTimeInSeconds: number;
const keyPrefix = '';
let redisClient: RedisClientType;
const redisDatabase = faker.number.int({ min: 1, max: 10 });

beforeAll(async () => {
redisClient = await redisClientFactory();
redisClient = await redisClientFactory(redisDatabase);
});

afterAll(async () => {
Expand Down Expand Up @@ -144,7 +145,7 @@ describe('RedisCacheService', () => {
// Connection is closed, this is expected to throw an error
await expect(redisCacheService.ping()).rejects.toThrow();
// Connection is reopened after this test execution
redisClient = await redisClientFactory();
redisClient = await redisClientFactory(redisDatabase);
});

it('creates a missing key and increments its value', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ describe('FirebaseCloudMessagingApiService', () => {
let pushNotificationsServiceAccountPrivateKey: string;

beforeAll(async () => {
redisClient = await redisClientFactory();
redisClient = await redisClientFactory(
faker.number.int({ min: 1, max: 10 }),
);
redisCacheService = new RedisCacheService(
redisClient,
mockLoggingService,
Expand Down
5 changes: 4 additions & 1 deletion src/routes/contracts/__tests__/get-contract.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { redisClientFactory } from '@/__tests__/redis-client.factory';
import { TestAppProvider } from '@/__tests__/test-app.provider';
import { CacheKeyPrefix } from '@/datasources/cache/constants';
import type { Server } from 'net';
import { faker } from '@faker-js/faker';

describe('Get contract e2e test', () => {
let app: INestApplication<Server>;
Expand All @@ -24,7 +25,9 @@ describe('Get contract e2e test', () => {

app = await new TestAppProvider().provide(moduleRef);
await app.init();
redisClient = await redisClientFactory();
redisClient = await redisClientFactory(
faker.number.int({ min: 1, max: 10 }),
);
});

afterAll(async () => {
Expand Down
4 changes: 3 additions & 1 deletion src/routes/hooks/__tests__/event-hooks-queue.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ describe('Events queue processing e2e tests', () => {

app = await new TestAppProvider().provide(moduleRef);
await app.init();
redisClient = await redisClientFactory();
redisClient = await redisClientFactory(
faker.number.int({ min: 1, max: 10 }),
);
const amqpClient = amqpClientFactory(queue);
channel = amqpClient.channel;
queueName = amqpClient.queueName;
Expand Down
5 changes: 4 additions & 1 deletion src/routes/owners/__tests__/get-safes-by-owner.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { redisClientFactory } from '@/__tests__/redis-client.factory';
import { CacheKeyPrefix } from '@/datasources/cache/constants';
import type { Server } from 'net';
import { TEST_SAFE } from '@/routes/common/__tests__/constants';
import { faker } from '@faker-js/faker';

describe('Get safes by owner e2e test', () => {
let app: INestApplication<Server>;
Expand All @@ -23,7 +24,9 @@ describe('Get safes by owner e2e test', () => {

app = moduleRef.createNestApplication();
await app.init();
redisClient = await redisClientFactory();
redisClient = await redisClientFactory(
faker.number.int({ min: 1, max: 10 }),
);
});

afterAll(async () => {
Expand Down
5 changes: 4 additions & 1 deletion src/routes/safe-apps/__tests__/get-safe-apps.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { redisClientFactory } from '@/__tests__/redis-client.factory';
import { CacheKeyPrefix } from '@/datasources/cache/constants';
import type { SafeApp } from '@/routes/safe-apps/entities/safe-app.entity';
import type { Server } from 'net';
import { faker } from '@faker-js/faker';

describe('Get Safe Apps e2e test', () => {
let app: INestApplication<Server>;
Expand All @@ -25,7 +26,9 @@ describe('Get Safe Apps e2e test', () => {

app = await new TestAppProvider().provide(moduleRef);
await app.init();
redisClient = await redisClientFactory();
redisClient = await redisClientFactory(
faker.number.int({ min: 1, max: 10 }),
);
});

afterAll(async () => {
Expand Down

0 comments on commit ad5c33e

Please sign in to comment.