MC/website/tests/cp-v2-native-services.test.mjs
Dev 6deb4a2e7d DuneRealms V2 clean baseline
Owner-authorised history reset; current source tree preserved exactly.
2026-11-13 00:05:14 +01:00

16 lines
3.1 KiB
JavaScript

import test from 'node:test';import assert from 'node:assert/strict';
import {NATIVE_SERVICES,nativeServiceAccess,nativeFrameHeight} from '../control-panel/public/cp-v2/cp-v2-native-services.mjs';
test('native staff workspaces retain their exact role requirements and verified SSO destinations',()=>{assert.equal(nativeServiceAccess(null,NATIVE_SERVICES['staff-tickets']),false);assert.equal(nativeServiceAccess({permissions:['web.tickets.staff']},NATIVE_SERVICES['support-management']),false);assert.equal(nativeServiceAccess({permissions:['web.menu.forum']},NATIVE_SERVICES['forum-admin']),false);assert.equal(nativeServiceAccess({permissions:['web.menu.forum','web.forum.moderate']},NATIVE_SERVICES['forum-admin']),true);for(const spec of Object.values(NATIVE_SERVICES))assert.ok(['support.dunerealms.com','forums.dunerealms.com','cp.dunerealms.com','www.dunerealms.com'].includes(new URL(spec.url).hostname));});
test('native shop retains either existing shop-support or sales access without granting ordinary users',()=>{assert.equal(nativeServiceAccess({permissions:[]},NATIVE_SERVICES['shop-admin']),false);for(const node of ['web.shop.support','web.tickets.sales'])assert.equal(nativeServiceAccess({permissions:[node]},NATIVE_SERVICES['shop-admin']),true);});
test('embedded resizing rejects foreign windows, other origins, wrong types and unbounded sizes',()=>{const source={},frame={contentWindow:source},origin='https://support.dunerealms.com',event={source,origin,data:{type:'dune-embed-size',height:1200.5}};assert.equal(nativeFrameHeight(event,frame,origin),1201);for(const bad of [{source:{}},{origin:'https://example.com'},{data:{type:'dune-embed-size',height:200001}},{data:{type:'dune-embed-size',height:NaN}},{data:{type:'other',height:500}}])assert.equal(nativeFrameHeight({...event,...bad},frame,origin),null);});
test('network workspace requires both navigation and server-view permission',()=>{const spec=NATIVE_SERVICES['server-operations'];assert.equal(spec.url,'https://cp.dunerealms.com/servers.html');assert.equal(spec.selfResize,true);assert.equal(nativeServiceAccess({permissions:['web.menu.servers']},spec),false);assert.equal(nativeServiceAccess({permissions:['web.menu.servers','web.servers.view']},spec),true);});
test('Dev workspace retains staff/VIP submission access and starts only at the requested native view',()=>{
for(const [id,view]of [['dev-panel','overview'],['dev-queue','queue'],['dev-approvals','approvals'],['dev-new','new'],['dev-archive','archive']]){
const spec=NATIVE_SERVICES[id];assert.equal(nativeServiceAccess({ranks:['user'],permissions:[]},spec),false);assert.equal(nativeServiceAccess({ranks:['vip'],permissions:[]},spec),true);assert.equal(nativeServiceAccess({ranks:['web_dev'],permissions:[]},spec),true);assert.equal(new URL(spec.url).searchParams.get('view'),view);assert.equal(spec.bootstrapUrl,'https://support.dunerealms.com/dune-sso.php?dev=1');
}
assert.equal(nativeServiceAccess({permissions:['web.menu.security']},NATIVE_SERVICES['git-administration']),false);
assert.equal(nativeServiceAccess({permissions:['web.git.admin']},NATIVE_SERVICES['git-administration']),true);
});