mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
fix: email ban tests
This commit is contained in:
@@ -230,7 +230,7 @@ Emailer.send = async (template, uid, params) => {
|
|||||||
if (!meta.config.sendEmailToBanned && template !== 'banned') {
|
if (!meta.config.sendEmailToBanned && template !== 'banned') {
|
||||||
if (userData.banned) {
|
if (userData.banned) {
|
||||||
winston.warn(`[emailer/send] User ${userData.username} (uid: ${uid}) is banned; not sending email due to system config.`);
|
winston.warn(`[emailer/send] User ${userData.username} (uid: ${uid}) is banned; not sending email due to system config.`);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,39 +144,52 @@ describe('emailer', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('emailer.send()', () => {
|
describe('emailer.send()', () => {
|
||||||
let senderUid;
|
|
||||||
let recipientUid;
|
let recipientUid;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
Plugins.hooks.register('emailer-test', {
|
|
||||||
hook: 'filter:email.send',
|
|
||||||
method: async () => {}, // noop
|
|
||||||
});
|
|
||||||
|
|
||||||
senderUid = await user.create({ username: 'sender' });
|
|
||||||
recipientUid = await user.create({ username: 'recipient', email: 'test@example.org' });
|
recipientUid = await user.create({ username: 'recipient', email: 'test@example.org' });
|
||||||
await user.email.confirmByUid(recipientUid);
|
await user.email.confirmByUid(recipientUid);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false on attempted email send to a banned user', async () => {
|
it('should not send email to a banned user', async () => {
|
||||||
|
Plugins.hooks.register('emailer-test', {
|
||||||
|
hook: 'filter:email.send',
|
||||||
|
method: async () => {
|
||||||
|
assert(false); // if thrown, email was sent
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
await user.bans.ban(recipientUid);
|
await user.bans.ban(recipientUid);
|
||||||
const success = await Emailer.send('test', recipientUid, {});
|
await Emailer.send('test', recipientUid, {});
|
||||||
assert.strictEqual(success, false);
|
|
||||||
|
Plugins.hooks.unregister('emailer-test', 'filter:email.send');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true if the template is "banned"', async () => {
|
it('should return true if the template is "banned"', async () => {
|
||||||
const success = await Emailer.send('banned', recipientUid, {});
|
Plugins.hooks.register('emailer-test', {
|
||||||
assert.strictEqual(success, true);
|
hook: 'filter:email.send',
|
||||||
|
method: async () => {
|
||||||
|
assert(true); // if thrown, email was sent
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await Emailer.send('banned', recipientUid, {});
|
||||||
|
Plugins.hooks.unregister('emailer-test', 'filter:email.send');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true if system settings allow sending to banned users', async () => {
|
it('should return true if system settings allow sending to banned users', async () => {
|
||||||
meta.config.sendEmailToBanned = 1;
|
Plugins.hooks.register('emailer-test', {
|
||||||
const success = await Emailer.send('test', recipientUid, {});
|
hook: 'filter:email.send',
|
||||||
assert.strictEqual(success, true);
|
method: async () => {
|
||||||
meta.config.sendEmailToBanned = 0;
|
assert(true); // if thrown, email was sent
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
after(() => {
|
meta.config.sendEmailToBanned = 1;
|
||||||
|
await Emailer.send('test', recipientUid, {});
|
||||||
|
meta.config.sendEmailToBanned = 0;
|
||||||
|
await user.bans.unban(recipientUid);
|
||||||
|
|
||||||
Plugins.hooks.unregister('emailer-test', 'filter:email.send');
|
Plugins.hooks.unregister('emailer-test', 'filter:email.send');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user