'use strict';
// Evernote .enex: notes to cards with their to-dos as a checklist, tags as
// labels and the reminder as the due date (models/lib/enexFormat.js, parsed on
// the server by server/lib/enexImport.js), and a board written back as .enex.
// Run: node --test tests/enexFormat.test.cjs
const test = require('node:test');
const assert = require('node:assert');
const { readEnex, enmlText } = require('../server/lib/enexImport');
const ENEX = `
Shopping & errands
20261101T080000Z
20261102T080000Z
homeweekly
20261120T090000Zhttps://example.com/list
Before the weekend.
Milk
Bread <whole>
]]>
iVBORw0KGgo=image/png
Done one
20261110T090000Z20261110T100000Z
ok]]>
`;
let enex;
test.before(async () => { enex = await import('../models/lib/enexFormat.js'); });
test('notes become cards with their to-dos, tags, reminder and done state', () => {
const { notes } = readEnex(ENEX);
const board = enex.enexBoard(notes);
assert.deepStrictEqual(board.columns.map(c => c.title), ['Notes', 'Done']);
const [shop, done] = board.tasks;
assert.strictEqual(shop.title, 'Shopping & errands');
assert.strictEqual(shop.description, 'Before the weekend.\n\nhttps://example.com/list');
assert.deepStrictEqual(shop.checklists, [{ title: 'To-do', items: [{ title: 'Milk', done: true }, { title: 'Bread ', done: false }] }]);
assert.deepStrictEqual(shop.tags, ['home', 'weekly']);
assert.strictEqual(shop.date_due, '2026-11-20T09:00:00.000Z');
assert.strictEqual(shop.date_creation, '2026-11-01T08:00:00.000Z');
assert.strictEqual(done.column_name, 'Done');
assert.strictEqual(done.due_complete, true);
assert.ok(board.unsupported.some(u => /1 attached file/.test(u.reason)));
});
test('negative: no script, no markup and no non-ENEX file', () => {
assert.doesNotMatch(enmlText('a
'), /alert/);
const { notes } = readEnex(ENEX);
assert.doesNotMatch(JSON.stringify(enex.enexBoard(notes)), /