mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
An outgoing webhook was sent every activity, or whatever its activities list said with no way to change it in the interface. Its form now has "Send this webhook:" with "Every activity" and a tick per kind of activity - the same groups a member mutes notifications by (#572): labels, members, assignees, comments, moves, dates, checklists, attachments, custom field values, archive and created. Ticks are saved as the act-<type> descriptions the activity hook matches webhooks by; nothing ticked, or Every activity, stays "all", the default. models/lib/webhookActivityPicker.js maps both ways; tests/webhookActivityPicker.test.cjs checks that a picked group selects exactly its activities through webhookActivitySelection, the form state, and that a webhook never silently gets nothing. Part of #2026 and #1377, with the activity feed and browser push. The new strings are English placeholders until the next translation pass. Thanks to xet7 !
39 lines
2.4 KiB
JavaScript
39 lines
2.4 KiB
JavaScript
'use strict';
|
|
|
|
// #2026 / #1377: a webhook activity picker in the UI.
|
|
// Run: node tests/webhookActivityPicker.test.cjs
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const { groupDescriptions, pickerState, activitiesFor } = require('../models/lib/webhookActivityPicker.js');
|
|
const { webhookActivitySelection } = require('../models/lib/editCardWebhook.js');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
const read = f => fs.readFileSync(path.join(ROOT, f), 'utf8');
|
|
|
|
// Positive: the picked groups are exactly what the activity hook selects on.
|
|
const comments = activitiesFor({ groups: ['comments'] });
|
|
assert.deepEqual(comments, ['act-addComment', 'act-editComment', 'act-deleteComment']);
|
|
assert.ok(webhookActivitySelection('act-addComment').some(d => comments.includes(d)), 'a comment reaches a comments webhook');
|
|
assert.ok(!webhookActivitySelection('act-moveCard').some(d => comments.includes(d)), 'a move does not');
|
|
assert.deepEqual(pickerState(comments), { all: false, groups: ['comments'] }, 'the form shows what was stored');
|
|
assert.deepEqual(pickerState(['all']), { all: true, groups: [] });
|
|
assert.deepEqual(pickerState(undefined), { all: true, groups: [] }, 'the default is every activity');
|
|
console.log(' ok - picked groups select exactly their activities');
|
|
|
|
// Negative: nothing picked, or all, is every activity; unknown groups ignored.
|
|
assert.deepEqual(activitiesFor({}), ['all'], 'a webhook never silently gets nothing');
|
|
assert.deepEqual(activitiesFor({ all: true, groups: ['comments'] }), ['all']);
|
|
assert.deepEqual(activitiesFor({ groups: ['nope'] }), ['all']);
|
|
assert.deepEqual(groupDescriptions('nope'), []);
|
|
assert.deepEqual(pickerState(['act-addComment']).groups, [], 'a partly picked group is not shown as picked');
|
|
console.log(' ok - nothing or everything is "all"; unknown groups ignored');
|
|
|
|
const jade = read('client/components/sidebar/sidebar.jade');
|
|
assert.match(jade, /\.webhook-activity-picker[\s\S]{0,200}a\.flex\.js-toggle-webhook-activity-all/);
|
|
assert.match(jade, /each webhookActivityGroups\s*\n\s*a\.flex\.js-toggle-webhook-activity-group\(data-group=key\)/);
|
|
assert.match(read('client/components/sidebar/sidebar.js'), /\.\.\.\(pickedActivities \? \{ activities: pickedActivities \} : \{\}\),/);
|
|
console.log(' ok - the webhook form saves the picked activities');
|
|
console.log('\nwebhookActivityPicker: all tests passed');
|