roles.test.ts43 lines · main
| 1 | import { describe, expect, test } from 'bun:test'; |
| 2 | |
| 3 | import { |
| 4 | assignBrivenEngineRole, |
| 5 | createBrivenEngineRole, |
| 6 | getBrivenEngineUserRoles, |
| 7 | listBrivenEngineRoles, |
| 8 | userHasPermission, |
| 9 | } from './roles.js'; |
| 10 | |
| 11 | /** |
| 12 | * Phase 6 — roles service closed when engine not bootstrapped. |
| 13 | * Full create/list/assign runs in local Doltgres proof (engine init). |
| 14 | */ |
| 15 | describe('briven-engine roles (Phase 6, engine off)', () => { |
| 16 | test('list returns empty shell when engine not ready', async () => { |
| 17 | const r = await listBrivenEngineRoles(); |
| 18 | expect(r.engine).toBe('briven-engine'); |
| 19 | expect(r.storage).toBe('doltgres'); |
| 20 | expect(Array.isArray(r.roles)).toBe(true); |
| 21 | }); |
| 22 | |
| 23 | test('create fails closed when engine not ready', async () => { |
| 24 | const r = await createBrivenEngineRole('admin', ['read']); |
| 25 | expect(r.ok).toBe(false); |
| 26 | expect(r.engine).toBe('briven-engine'); |
| 27 | }); |
| 28 | |
| 29 | test('assign fails closed when engine not ready', async () => { |
| 30 | const r = await assignBrivenEngineRole('beu_x', 'admin'); |
| 31 | expect(r.ok).toBe(false); |
| 32 | }); |
| 33 | |
| 34 | test('user roles empty when engine not ready', async () => { |
| 35 | const r = await getBrivenEngineUserRoles('beu_x'); |
| 36 | expect(r.roles).toEqual([]); |
| 37 | expect(r.permissions).toEqual([]); |
| 38 | }); |
| 39 | |
| 40 | test('userHasPermission false when engine not ready', async () => { |
| 41 | expect(await userHasPermission('beu_x', 'read')).toBe(false); |
| 42 | }); |
| 43 | }); |