import { describe, expect, it } from 'vitest';
import { toDisplayRole, enumRolesForDisplay, normalizeAssignableRole, isOwnerRole, roleRank, permissionsForRole, ASSIGNABLE_ROLES, } from '../../auth/roles.js';
describe('role display mapping', () => {
    it('maps legacy roles to product display roles', () => {
        expect(toDisplayRole('OWNER')).toBe('Owner');
        expect(toDisplayRole('ADMIN')).toBe('Admin');
        expect(toDisplayRole('EDITOR')).toBe('Editor');
        expect(toDisplayRole('AUTHOR')).toBe('Editor');
        expect(toDisplayRole('CLIENT')).toBe('Viewer');
        expect(toDisplayRole('VIEWER')).toBe('Viewer');
        expect(toDisplayRole('garbage')).toBe('Viewer');
    });
    it('maps a display filter to the enum values it covers', () => {
        expect(enumRolesForDisplay('Editor')).toEqual(['EDITOR', 'AUTHOR']);
        expect(enumRolesForDisplay('Viewer')).toEqual(['VIEWER', 'CLIENT']);
        expect(enumRolesForDisplay('Owner')).toEqual(['OWNER']);
        expect(enumRolesForDisplay('all')).toBeNull();
    });
});
describe('assignable roles', () => {
    it('only allows the four product roles', () => {
        expect(ASSIGNABLE_ROLES).toEqual(['OWNER', 'ADMIN', 'EDITOR', 'VIEWER']);
        expect(normalizeAssignableRole('admin')).toBe('ADMIN');
        expect(normalizeAssignableRole('AUTHOR')).toBeNull();
        expect(normalizeAssignableRole('CLIENT')).toBeNull();
        expect(normalizeAssignableRole('nope')).toBeNull();
    });
});
describe('role rank + owner check', () => {
    it('ranks Owner above Admin above Editor above Viewer', () => {
        expect(roleRank('OWNER')).toBeGreaterThan(roleRank('ADMIN'));
        expect(roleRank('ADMIN')).toBeGreaterThan(roleRank('EDITOR'));
        expect(roleRank('EDITOR')).toBeGreaterThan(roleRank('VIEWER'));
        expect(roleRank('AUTHOR')).toBe(roleRank('EDITOR'));
    });
    it('detects the Owner role', () => {
        expect(isOwnerRole('OWNER')).toBe(true);
        expect(isOwnerRole('owner')).toBe(true);
        expect(isOwnerRole('ADMIN')).toBe(false);
    });
});
describe('permissions for role', () => {
    it('grants Owner everything and Admin everything except owner-only scopes', () => {
        expect(permissionsForRole('OWNER')).toContain('billing.manage');
        expect(permissionsForRole('OWNER')).toContain('workspace.delete');
        const admin = permissionsForRole('ADMIN');
        expect(admin).toContain('users.invite');
        expect(admin).not.toContain('billing.manage');
        expect(admin).not.toContain('workspace.delete');
    });
    it('limits Editor to content and Viewer to read-only', () => {
        const editor = permissionsForRole('EDITOR');
        expect(editor).toContain('content.publish');
        expect(editor).not.toContain('users.invite');
        expect(editor).not.toContain('settings.manage');
        expect(permissionsForRole('VIEWER')).toEqual(['dashboard.view', 'content.view']);
        expect(permissionsForRole('AUTHOR')).toEqual(permissionsForRole('EDITOR'));
    });
});
//# sourceMappingURL=roles.test.js.map