feat: add messaging toggles, password reset SMS, and payment discounts

Allow SuperAdmin to disable SMS, email, and bot from dashboard settings on top of env flags. Add admin password reset with credentials SMS, plus payment discounts, notes, and payable amount handling.
This commit is contained in:
2026-08-16 06:58:08 +03:30
parent a6c760c3b7
commit 72be01fee3
25 changed files with 601 additions and 43 deletions
+46
View File
@@ -0,0 +1,46 @@
'use strict';
const { describe, it } = require('node:test');
const assert = require('node:assert/strict');
const {
getPayableAmount,
normalizeDiscount,
sanitizeNotes,
NOTES_MAX_LENGTH
} = require('./paymentAmount');
describe('payment amount helpers', () => {
it('returns the original amount when there is no discount', () => {
assert.equal(getPayableAmount({ amount: 1_000_000 }), 1_000_000);
assert.equal(getPayableAmount({ amount: 1_000_000, discount: 0 }), 1_000_000);
});
it('subtracts a discount from the total', () => {
assert.equal(getPayableAmount({ amount: 1_000_000, discount: 150_000 }), 850_000);
});
it('never returns a negative payable amount', () => {
assert.equal(getPayableAmount({ amount: 100, discount: 250 }), 0);
});
it('treats missing or invalid values as zero', () => {
assert.equal(getPayableAmount({}), 0);
assert.equal(getPayableAmount({ amount: 'abc', discount: 'x' }), 0);
assert.equal(normalizeDiscount(-50, 1000), 0);
assert.equal(normalizeDiscount('not-a-number', 1000), 0);
});
it('clamps discount so it cannot exceed the total', () => {
assert.equal(normalizeDiscount(2_000, 1_000), 1_000);
assert.equal(normalizeDiscount(200, 1_000), 200);
});
});
describe('sanitizeNotes', () => {
it('trims notes and caps length', () => {
assert.equal(sanitizeNotes(' hello '), 'hello');
assert.equal(sanitizeNotes(null), '');
assert.equal(sanitizeNotes(undefined), '');
assert.equal(sanitizeNotes('a'.repeat(NOTES_MAX_LENGTH + 10)).length, NOTES_MAX_LENGTH);
});
});