mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
The Cards.before.update timing hook read modifier.$set[field] for any update whose first field was a date, but unsetDue/unsetStart/unsetEnd/ unsetReceived send only a $unset. Without a $set the hook threw a TypeError; with one beside the $unset (a stamped modifiedAt) it wrote an a-dueAt with timeValue: undefined, which counted as a due date change (#6081), matched the "date set or changed" rule triggers (#2474), and showed in the activity feed as an empty date. server/lib/timingChangeActivity.js now decides it: a date set records timeValue, a date cleared records timeOldValue alone - the same record a rule's removeDate writes, and the one models/lib/boardTimeline.js rewinds - and clearing a date the card does not have records nothing. The rules skip a cleared date before matching triggers, as server/triggersDef.js already said they should, and the feed shows only the date it had. tests/cardTimingActivity.test.cjs runs the real hook: a set, a $unset alone and a $unset beside a $set (both used to fail), and clearing nothing; and, tree-wide, no modifier.$set[...] read that assumes the $set is there. The two guards that pinned the old inline list and its modifier.$set[action] read now pin the helper instead. Thanks to xet7 !
90 lines
4.1 KiB
JavaScript
90 lines
4.1 KiB
JavaScript
'use strict';
|
|
|
|
// Plain-Node source-pattern regression test (no Meteor) for #4912 ("Global
|
|
// Webhook act-editCard?" — a request to make the global webhook fire when a
|
|
// card is edited, e.g. title/description/due-date changes).
|
|
//
|
|
// This is already implemented: server/models/cards.js logs an Activities
|
|
// entry for title (`a-changedTitle`, #3619), description (`a-changedDescription`,
|
|
// #5482) and the timing fields (`a-${dueAt|startAt|endAt|receivedAt}`) whenever
|
|
// they change, and server/models/activities.js's Activities.after.insert hook
|
|
// turns every such activityType into `act-${activityType}` and dispatches it to
|
|
// any enabled integration whose boardId is the card's own board OR the special
|
|
// Integrations.Const.GLOBAL_WEBHOOK_ID, filtered by `activities: { $in: [description, 'all'] }`.
|
|
// So editing a card's title/description/due date already reaches a globally
|
|
// configured webhook today, under those activity names.
|
|
//
|
|
// Since 2026-10-02 (maintainer decision) a webhook may also opt into ONE
|
|
// consolidated `act-editCard` event (models/lib/editCardWebhook.js), so the
|
|
// selection and the per-webhook event name below go through that helper; the
|
|
// helper's own behaviour is pinned by tests/editCardWebhook.test.cjs.
|
|
//
|
|
// Run: node tests/globalWebhookEditCardActivity.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const cardsSrc = fs.readFileSync(
|
|
path.join(__dirname, '..', 'server', 'models', 'cards.js'),
|
|
'utf8',
|
|
);
|
|
const activitiesSrc = fs.readFileSync(
|
|
path.join(__dirname, '..', 'server', 'models', 'activities.js'),
|
|
'utf8',
|
|
);
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
// --- POSITIVE: cards.js logs an activity for each edit that #4912 asked about --
|
|
|
|
test('#4912: title changes log activityType a-changedTitle', () => {
|
|
assert.match(cardsSrc, /activityType:\s*'a-changedTitle'/);
|
|
});
|
|
|
|
test('#4912: description changes log activityType a-changedDescription', () => {
|
|
assert.match(cardsSrc, /activityType:\s*'a-changedDescription'/);
|
|
});
|
|
|
|
test('#4912: due/start/end/received date changes log activityType a-${action}', () => {
|
|
// The four dates moved from an inline list into server/lib/timingChangeActivity.js
|
|
// when the hook stopped reading a $set a cleared date does not have.
|
|
const timingSrc = fs.readFileSync(path.join(__dirname, '../server/lib/timingChangeActivity.js'), 'utf8');
|
|
assert.match(timingSrc, /export const TIMING_FIELDS = \[\s*'receivedAt',\s*'dueAt',\s*'startAt',\s*'endAt',?\s*\];/);
|
|
assert.match(cardsSrc, /const change = timingChange\(fieldNames, modifier\);/);
|
|
assert.match(cardsSrc, /const activityType = `a-\$\{action\}`;/);
|
|
});
|
|
|
|
// --- POSITIVE: activities.js dispatches every logged activity to the global
|
|
// webhook (not just per-board integrations) ---------------------------------
|
|
|
|
test('#4912: outgoing-webhook dispatch is keyed off act-${activityType}, covering every activityType above', () => {
|
|
assert.match(activitiesSrc, /const description = `act-\$\{activity\.activityType\}`;/);
|
|
});
|
|
|
|
test('#4912: integrations are looked up on the card\'s board AND the global webhook id', () => {
|
|
assert.match(
|
|
activitiesSrc,
|
|
/const integrationBoardIds = board\s*\?\s*\[board\._id, Integrations\.Const\.GLOBAL_WEBHOOK_ID\]\s*:\s*\[Integrations\.Const\.GLOBAL_WEBHOOK_ID\];/,
|
|
);
|
|
});
|
|
|
|
test('#4912: integrations are filtered by this description, "all" or the act-editCard opt-in', () => {
|
|
assert.match(activitiesSrc, /activities:\s*\{\s*\$in:\s*webhookActivitySelection\(description\)\s*\}/);
|
|
const { webhookActivitySelection } = require('../models/lib/editCardWebhook');
|
|
assert.deepEqual(webhookActivitySelection('act-a-dueAt'), ['act-a-dueAt', 'all']);
|
|
});
|
|
|
|
test('#4912: matching integrations are delivered with their own event', () => {
|
|
assert.match(activitiesSrc, /const delivered = webhookDescriptionFor\(integration, description\);/);
|
|
// #6782: through deliverActivityWebhook, not the outgoingWebhooks method.
|
|
assert.match(activitiesSrc, /deliverActivityWebhook\(integration, delivered, deliveredParams,/);
|
|
});
|
|
|
|
console.log('\n' + passed + ' passed');
|