74 lines
2.6 KiB
JavaScript
74 lines
2.6 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import {
|
|
ADMIN_NAVIGATION,
|
|
firstAuthorizedPath,
|
|
isNavigationAllowed,
|
|
pathForMenu,
|
|
resolveAuthorizedPath
|
|
} from '../src/navigation.mjs';
|
|
|
|
assert.deepEqual(
|
|
ADMIN_NAVIGATION.map(({ path }) => path),
|
|
['/reports', '/overview', '/stores', '/orders', '/products', '/notifications', '/payments', '/third-party', '/people',
|
|
'/cleaning', '/devices', '/apps', '/content', '/franchise', '/system']
|
|
);
|
|
assert.equal(pathForMenu('platformApps'), '/apps');
|
|
assert.equal(pathForMenu('thirdParty'), '/third-party');
|
|
assert.equal(pathForMenu('products'), '/products');
|
|
assert.equal(pathForMenu('notifications'), '/notifications');
|
|
assert.equal(pathForMenu('reports'), '/reports');
|
|
|
|
const storeOperator = {
|
|
roles: ['STORE_ADMIN'],
|
|
capabilities: ['store.operation.read'],
|
|
menus: ['overview', 'stores', 'orders', 'thirdParty']
|
|
};
|
|
assert.equal(resolveAuthorizedPath(storeOperator, 'orders'), '/orders');
|
|
assert.equal(resolveAuthorizedPath(storeOperator, 'system'), '/overview');
|
|
assert.equal(firstAuthorizedPath(storeOperator), '/overview');
|
|
|
|
const goodsOperator = {
|
|
roles: ['STAFF'],
|
|
capabilities: ['goods.order.read'],
|
|
menus: ['products']
|
|
};
|
|
assert.equal(resolveAuthorizedPath(goodsOperator, 'products'), '/products');
|
|
assert.equal(firstAuthorizedPath(goodsOperator), '/products');
|
|
|
|
const notificationOperator = {
|
|
roles: ['STORE_ADMIN'], capabilities: ['notification.read'], menus: ['notifications']
|
|
};
|
|
assert.equal(resolveAuthorizedPath(notificationOperator, 'notifications'), '/notifications');
|
|
|
|
const reportOperator = {
|
|
roles: ['STORE_ADMIN'], capabilities: ['report.read'], menus: ['reports']
|
|
};
|
|
assert.equal(resolveAuthorizedPath(reportOperator, 'reports'), '/reports');
|
|
|
|
const forgedSystemMenu = {
|
|
roles: ['STORE_ADMIN'],
|
|
capabilities: ['store.operation.read'],
|
|
menus: ['system']
|
|
};
|
|
const systemNavigation = ADMIN_NAVIGATION.find(({ menuKey }) => menuKey === 'system');
|
|
assert.ok(systemNavigation);
|
|
assert.equal(isNavigationAllowed(forgedSystemMenu, systemNavigation), false);
|
|
assert.equal(firstAuthorizedPath(forgedSystemMenu), null);
|
|
|
|
const cleaner = {
|
|
roles: ['CLEANER'],
|
|
capabilities: ['cleaning.task.read'],
|
|
menus: ['cleaning']
|
|
};
|
|
assert.equal(resolveAuthorizedPath(cleaner, 'cleaning'), '/cleaning');
|
|
assert.equal(resolveAuthorizedPath(cleaner, 'devices'), '/cleaning');
|
|
|
|
const platformAdmin = {
|
|
roles: ['PLATFORM_ADMIN'],
|
|
capabilities: [],
|
|
menus: ADMIN_NAVIGATION.map(({ menuKey }) => menuKey)
|
|
};
|
|
assert.equal(resolveAuthorizedPath(platformAdmin, 'system'), '/system');
|
|
|
|
console.log('PASS: M08-D-R1 deep links, menu/capability guards and refresh fallbacks are deterministic.');
|