refactor(M08-D-R1): 后台改用权限路由与懒加载
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
ADMIN_NAVIGATION,
|
||||
firstAuthorizedPath,
|
||||
isNavigationAllowed,
|
||||
pathForMenu,
|
||||
resolveAuthorizedPath
|
||||
} from '../src/navigation.mjs';
|
||||
|
||||
assert.deepEqual(
|
||||
ADMIN_NAVIGATION.map(({ path }) => path),
|
||||
['/overview', '/stores', '/orders', '/payments', '/third-party', '/people',
|
||||
'/cleaning', '/devices', '/apps', '/content', '/franchise', '/system']
|
||||
);
|
||||
assert.equal(pathForMenu('platformApps'), '/apps');
|
||||
assert.equal(pathForMenu('thirdParty'), '/third-party');
|
||||
|
||||
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 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.');
|
||||
Reference in New Issue
Block a user