mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 08:03:30 +01:00
24 lines
595 B
TypeScript
24 lines
595 B
TypeScript
import type Redis from 'ioredis';
|
|
import { test, expect, vi } from 'vitest';
|
|
import { PubSubRedisBroker } from '../src/index.js';
|
|
|
|
vi.mock('node:fs', () => {
|
|
return {
|
|
readFileSync: vi.fn(),
|
|
};
|
|
});
|
|
|
|
const mockRedisClient = {
|
|
defineCommand: vi.fn(),
|
|
xadd: vi.fn(),
|
|
duplicate: vi.fn(() => mockRedisClient),
|
|
} as unknown as Redis;
|
|
|
|
test('pubsub with custom encoding', async () => {
|
|
const encode = vi.fn((data) => data);
|
|
|
|
const broker = new PubSubRedisBroker({ redisClient: mockRedisClient, encode });
|
|
await broker.publish('test', 'test');
|
|
expect(encode).toHaveBeenCalledWith('test');
|
|
});
|