Files
NODEDC_MISSION_CORE/apps/control-station/test/boardUplink.test.mjs
T

28 lines
3.7 KiB
JavaScript

import assert from 'node:assert/strict';
import {after,before,test} from 'node:test';
import {createServer} from './support/vite-server.mjs';
let server,can,pending,options,reconcile,message,currentLabel;
before(async()=>{server=await createServer({appType:'custom',logLevel:'silent',server:{middlewareMode:true}});
({canSelectUplink:can,uplinkPending:pending,uplinkOptions:options,reconcileUplinkSelection:reconcile,uplinkStatusMessage:message,uplinkCurrentLabel:currentLabel}=await server.ssrLoadModule('/src/core/fleet/boardUplink.ts'));});
after(async()=>{await server?.close();});
const sample=()=>({available:true,current_id:'a',operation:null,candidates:[{id:'a',kind:'wifi',label:'Saved network',interface:'random-radio',verified:true,active:true},{id:'b',kind:'ethernet',label:'Cable',interface:'random-port',verified:true,active:true}]});
test('only verified fresh alternatives can be selected',()=>{const v=sample();assert.ok(can(v,'b'));assert.ok(!can(v,'a'));assert.ok(!can(v,'missing'));assert.ok(!can(null,'b'));v.available=false;assert.ok(!can(v,'b'));v.available=true;v.candidates[1].verified=false;assert.ok(!can(v,'b'));});
test('pending phases exclude a second command without hiding receipt',()=>{for(const phase of ['queued','applying','verifying','rolling_back','recovering','unknown','rollback_failed']){const v={...sample(),operation:{phase}};assert.ok(pending(v));assert.ok(!can(v,'b'));}assert.ok(!pending({...sample(),operation:{phase:'rolled_back'}}));});
test('options use board profile identities and disclose unverified alternatives',()=>{const v=sample();v.candidates[1].verified=false;const items=options(v);assert.equal(items[1].disabled,true);assert.match(items[0].description,/Текущее/);assert.match(items[1].description,/Интернет не подтверждён/);});
test('observed state updates an unchanged selection without replacing a deliberate draft',()=>{const next={...sample(),current_id:'b'};assert.equal(reconcile('a','a',next),'b');assert.equal(reconcile('b','a',sample()),'b');next.candidates[0].verified=false;assert.equal(reconcile('a','b',next),'b');});
test('same default can be repaired when VPN path was not verified',()=>{const v={...sample(),path_verified:false};assert.ok(can(v,'a'));v.path_verified=true;assert.ok(!can(v,'a'));});
test('current path proof overrides historical success text',()=>{const v={...sample(),operation:{phase:'applied',message:'Путь к Core подтверждён.'},path_verified:false};assert.match(message(v),/не подтверждён/);v.path_verified=true;assert.match(message(v),/Путь к Core подтверждён/);v.available=false;v.reason='Нет свежих данных';assert.equal(message(v),v.reason);});
test('disconnected available profile permits a trial but is never called verified',()=>{const v=sample();Object.assign(v.candidates[1],{verified:false,active:false,available:true});assert.ok(can(v,'b'));assert.equal(options(v)[1].disabled,false);assert.match(options(v)[1].description,/Не подключено/);});
test('pending default route never presents a completed current connection',()=>{const v={...sample(),current_id:'b',path_verified:false,operation:{phase:'verifying',message:'Проверяем путь связи с Core.'}};assert.match(currentLabel(v),/проверяется/);assert.doesNotMatch(currentLabel(v),/Cable/);assert.doesNotMatch(message(v),/подтверждён/);});
test('settled rollback resets failed draft once, then permits a new deliberate selection',()=>{
const v={...sample(),operation:{id:'attempt',phase:'rolled_back'},path_verified:true};
assert.equal(reconcile('b','a',v,'attempt:recovering'),'a');
assert.equal(reconcile('b','a',v,'attempt:rolled_back'),'b');
assert.equal(reconcile('b','a',v,'older:rolled_back'),'a');
});