Improve chat roster parsing, message read state and loading feedback

This commit is contained in:
alberto committed 2026-10-18 14:35:41 +02:00
1 parent c980ba10de
commit c8941dc199
16 files changed
+183 -20

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
import {test} from 'node:test';import assert from 'node:assert/strict';import {mkdtemp,rm} from 'node:fs/promises';import os from 'node:os';import path from 'node:path';
import {ForwardingScheduler} from './forwarding-scheduler.mjs';
test('hourly forwarding reserves its configured VHF route once, persists across restart and skips occupied hours',async()=>{
const dir=await mkdtemp(path.join(os.tmpdir(),'fwd-schedule-'));let now=Date.parse('2026-10-17T19:37:00Z'),calls=[],blocked=false;
const client={routes:[{id:'N0TEST-VHF'}],startRoute:async id=>{calls.push(id);if(blocked)throw Error('Radio occupata');}};
const config={forwardingSchedules:[{route:'N0TEST-VHF',intervalSeconds:3600,enabled:true}]};let first,second;
try{first=new ForwardingScheduler(config,dir,client,{clock:()=>now});await first.init;assert.equal(first.snapshot()[0].nextAt,'2026-10-17T20:00:00.000Z');await first.tick();assert.equal(calls.length,0);
now=Date.parse('2026-10-17T20:00:00Z');await Promise.all([first.tick(),first.tick()]);assert.deepEqual(calls,['N0TEST-VHF']);
second=new ForwardingScheduler(config,dir,client,{clock:()=>now});await second.init;await second.tick();assert.equal(calls.length,1);
blocked=true;now+=3600000;await second.tick();assert.equal(calls.length,2);assert.equal(second.snapshot()[0].error,'Radio occupata');await second.tick();assert.equal(calls.length,2);
assert.equal(second.snapshot()[0].nextAt,new Date(now+3600000).toISOString());
}finally{if(first)clearInterval(first.timer);if(second)clearInterval(second.timer);await rm(dir,{recursive:true,force:true});}
});
test('Rome operating hours skip midnight and follow summer/winter UTC offsets',async()=>{
const dir=await mkdtemp(path.join(os.tmpdir(),'fwd-hours-'));const config={forwardingSchedules:[{route:'N0TEST-VHF',intervalSeconds:3600,enabled:true,hours:{timeZone:'Europe/Rome',start:7,end:24}}]};const scheduler=new ForwardingScheduler(config,dir,{routes:[{id:'N0TEST-VHF'}]});
try{await scheduler.init;const s=scheduler.schedules[0];assert.equal(new Date(scheduler.boundary(s,Date.parse('2026-10-17T21:00:00Z'))).toISOString(),'2026-10-18T05:00:00.000Z');assert.equal(new Date(scheduler.boundary(s,Date.parse('2026-11-17T22:00:00Z'))).toISOString(),'2026-11-18T06:00:00.000Z');assert.equal(scheduler.allowed(s,Date.parse('2026-10-17T22:00:00Z')),false);assert.equal(scheduler.allowed(s,Date.parse('2026-10-18T05:00:00Z')),true);
}finally{clearInterval(scheduler.timer);await rm(dir,{recursive:true,force:true});}
});