Files
5chan/src/lib/utils/__tests__/mod-access.test.ts
T
Tommaso CasaburiandGitHub fd9ab19de3 fix(mod-queue): show board button from live roles (#1079)
* fix(mod-queue): show board button from live roles

* fix(mod-queue): require live role for board access
2026-03-13 16:37:57 +08:00

62 lines
1.9 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { canAccessBoardModQueue, hasModQueueAccessRole } from '../mod-access';
describe('hasModQueueAccessRole', () => {
it('accepts board moderation roles', () => {
expect(hasModQueueAccessRole('owner')).toBe(true);
expect(hasModQueueAccessRole('admin')).toBe(true);
expect(hasModQueueAccessRole('moderator')).toBe(true);
});
it('rejects missing and unrelated roles', () => {
expect(hasModQueueAccessRole(undefined)).toBe(false);
expect(hasModQueueAccessRole('viewer')).toBe(false);
});
});
describe('canAccessBoardModQueue', () => {
it('allows access to the global queue when at least one moderated board is cached', () => {
expect(
canAccessBoardModQueue({
accountCommunityAddresses: ['music-posting.eth'],
}),
).toBe(true);
});
it('rejects access to the global queue when no moderated boards are cached', () => {
expect(
canAccessBoardModQueue({
accountCommunityAddresses: [],
}),
).toBe(false);
});
it('allows access when the current board role is moderator even without cached board membership', () => {
expect(
canAccessBoardModQueue({
boardAddress: '12D3KooWNFgjQWX2EUEs7pixdjkWSLh21EZ9NeYnV8iMaCyYhLGJ',
accountCommunityAddresses: [],
accountRole: 'moderator',
}),
).toBe(true);
});
it('rejects board-scoped access when only the cached moderated board matches by alias', () => {
expect(
canAccessBoardModQueue({
boardAddress: 'music-posting.eth',
accountCommunityAddresses: ['music-posting.bso'],
}),
).toBe(false);
});
it('rejects access when neither the role nor moderated board list matches', () => {
expect(
canAccessBoardModQueue({
boardAddress: 'music-posting.eth',
accountCommunityAddresses: ['tech-posting.eth'],
}),
).toBe(false);
});
});