Files
persona-lenz/apps/api/src/modules/analysis/bullmq.config.spec.ts
T
2026-07-02 20:40:49 -07:00

55 lines
1.4 KiB
TypeScript

import {
createBullMqOptions,
resolveBullMqRedisConnection,
} from './bullmq.config';
describe('BullMQ config', () => {
it('parses redis URLs into BullMQ connection options', () => {
expect(
resolveBullMqRedisConnection('redis://worker:secret@redis.local:6380/2'),
).toMatchObject({
host: 'redis.local',
port: 6380,
username: 'worker',
password: 'secret',
db: 2,
maxRetriesPerRequest: null,
});
});
it('enables TLS for rediss URLs', () => {
expect(resolveBullMqRedisConnection('rediss://redis.local')).toMatchObject({
host: 'redis.local',
port: 6379,
tls: {},
});
});
it('rejects malformed Redis URLs without an explicit host', () => {
expect(() => resolveBullMqRedisConnection('redis:///0')).toThrow(
'REDIS_URL must include a hostname.',
);
});
it('creates root options from SecretService without exposing secrets', async () => {
const secretService = {
get: jest
.fn<Promise<string>, [string]>()
.mockResolvedValue('redis://localhost:6379/0'),
};
await expect(createBullMqOptions(secretService)).resolves.toMatchObject({
connection: {
host: 'localhost',
port: 6379,
db: 0,
maxRetriesPerRequest: null,
},
defaultJobOptions: {
attempts: 2,
},
});
expect(secretService.get).toHaveBeenCalledWith('REDIS_URL');
});
});