Files
wekan/tests/boardCopyDefaults.test.cjs
T
Lauri Ojansivu 8d1fae4f7d Convert client-reachable models/lib helpers from CommonJS to ES modules (1/2).
The rspack client build treats a `module.exports` file imported into the
client bundle as an ES module and throws
"ES Modules may not assign module.exports" at evaluation time, aborting
the whole client module chain (No such template: swimlane / notifications
/ boardButtons, blank board, missing top bar). This is not an rspack
version regression (the lockfile has pinned ~1.7.x since v8.40); it is
that WeKan added CommonJS helpers to the client bundle.

Convert the 42 client-reachable pure-logic models/lib helpers from
`module.exports = { ... }` to `export { ... }`, and calendarFilter's
internal require('./swimlaneFilter') to an import with a .js extension
(node ESM needs it; rspack/reify tolerate it). Server-only helpers that
use node built-ins (fs/path/child_process) stay CommonJS. The plain-Node
.cjs unit tests for these helpers now use `await import(...js)` (wrapped
in an async IIFE); a source-guard in importVirtualMembers was updated
from module.exports to export. Verified: the full tests/*.test.cjs suite
has the SAME 7 pre-existing failures as before this change and no new
ones.
2026-07-23 18:55:30 +03:00

86 lines
3.2 KiB
JavaScript

'use strict';
(async () => {
// Plain-Node unit test (no Meteor) for the board-copy default-pointer remap.
// Run: node tests/boardCopyDefaults.test.cjs
//
// Regression guard for #4494 ("Creating a board from a template breaks
// subtasks"). Copying a template board inherited its subtasksDefaultBoardId /
// dateSettingsDefaultBoardId. When those pointed at the template board itself,
// subtasks created on the NEW board were dropped onto the TEMPLATE board.
// remapCopiedBoardDefaults() must repoint the source-board references to the
// copy (and clear the paired list id so it self-heals on the new board).
const assert = require('assert');
const { remapCopiedBoardDefaults } = await import('../models/lib/boardCopyDefaults.js');
let passed = 0;
function test(name, fn) {
fn();
passed += 1;
console.log(' ok -', name);
}
const OLD = 'templateBoard';
const NEW = 'newBoard';
// --- POSITIVE ---------------------------------------------------------------
test('self-referential subtasks default is repointed to the copy (#4494)', () => {
const patch = remapCopiedBoardDefaults(
{ subtasksDefaultBoardId: OLD, subtasksDefaultListId: 'oldList' },
OLD, NEW,
);
assert.strictEqual(patch.subtasksDefaultBoardId, NEW);
assert.strictEqual(patch.subtasksDefaultListId, null); // cleared, self-heals
});
test('self-referential date-settings default is repointed to the copy', () => {
const patch = remapCopiedBoardDefaults(
{ dateSettingsDefaultBoardId: OLD, dateSettingsDefaultListId: 'oldList' },
OLD, NEW,
);
assert.strictEqual(patch.dateSettingsDefaultBoardId, NEW);
assert.strictEqual(patch.dateSettingsDefaultListId, null);
});
test('both defaults repointed at once', () => {
const patch = remapCopiedBoardDefaults(
{ subtasksDefaultBoardId: OLD, dateSettingsDefaultBoardId: OLD },
OLD, NEW,
);
assert.strictEqual(patch.subtasksDefaultBoardId, NEW);
assert.strictEqual(patch.dateSettingsDefaultBoardId, NEW);
});
// --- NEGATIVE ---------------------------------------------------------------
test('NEGATIVE: subtasks default pointing at ANOTHER board is left untouched', () => {
// The template deliberately routes subtasks to a shared board; don't hijack it.
const patch = remapCopiedBoardDefaults(
{ subtasksDefaultBoardId: 'someSharedBoard' },
OLD, NEW,
);
assert.ok(!('subtasksDefaultBoardId' in patch));
assert.deepStrictEqual(patch, {});
});
test('NEGATIVE: null / unset defaults produce no patch (empty = no DB write)', () => {
assert.deepStrictEqual(
remapCopiedBoardDefaults({ subtasksDefaultBoardId: null }, OLD, NEW),
{},
);
assert.deepStrictEqual(remapCopiedBoardDefaults({}, OLD, NEW), {});
});
test('NEGATIVE: null board does not throw', () => {
assert.doesNotThrow(() => remapCopiedBoardDefaults(null, OLD, NEW));
assert.deepStrictEqual(remapCopiedBoardDefaults(null, OLD, NEW), {});
});
test('NEGATIVE: the new board must NOT keep the template board id', () => {
const patch = remapCopiedBoardDefaults({ subtasksDefaultBoardId: OLD }, OLD, NEW);
assert.notStrictEqual(patch.subtasksDefaultBoardId, OLD);
});
console.log(`\n${passed} tests passed`);
})().catch(e => { console.error(e); process.exit(1); });