Files
discord.js/packages/brokers/__tests__/index.test.ts
DD 393ded4ea1 refactor(brokers): make option props more correct (#10242)
* refactor(brokers): make option props more correct

BREAKING CHANGE: Classes now take redis client as standalone parameter, various props from the base option interface moved to redis options

* chore: update comment

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2024-05-11 15:54:06 +00:00

24 lines
582 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(mockRedisClient, { encode });
await broker.publish('test', 'test');
expect(encode).toHaveBeenCalledWith('test');
});