Files
lolympus-tournament-support/apps/api/src/modules/global/redis/redis.config.spec.ts
T

60 lines
1.6 KiB
TypeScript

import {
assertDistinctRedisInstances,
normalizeRedisUrl,
resolveRedisClientOptions,
} from './redis.config';
describe('redis.config', () => {
it('normalizes host:port endpoints into redis URLs', () => {
expect(normalizeRedisUrl('127.0.0.1:6379', 'REDIS_ENDPOINT')).toBe(
'redis://127.0.0.1:6379',
);
expect(normalizeRedisUrl('rediss://cache.example.com:6380')).toBe(
'rediss://cache.example.com:6380',
);
});
it('throws a clear error for empty endpoints', () => {
expect(() => normalizeRedisUrl(' ', 'REDIS_ENDPOINT')).toThrow(
'REDIS_ENDPOINT cannot be empty',
);
});
it('keeps credentials optional when resolving client options', () => {
expect(
resolveRedisClientOptions({
endpoint: 'redis.internal:6379',
username: '',
password: undefined,
endpointEnvName: 'REDIS_ENDPOINT',
}),
).toEqual({
url: 'redis://redis.internal:6379',
});
});
it('rejects auction Redis when it points at the same physical Redis instance', () => {
expect(() =>
assertDistinctRedisInstances(
'redis://cache.internal:6379/0',
'redis://cache.internal:6379/1',
),
).toThrow('AUCTION_REDIS must use a separate Redis instance');
});
it('allows different Redis hosts or ports', () => {
expect(() =>
assertDistinctRedisInstances(
'redis://cache.internal:6379',
'redis://auction.internal:6379',
),
).not.toThrow();
expect(() =>
assertDistinctRedisInstances(
'redis://cache.internal:6379',
'redis://cache.internal:6380',
),
).not.toThrow();
});
});