- Updated package dependencies to include `@sentry/node` for error tracking. - Refactored command routing to incorporate user and guild blacklisting checks, improving command execution safety. - Enhanced health server metrics to include queue waiting times, providing better insights into system performance. - Introduced confirmation handling for guild backup commands, streamlining user interactions. - Improved moderation commands with better error handling and case management, ensuring robust moderation capabilities. - Added new duration parsing functions to handle timeout durations effectively, enhancing moderation features. - Updated localization files to reflect new command structures and user guidance improvements.
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import type { Redis } from 'ioredis';
|
|
import {
|
|
deleteConfirmation,
|
|
getConfirmation,
|
|
setConfirmation,
|
|
takeConfirmation
|
|
} from './confirmation-store.js';
|
|
|
|
function createMemoryRedis(): Redis {
|
|
const store = new Map<string, string>();
|
|
return {
|
|
async set(key: string, value: string) {
|
|
store.set(key, value);
|
|
return 'OK';
|
|
},
|
|
async get(key: string) {
|
|
return store.get(key) ?? null;
|
|
},
|
|
async del(key: string) {
|
|
store.delete(key);
|
|
return 1;
|
|
}
|
|
} as unknown as Redis;
|
|
}
|
|
|
|
describe('confirmation-store', () => {
|
|
it('stores and retrieves pending confirmations', async () => {
|
|
const redis = createMemoryRedis();
|
|
await setConfirmation(redis, 'moderation', 'tok-1', { action: 'ban', userId: '1' }, 60);
|
|
await expect(getConfirmation(redis, 'moderation', 'tok-1')).resolves.toEqual({
|
|
action: 'ban',
|
|
userId: '1'
|
|
});
|
|
});
|
|
|
|
it('takeConfirmation deletes the entry', async () => {
|
|
const redis = createMemoryRedis();
|
|
await setConfirmation(redis, 'moderation', 'tok-2', { action: 'purge' }, 60);
|
|
await expect(takeConfirmation(redis, 'moderation', 'tok-2')).resolves.toEqual({
|
|
action: 'purge'
|
|
});
|
|
await expect(getConfirmation(redis, 'moderation', 'tok-2')).resolves.toBeNull();
|
|
});
|
|
|
|
it('deleteConfirmation removes pending state', async () => {
|
|
const redis = createMemoryRedis();
|
|
await setConfirmation(redis, 'guildbackup', 'tok-3', { action: 'delete' }, 60);
|
|
await deleteConfirmation(redis, 'guildbackup', 'tok-3');
|
|
await expect(getConfirmation(redis, 'guildbackup', 'tok-3')).resolves.toBeNull();
|
|
});
|
|
});
|