Files
wekan/tests/cardMoveLabelActivities.test.cjs
T
Lauri Ojansivu e108bb83b0 Lay the groundwork for durable rule moves to another board.
The saved command for a rule move onto another board is written
(server/lib/syncRuleMoveBoardCommand.js). It plans what Card.move and
its hooks write there: labels by name, the card number, mapped custom
fields, filtered members and watchers, cleared dependencies, the
History rows, the moveCardBoard and custom-field activities, the
re-pointed label activities and the legacy undo row. It accepts only
the last action of its rule plan. The History planner gains those
fields, and the recording scope can defer the dependencies row and the
label-activity hook, which runs while the card is still on its old
board. Nothing uses the command yet: such a rule still keeps its board
on direct Sync until its runner, guard and eligibility are added.

Thanks to xet7 !
2026-10-02 18:27:47 +03:00

27 lines
1.7 KiB
JavaScript

'use strict';
// A card moved to another board keeps its addedLabel activities, re-pointed
// at the new board's labels. updateActivities (models/cards.js) is not
// idempotent - a second run in the same update deletes what the first one
// re-pointed - so it must run once per update.
// Server test: server/lib/tests/cardMoveLabelActivities.tests.js.
// Run: node tests/cardMoveLabelActivities.test.cjs
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const src = fs.readFileSync(path.join(__dirname, '../server/models/cards.js'), 'utf8');
assert.equal((src.match(/updateActivities\(doc, fieldNames, modifier\)/g) || []).length, 1, 'updateActivities runs once per update');
// ...unless a durable rule move to another board writes its changes itself
// (server/lib/syncRuleMoveBoardCommand.js).
assert.match(src, /await cardMembers\(userId, doc, fieldNames, modifier\);[\s\S]{0,500}if \(!deferSyncLabelActivities\(doc\)\) await updateActivities\(doc, fieldNames, modifier\);/);
// Negative: no other server hook calls it again.
for (const dir of ['server', 'models']) {
const walk = d => fs.readdirSync(d, { withFileTypes: true }).flatMap(e => e.isDirectory()
? (['node_modules', 'tests'].includes(e.name) ? [] : walk(path.join(d, e.name))) : [path.join(d, e.name)]);
for (const file of walk(path.join(__dirname, '..', dir)).filter(f => f.endsWith('.js'))) {
if (file.endsWith(path.join('server', 'models', 'cards.js'))) continue;
assert.ok(!/await updateActivities\(/.test(fs.readFileSync(file, 'utf8')), `${file} calls updateActivities`);
}
}
console.log(' ok - updateActivities runs once per card update');