import test from 'node:test'; import assert from 'node:assert/strict'; import vm from 'node:vm'; import {readFileSync} from 'node:fs'; import {parseNativeStations} from './aprs-activity.mjs'; const context=vm.createContext({window:{}}); vm.runInContext(readFileSync(new URL('./public/aprs-symbols.js',import.meta.url),'utf8'),context); const decode=context.window.BPQAprsPacket.decode; const mic='`\x7f^U!n^>/'; test('Mic-E station descriptions decode movement and base91 altitude instead of showing binary position bytes',()=>{ const info=decode(mic+'"5J}'); assert.equal(info.format,'Mic-E');assert.equal(info.speedKmh,107);assert.equal(info.course,266);assert.equal(info.altitudeM,142);assert.equal(info.comment,''); assert.equal(decode(mic+'"5J}Hello from the car').comment,'Hello from the car'); assert.equal(decode('`short').speedKmh,null);assert.equal(decode('`short').comment,''); }); test('known Mic-E device identifiers are separated from comments; unknown suffixes and real comments are preserved',()=>{ const info=decode(mic+'`"5J}Test_3');assert.equal(info.device,'Yaesu FT5D');assert.equal(info.altitudeM,142);assert.equal(info.comment,'Test'); assert.equal(decode(mic+'>Hello=').device,'Kenwood TH-D72'); assert.equal(decode(mic+'`Hello?Z').comment,'Hello?Z'); assert.equal(decode(mic+'').comment,''); }); test('plain position descriptions omit position fields without damaging the transmitted text',()=>{ assert.equal(decode('!4534.18N/00907.89E]Local BBS').comment,'Local BBS'); assert.equal(decode('@191200z4534.18N/00907.89E]Local BBS').comment,'Local BBS'); assert.equal(decode('>191200zOn air').comment,'On air'); assert.equal(decode('Comment\x7f with controls').comment,'Comment with controls'); }); test('native HTML decoding preserves Mic-E byte positions, literal angle brackets and repeated spaces',()=>{ const body='`\x7f<U ^>/"5J}'; const row='A,45.5,9.1,N0TEST,TEST,WIDE1-1
'+body+'
Last Heard: 12:00:00 on Port 3
,010D@,1\r\n|'; const station=parseNativeStations(row)[0]; assert.equal(station.lastBody,'`\x7f/"5J}');assert.equal(station.lastBody[7],'>');assert.equal(station.lastBody[8],'/'); assert.equal(decode(station.lastBody).altitudeM,142); });