Files
wekan/tests/notificationSettingsResolution.test.cjs
T
Lauri Ojansivu bde66a5c7d Add a 3-tier Notification Settings popup (Member/Board/Admin).
Admin Panel / People, Board Settings and Member Settings each gain a
"Notification Settings" menu entry, right below Email in Admin Panel /
People. All three open the same reusable notificationSettingsPopup
template, letting notifications (tray/in-app and email, the two services
Notifications.notify already dispatches to) be turned on or off with the
same precedence the theme override already uses: Admin Panel default,
then Board override, then the member's own override.

models/lib/notificationSettings.js is a small pure module with the
resolution function (resolveNotificationSetting) and the notification-type
catalog; server/notifications/profile.js and server/notifications/email.js
now resolve the decision before adding to the tray or buffering an email,
so a disabled service is genuinely skipped rather than only hidden in the
UI. Settings.notifyDefaultTray/Email hold the admin default,
Board.notifyOverrideTray/Email the board override, and
profile.notifyOverrideTray/Email the member override; each is optional/
nullable so "unset" always falls through to the next level.
2026-09-10 21:00:20 +03:00

141 lines
3.7 KiB
JavaScript

'use strict';
// Regression coverage for the 3-tier Notification Settings resolution
// (models/lib/notificationSettings.js), added as part of "Add big popup of
// Notification Settings as menu option to Member Settings, Board Settings
// and Admin Panel / People".
//
// Precedence, highest wins: member override > board override > admin
// default > hardcoded fallback (true) - the same shape as the admin-default
// -> board-override -> member-override "theme override" pattern used
// elsewhere in WeKan.
//
// Run: node tests/notificationSettingsResolution.test.cjs
const assert = require('assert');
const {
resolveNotificationSetting,
HARDCODED_FALLBACK,
NOTIFICATION_SERVICES,
} = require('../models/lib/notificationSettings.js');
let passed = 0;
function test(name, fn) {
fn();
passed += 1;
console.log(' ok -', name);
}
console.log('notificationSettingsResolution:');
test('catalog has exactly tray and email, matching the registered services', () => {
assert.deepStrictEqual(Object.keys(NOTIFICATION_SERVICES).sort(), [
'email',
'tray',
]);
assert.strictEqual(NOTIFICATION_SERVICES.tray, 'profile');
assert.strictEqual(NOTIFICATION_SERVICES.email, 'email');
});
test('nothing configured anywhere falls back to the hardcoded default (true)', () => {
assert.strictEqual(
resolveNotificationSetting('tray', {}),
HARDCODED_FALLBACK,
);
assert.strictEqual(
resolveNotificationSetting('email', {
adminDefault: undefined,
boardOverride: undefined,
memberOverride: undefined,
}),
HARDCODED_FALLBACK,
);
});
test('null is treated the same as undefined at every level', () => {
assert.strictEqual(
resolveNotificationSetting('tray', {
adminDefault: null,
boardOverride: null,
memberOverride: null,
}),
HARDCODED_FALLBACK,
);
});
test('admin default alone decides when board and member are unset', () => {
assert.strictEqual(
resolveNotificationSetting('tray', { adminDefault: false }),
false,
);
assert.strictEqual(
resolveNotificationSetting('tray', { adminDefault: true }),
true,
);
});
test('board override wins over the admin default', () => {
assert.strictEqual(
resolveNotificationSetting('email', {
adminDefault: true,
boardOverride: false,
}),
false,
);
assert.strictEqual(
resolveNotificationSetting('email', {
adminDefault: false,
boardOverride: true,
}),
true,
);
});
test('member override wins over both the board override and the admin default', () => {
assert.strictEqual(
resolveNotificationSetting('tray', {
adminDefault: true,
boardOverride: true,
memberOverride: false,
}),
false,
);
assert.strictEqual(
resolveNotificationSetting('tray', {
adminDefault: false,
boardOverride: false,
memberOverride: true,
}),
true,
);
});
test('an explicit false at a lower level is not treated as "unset"', () => {
// admin explicitly disabled, board says nothing -> stays disabled
assert.strictEqual(
resolveNotificationSetting('email', {
adminDefault: false,
boardOverride: undefined,
memberOverride: undefined,
}),
false,
);
});
test('tray and email resolve independently of each other', () => {
const trayEnabled = resolveNotificationSetting('tray', {
adminDefault: true,
boardOverride: undefined,
memberOverride: false,
});
const emailEnabled = resolveNotificationSetting('email', {
adminDefault: true,
boardOverride: undefined,
memberOverride: undefined,
});
assert.strictEqual(trayEnabled, false);
assert.strictEqual(emailEnabled, true);
});
console.log(`notificationSettingsResolution: ${passed} passed`);