mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
globalWebhookEditCardActivity pinned the old webhook selection and call, which the opt-in event replaced on purpose; it now pins the shared per-webhook choice. notificationActivityGroups read act-editCard as a new activity type; it is a webhook-only event name, so it is listed with that reason. Thanks to xet7 !
85 lines
3.7 KiB
JavaScript
85 lines
3.7 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}', () => {
|
|
assert.match(cardsSrc, /const timingaction = \[\s*'receivedAt',\s*'dueAt',\s*'startAt',\s*'endAt',?\s*\];/);
|
|
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 call the outgoingWebhooks Meteor method with their own event', () => {
|
|
assert.match(activitiesSrc, /const delivered = webhookDescriptionFor\(integration, description\);/);
|
|
assert.match(activitiesSrc, /Meteor\.call\('outgoingWebhooks', integration, delivered, deliveredParams,/);
|
|
});
|
|
|
|
console.log('\n' + passed + ' passed');
|