// A receipt is checked on its text: what the person or the engine gave, never a // JavaScript object written out again, which moves a member named by digits // ahead of the others and rewrites a large whole number. // // node test/verify-text.test.mjs let fails = 0; const check = (ok, what) => { console.log(`${ok ? 'PASS' : 'FAIL'} ${what}`); if (!ok) fails += 1; }; const calls = []; globalThis.window = { __TAURI__: { core: { invoke: async (cmd, args) => { calls.push([cmd, args]); return JSON.stringify({ valid: true }); } } } }; const { DesktopEngine } = await import('../src/engine.js'); const desk = new DesktopEngine(); const text = '{"request":{"x":1},"result":{"counts":{"00":1,"11":2},"receipt":{}}}'; await desk.verify(text); check(calls.at(-1)?.[1]?.job === text, 'the desktop app is given the receipt\'s text as it is'); await desk.verify(JSON.parse(text)); check(typeof calls.at(-1)?.[1]?.job === 'string', 'an object, all there is, is written out'); const { jobText } = await import('../src/job-text.js'); check(jobText(text) === text && jobText({ a: 1 }) === '{"a":1}', 'the worker sends a text as it is, an object written out'); if (fails) { console.log(`${fails} check(s) failed`); process.exit(1); } console.log('verify-text: every check held');