Files
wekan/tests/linkedCardTarget.test.cjs
T
Lauri Ojansivu 3b3f7ebd77 Allow same-board linked cards while retaining link and write guards
The card-link picker excluded every real card on its own board, and the
server rejected same-board sources. Include the current board and exclude
only sources already mirrored. Preserve coordinate and write validation,
reject link chains, and prevent whole-board self-links through both buttons.

Labels already use the source card. Verify live source-to-mirror updates
and edits through the mirror, same-board authorization failures, whole-board
self-link rejection, and existing cross-board behavior in Chromium.
Focused linked-card Node regression suites pass.

Thanks to RinTheCatato, mohamed-aziz-chamakh and xet7 !

Fixes #5683,
2026-09-27 00:09:56 +03:00

85 lines
3.6 KiB
JavaScript

'use strict';
(async () => {
// Plain-Node unit test (no Meteor) for the "Link to this card" target guard.
// Run: node tests/linkedCardTarget.test.cjs
//
// Regression guard for #5808 ("Linking two cards to each other across boards
// renders both cards inaccessible"): the link-target picker only excluded
// template cards, so an existing LINKED card could be chosen as a target,
// building a chain of linkedId pointers. Card helpers resolve linkedId only one
// hop, so such a card renders as an empty/broken pointer — inaccessible. Only a
// real card, not already linking back to this board, may be a link target.
const assert = require('assert');
const {
isLinkPointerCard,
isLinkableCardTarget,
} = await import('../models/lib/linkedCardTarget.js');
let passed = 0;
function test(name, fn) {
fn();
passed += 1;
console.log(' ok -', name);
}
const MIRRORED = ['A1', 'A2']; // source ids already mirrored on the destination board
// --- isLinkPointerCard ------------------------------------------------------
test('isLinkPointerCard: linked card and linked board are pointers', () => {
assert.strictEqual(isLinkPointerCard({ type: 'cardType-linkedCard' }), true);
assert.strictEqual(isLinkPointerCard({ type: 'cardType-linkedBoard' }), true);
});
test('isLinkPointerCard: a normal card is not a pointer', () => {
assert.strictEqual(isLinkPointerCard({ type: 'cardType-card' }), false);
assert.strictEqual(isLinkPointerCard(undefined), false);
});
// --- POSITIVE: a real, unrelated card on another board is linkable ----------
test('POSITIVE: a normal card on another board is a valid link target', () => {
const target = { _id: 'B1', type: 'cardType-card', boardId: 'boardB' };
assert.strictEqual(isLinkableCardTarget(target, MIRRORED), true);
});
test('POSITIVE: accepts a Set of mirrored source ids too', () => {
const target = { _id: 'B1', type: 'cardType-card' };
assert.strictEqual(isLinkableCardTarget(target, new Set(MIRRORED)), true);
});
// --- NEGATIVE: the #5808 configurations must be refused ---------------------
test('NEGATIVE: cannot link to an existing linked card (no chains of links)', () => {
const linkedCard = { _id: 'L1', type: 'cardType-linkedCard', linkedId: 'X9' };
assert.strictEqual(isLinkableCardTarget(linkedCard, MIRRORED), false);
});
test('NEGATIVE: cannot link to a linked board', () => {
const linkedBoard = { _id: 'LB1', type: 'cardType-linkedBoard', linkedId: 'brd' };
assert.strictEqual(isLinkableCardTarget(linkedBoard, MIRRORED), false);
});
test('#5683: a same-board real card can be mirrored', () => {
const own = { _id: 'A1', type: 'cardType-card', boardId: 'boardA' };
assert.strictEqual(isLinkableCardTarget(own), true);
});
test('NEGATIVE: an already mirrored source is excluded from the picker', () => {
assert.strictEqual(isLinkableCardTarget({ _id: 'A1', type: 'cardType-card' }, MIRRORED), false);
});
test('NEGATIVE: cannot link to a card that links back to one of our cards (mutual)', () => {
// Target is a real-ish card whose linkedId points at our card A2 → mutual loop.
const backLink = { _id: 'B7', type: 'cardType-card', linkedId: 'A2' };
assert.strictEqual(isLinkableCardTarget(backLink, MIRRORED), false);
});
test('NEGATIVE: cannot link to a template card, or to nothing', () => {
assert.strictEqual(isLinkableCardTarget({ _id: 'T1', type: 'template-card' }, MIRRORED), false);
assert.strictEqual(isLinkableCardTarget(undefined, MIRRORED), false);
assert.strictEqual(isLinkableCardTarget({ type: 'cardType-card' }, MIRRORED), false); // no _id
});
console.log(`\n${passed} passing`);
})().catch(e => { console.error(e); process.exit(1); });