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.
57 lines
1.8 KiB
JavaScript
57 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
const { describe, it } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const {
|
|
assertCanResetPasswordAndSms,
|
|
isCredentialsSmsDelivered
|
|
} = require('./passwordReset');
|
|
|
|
describe('assertCanResetPasswordAndSms', () => {
|
|
it('throws USER_NOT_FOUND when the user is missing', () => {
|
|
assert.throws(() => assertCanResetPasswordAndSms(null), { errorCode: 'USER_NOT_FOUND' });
|
|
assert.throws(() => assertCanResetPasswordAndSms(undefined), { errorCode: 'USER_NOT_FOUND' });
|
|
});
|
|
|
|
it('throws PHONE_NUMBER_REQUIRED when no phone number is stored', () => {
|
|
assert.throws(
|
|
() => assertCanResetPasswordAndSms({ username: 'u123456' }),
|
|
{ errorCode: 'PHONE_NUMBER_REQUIRED' }
|
|
);
|
|
assert.throws(
|
|
() => assertCanResetPasswordAndSms({ username: 'u123456', phoneNumber: ' ' }),
|
|
{ errorCode: 'PHONE_NUMBER_REQUIRED' }
|
|
);
|
|
});
|
|
|
|
it('throws VALIDATION_FAILED when username is missing', () => {
|
|
assert.throws(
|
|
() => assertCanResetPasswordAndSms({ phoneNumber: '09120000000' }),
|
|
{ errorCode: 'VALIDATION_FAILED' }
|
|
);
|
|
});
|
|
|
|
it('returns the stored username and phone number', () => {
|
|
assert.deepEqual(
|
|
assertCanResetPasswordAndSms({
|
|
username: ' u482910 ',
|
|
phoneNumber: ' 09120000000 ',
|
|
name: 'علی'
|
|
}),
|
|
{ username: 'u482910', phoneNumber: '09120000000', name: 'علی' }
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('isCredentialsSmsDelivered', () => {
|
|
it('is false when sending was skipped or missing', () => {
|
|
assert.equal(isCredentialsSmsDelivered(null), false);
|
|
assert.equal(isCredentialsSmsDelivered({ result: { skipped: true } }), false);
|
|
});
|
|
|
|
it('is true when the SMS sender did not skip delivery', () => {
|
|
assert.equal(isCredentialsSmsDelivered({ result: { status: 1 } }), true);
|
|
assert.equal(isCredentialsSmsDelivered({}), true);
|
|
});
|
|
});
|