Files
wekan/tests/rulesBoardSelector.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

137 lines
4.8 KiB
JavaScript

'use strict';
(async () => {
// Plain-Node unit test (no Meteor) for the IFTTT-Rules board selector logic.
// Run: node tests/rulesBoardSelector.test.cjs
//
// Regression guard for #5698 ("Impossible to select other board in rules"): the
// rules "move card to the board" / "link card to the board" dropdown filtered
// the client cache with `'members.userId': me`, so boards reached through an
// Organization / Team / email-domain share (where the user is not an individual
// member) never appeared — the reporter's dropdown was empty, current board
// included, while direct-member colleagues saw boards. canSelectBoardInRules()
// must include org/team/domain/public boards, while still excluding archived,
// helper, template-container and templates boards, and boards with no access.
const assert = require('assert');
const {
canSelectBoardInRules,
boardVisibleToUserContext,
} = await import('../models/lib/rulesBoardSelector.js');
let passed = 0;
function test(name, fn) {
fn();
passed += 1;
console.log(' ok -', name);
}
// The user: member of org O1 and team T1, email domain example.com.
const CTX = {
userId: 'u1',
orgIds: ['O1'],
teamIds: ['T1'],
emailDomains: ['example.com'],
};
const board = props => ({ _id: 'b', type: 'board', title: 'Board', ...props });
// --- POSITIVE: every access path lets the board be selected -----------------
test('direct active member board is selectable', () => {
const b = board({ members: [{ userId: 'u1', isActive: true }] });
assert.strictEqual(canSelectBoardInRules(b, CTX), true);
});
test('public board is selectable even without membership', () => {
const b = board({ permission: 'public', members: [] });
assert.strictEqual(canSelectBoardInRules(b, CTX), true);
});
test('#5698: org-shared board (not a direct member) is selectable', () => {
const b = board({
members: [{ userId: 'someone-else', isActive: true }],
orgs: [{ orgId: 'O1', isActive: true }],
});
assert.strictEqual(canSelectBoardInRules(b, CTX), true);
});
test('#5698: team-shared board (not a direct member) is selectable', () => {
const b = board({ members: [], teams: [{ teamId: 'T1', isActive: true }] });
assert.strictEqual(canSelectBoardInRules(b, CTX), true);
});
test('#5698: domain-shared board (not a direct member) is selectable', () => {
const b = board({
members: [],
domains: [{ domain: 'example.com', isActive: true }],
});
assert.strictEqual(canSelectBoardInRules(b, CTX), true);
});
// --- NEGATIVE: no access / excluded categories are NOT selectable -----------
test('board the user cannot access at all is NOT selectable', () => {
const b = board({
permission: 'private',
members: [{ userId: 'other', isActive: true }],
orgs: [{ orgId: 'O2', isActive: true }],
teams: [{ teamId: 'T2', isActive: true }],
domains: [{ domain: 'other.com', isActive: true }],
});
assert.strictEqual(canSelectBoardInRules(b, CTX), false);
});
test('inactive member entry does NOT grant selection', () => {
const b = board({ members: [{ userId: 'u1', isActive: false }] });
assert.strictEqual(canSelectBoardInRules(b, CTX), false);
});
test('inactive org / team / domain shares do NOT grant selection', () => {
const b = board({
members: [],
orgs: [{ orgId: 'O1', isActive: false }],
teams: [{ teamId: 'T1', isActive: false }],
domains: [{ domain: 'example.com', isActive: false }],
});
assert.strictEqual(canSelectBoardInRules(b, CTX), false);
});
test('archived board is excluded even if visible', () => {
const b = board({ archived: true, members: [{ userId: 'u1', isActive: true }] });
assert.strictEqual(canSelectBoardInRules(b, CTX), false);
});
test('the user templates board is excluded by id', () => {
const b = board({ _id: 'tpl', members: [{ userId: 'u1', isActive: true }] });
assert.strictEqual(canSelectBoardInRules(b, CTX, 'tpl'), false);
});
test('template-container type is excluded', () => {
const b = board({
type: 'template-container',
members: [{ userId: 'u1', isActive: true }],
});
assert.strictEqual(canSelectBoardInRules(b, CTX), false);
});
test('internal caret-wrapped helper board is excluded', () => {
const b = board({
title: '^Subtasks^',
members: [{ userId: 'u1', isActive: true }],
});
assert.strictEqual(canSelectBoardInRules(b, CTX), false);
});
test('null board / null ctx are handled without throwing', () => {
assert.strictEqual(canSelectBoardInRules(null, CTX), false);
assert.strictEqual(canSelectBoardInRules(board({}), null), false);
assert.strictEqual(boardVisibleToUserContext(null, CTX), false);
});
test('missing org/team/domain arrays on ctx do not throw', () => {
const b = board({ members: [], orgs: [{ orgId: 'O1', isActive: true }] });
assert.strictEqual(boardVisibleToUserContext(b, { userId: 'u1' }), false);
});
console.log(`\n${passed} tests passed`);
})().catch(e => { console.error(e); process.exit(1); });