import test from 'node:test';import assert from 'node:assert/strict';import {deleteNativeMessage} from './delete-message.mjs'; const list=(status='N')=>'Message List\r\n 7 17-Oct B'+status+' 100 '+['ALL','WW','N1TEST'].map(s=>s.padEnd(7)).join(' ')+' Test bulletin\r\n'; test('delete uses a fresh private WebMail session and confirms the message is gone',async()=>{ const calls=[];let killed=false; const bpq=async url=>{calls.push(url);if(url==='/Webmail')return 'Bulls';if(url==='/WebMail/WMALL?fresh')return killed?'Message List':list();if(url==='/WebMail/WMDel/7?fresh'){killed=true;return 'Message #7 Killed';}throw Error('Unexpected or stale WebMail key');}; assert.deepEqual(await deleteNativeMessage(7,bpq),{ok:true});assert.deepEqual(calls,['/Webmail','/WebMail/WMALL?fresh','/WebMail/WMDel/7?fresh','/WebMail/WMALL?fresh']); }); test('a BPQ permission denial is reported instead of pretending the message was deleted',async()=>{ await assert.rejects(deleteNativeMessage(7,async url=>url==='/Webmail'?'Mail':url.includes('WMDel')?'Not your message':list()),/permessi sysop/); }); test('a native HTTP 200 or session-redirect page is insufficient if the message remains visible',async()=>{ await assert.rejects(deleteNativeMessage(7,async url=>url==='/Webmail'?'Mail':list()),/non ha confermato/); }); test('already absent or killed messages are idempotent and never issue another delete',async()=>{ for(const html of ['Message List',list('K')]){const calls=[];const result=await deleteNativeMessage(7,async url=>{calls.push(url);return url==='/Webmail'?'Mail':html;});assert.equal(result.alreadyDeleted,true);assert.ok(!calls.some(url=>url.includes('WMDel')));} }); test('BPQ may retain the killed row for sysop inspection; status K confirms deletion',async()=>{ let killed=false;assert.deepEqual(await deleteNativeMessage(7,async url=>{if(url==='/Webmail')return 'Mail';if(url.includes('WMDel')){killed=true;return 'Killed';}return list(killed?'K':'N');}),{ok:true}); }); test('unverifiable sessions and invalid message IDs cannot issue a deletion',async()=>{ await assert.rejects(deleteNativeMessage(0,async()=>{throw Error('Must not contact BPQ');}),/non valido/); await assert.rejects(deleteNativeMessage(7,async()=>'