wulf-pulse/lib/permissions.test.ts

26 lines
941 B
TypeScript
Raw Permalink Normal View History

import { describe, it, expect } from 'vitest';
import { hasPermission } from './permissions';
describe('hasPermission', () => {
it('returns false (not a crash) for a "user" role on an admin-only resource', () => {
expect(() => hasPermission('user', 'admin', 'access')).not.toThrow();
expect(hasPermission('user', 'admin', 'access')).toBe(false);
});
it('returns true for "admin" role on an admin-gated resource', () => {
expect(hasPermission('admin', 'admin', 'access')).toBe(true);
});
it('returns true for "super-admin" role on an admin-gated resource', () => {
expect(hasPermission('super-admin', 'admin', 'access')).toBe(true);
});
it('returns true for "user" role on a permitted resource', () => {
expect(hasPermission('user', 'tickets', 'read')).toBe(true);
});
it('returns false for an unknown role', () => {
expect(hasPermission('bogus-role', 'admin', 'access')).toBe(false);
});
});