import assert from 'node:assert/strict' import { test } from 'node:test' import { allowed, can } from '../src/hooks.js' const held = new Set(['reports.view', 'catalog.menu.manage']) test('one key', () => { assert.equal(can(held, 'reports.view'), true) assert.equal(can(held, 'core.staff.manage'), false) }) test('a list means any of them (like require_any), or all with all=true', () => { assert.equal(can(held, ['core.staff.manage', 'reports.view']), true) assert.equal(can(held, ['core.staff.manage', 'reports.view'], true), false) assert.equal(can(held, ['reports.view', 'catalog.menu.manage'], true), true) }) test('an empty list asks for nothing', () => { assert.equal(can(new Set(), []), true) }) test('allowed: held, a manager may approve, or no (plan step 4.3)', () => { const approvable = new Set(['ordering.orders.cancel']) assert.equal(allowed(held, approvable, 'reports.view'), 'yes') assert.equal(allowed(held, approvable, 'ordering.orders.cancel'), 'approve') assert.equal(allowed(held, approvable, 'pricing.discounts.apply'), 'no') assert.equal(allowed(held, undefined, 'ordering.orders.cancel'), 'no') })