Files
wekan/tests/dueNotificationConfig.test.cjs
T
Lauri Ojansivu c0bbacaf94 Due-date reminders: honour hour 0 (midnight) and notify card assignees (#3192).
Two source bugs kept due-date reminder mail from reaching people. (1) The reminder hour was parsed as parseInt(NOTIFY_DUE_AT_HOUR_OF_DAY, 10) || 8, so a configured hour of 0 (midnight) silently became 8 (0 is falsy) and out-of-range hours were accepted; parseNotifyDueHour now keeps 0 and rejects anything outside 0..23. (2) A due-card activity's notification participants were only the card CREATOR and its MEMBERS (server/models/activities.js) -- a user ASSIGNED a card but not a member was never notified about it, including its due date; card.assignees are now included too (still gated downstream by the board tracking level, so nobody who is not tracking is newly emailed). The NOTIFY_DUE_* parsing is extracted to a pure, unit-tested models/lib/dueNotificationConfig.js. Note: the built-in reminder still requires NOTIFY_DUE_DAYS_BEFORE_AND_AFTER to be set, and members/assignees are emailed per their board watch/tracking level.

Tests: tests/dueNotificationConfig.test.cjs (12 checks) covers the midnight-hour case, valid/invalid/out-of-range hours, the day-offset window parsing and negatives, plus source guards that cards.js uses parseNotifyDueHour and that assignees are in the notification participants.

Thanks to SirConfigMgr and xet7 !

Fixes #3192,
2026-07-22 11:19:39 +03:00

81 lines
3.8 KiB
JavaScript

'use strict';
// Unit + negative tests for the due-date reminder config parsers (#3192).
// Run: node tests/dueNotificationConfig.test.cjs
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const {
parseNotifyDueDays,
parseNotifyDueHour,
} = require('../models/lib/dueNotificationConfig');
let passed = 0;
function check(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
// ── parseNotifyDueHour — the #3192 midnight bug ─────────────────────────────
check('#3192: hour "0" (midnight) is kept, NOT silently turned into the default', () => {
// The old `parseInt(env,10) || 8` returned 8 for "0" because 0 is falsy.
assert.strictEqual(parseNotifyDueHour('0', 8), 0);
});
check('a valid hour is parsed as itself', () => {
assert.strictEqual(parseNotifyDueHour('8', 8), 8);
assert.strictEqual(parseNotifyDueHour('23', 8), 23);
assert.strictEqual(parseNotifyDueHour('13', 8), 13);
});
check('missing / non-numeric hour falls back to the default', () => {
assert.strictEqual(parseNotifyDueHour(undefined, 8), 8);
assert.strictEqual(parseNotifyDueHour('', 8), 8);
assert.strictEqual(parseNotifyDueHour('abc', 8), 8);
});
check('out-of-range hour falls back to the default (negative, >23)', () => {
assert.strictEqual(parseNotifyDueHour('-1', 8), 8);
assert.strictEqual(parseNotifyDueHour('24', 8), 8);
assert.strictEqual(parseNotifyDueHour('25', 8), 8);
});
check('the default is configurable', () => {
assert.strictEqual(parseNotifyDueHour('nope', 6), 6);
});
// ── parseNotifyDueDays ──────────────────────────────────────────────────────
check('parses a comma list of day offsets, keeping 0 and negatives', () => {
assert.deepStrictEqual(parseNotifyDueDays('-2,0,3'), [-2, 0, 3]);
});
check('drops entries outside the -14..14 window', () => {
assert.deepStrictEqual(parseNotifyDueDays('-15,-14,14,15,100'), [-14, 14]);
});
check('drops non-numeric entries but keeps the valid ones', () => {
assert.deepStrictEqual(parseNotifyDueDays('0,foo,2'), [0, 2]);
});
check('empty / undefined / non-string yields an empty array (negative)', () => {
assert.deepStrictEqual(parseNotifyDueDays(''), []);
assert.deepStrictEqual(parseNotifyDueDays(undefined), []);
assert.deepStrictEqual(parseNotifyDueDays(null), []);
assert.deepStrictEqual(parseNotifyDueDays(5), []);
});
check('a single valid value works', () => {
assert.deepStrictEqual(parseNotifyDueDays('0'), [0]);
});
// ── source guards ───────────────────────────────────────────────────────────
const read = rel => fs.readFileSync(path.join(__dirname, '..', rel), 'utf8');
check('cards.js uses parseNotifyDueHour (no falsy `|| defaultitvl` hour parse)', () => {
const src = read('models/cards.js');
assert.ok(/parseNotifyDueHour\(process\.env\.NOTIFY_DUE_AT_HOUR_OF_DAY/.test(src),
'the scheduler must parse the hour via parseNotifyDueHour');
assert.ok(!/parseInt\(notifyitvl, 10\) \|\| defaultitvl/.test(src),
'the old falsy-zero hour parse must be gone');
});
check('#3192: due-card notifications include card ASSIGNEES as participants', () => {
const src = read('server/models/activities.js');
// The card-activity participants block must add card.assignees alongside members.
const m = src.match(/participants = \[\.\.\.new Set\(\[[\s\S]{0,200}?card\.userId[\s\S]{0,200}?\]\)\]/);
assert.ok(m, 'the card participants assignment must exist');
assert.ok(/card\.assignees/.test(m[0]),
'participants must include card.assignees so assignees are notified');
});
console.log(`\ndueNotificationConfig: ${passed} checks passed`);