mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-11 01:52:55 +01:00
fix: properly unregister hooks in emailer tests
This commit is contained in:
@@ -49,22 +49,23 @@ describe('emailer', () => {
|
|||||||
|
|
||||||
it('plugin hook should work', (done) => {
|
it('plugin hook should work', (done) => {
|
||||||
const error = new Error();
|
const error = new Error();
|
||||||
|
const method = function (data, next) {
|
||||||
|
assert(data);
|
||||||
|
assert.equal(data.to, email);
|
||||||
|
assert.equal(data.subject, `[NodeBB] ${params.subject}`);
|
||||||
|
|
||||||
|
next(error);
|
||||||
|
};
|
||||||
|
|
||||||
Plugins.hooks.register('emailer-test', {
|
Plugins.hooks.register('emailer-test', {
|
||||||
hook: 'filter:email.send',
|
hook: 'filter:email.send',
|
||||||
method: function (data, next) {
|
method,
|
||||||
assert(data);
|
|
||||||
assert.equal(data.to, email);
|
|
||||||
assert.equal(data.subject, `[NodeBB] ${params.subject}`);
|
|
||||||
|
|
||||||
next(error);
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Emailer.sendToEmail(template, email, language, params, (err) => {
|
Emailer.sendToEmail(template, email, language, params, (err) => {
|
||||||
assert.equal(err, error);
|
assert.equal(err, error);
|
||||||
|
|
||||||
Plugins.hooks.unregister('emailer-test', 'filter:email.send');
|
Plugins.hooks.unregister('emailer-test', 'filter:email.send', method);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -152,37 +153,40 @@ describe('emailer', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not send email to a banned user', async () => {
|
it('should not send email to a banned user', async () => {
|
||||||
|
const method = async () => {
|
||||||
|
assert(false); // if thrown, email was sent
|
||||||
|
};
|
||||||
Plugins.hooks.register('emailer-test', {
|
Plugins.hooks.register('emailer-test', {
|
||||||
hook: 'filter:email.send',
|
hook: 'filter:email.send',
|
||||||
method: async () => {
|
method,
|
||||||
assert(false); // if thrown, email was sent
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await user.bans.ban(recipientUid);
|
await user.bans.ban(recipientUid);
|
||||||
await Emailer.send('test', recipientUid, {});
|
await Emailer.send('test', recipientUid, {});
|
||||||
|
|
||||||
Plugins.hooks.unregister('emailer-test', 'filter:email.send');
|
Plugins.hooks.unregister('emailer-test', 'filter:email.send', method);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true if the template is "banned"', async () => {
|
it('should return true if the template is "banned"', async () => {
|
||||||
|
const method = async () => {
|
||||||
|
assert(true); // if thrown, email was sent
|
||||||
|
};
|
||||||
Plugins.hooks.register('emailer-test', {
|
Plugins.hooks.register('emailer-test', {
|
||||||
hook: 'filter:email.send',
|
hook: 'filter:email.send',
|
||||||
method: async () => {
|
method,
|
||||||
assert(true); // if thrown, email was sent
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await Emailer.send('banned', recipientUid, {});
|
await Emailer.send('banned', recipientUid, {});
|
||||||
Plugins.hooks.unregister('emailer-test', 'filter:email.send');
|
Plugins.hooks.unregister('emailer-test', 'filter:email.send', method);
|
||||||
});
|
});
|
||||||
|
|
||||||
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 () => {
|
||||||
|
const method = async () => {
|
||||||
|
assert(true); // if thrown, email was sent
|
||||||
|
};
|
||||||
Plugins.hooks.register('emailer-test', {
|
Plugins.hooks.register('emailer-test', {
|
||||||
hook: 'filter:email.send',
|
hook: 'filter:email.send',
|
||||||
method: async () => {
|
method,
|
||||||
assert(true); // if thrown, email was sent
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
meta.config.sendEmailToBanned = 1;
|
meta.config.sendEmailToBanned = 1;
|
||||||
@@ -190,7 +194,7 @@ describe('emailer', () => {
|
|||||||
meta.config.sendEmailToBanned = 0;
|
meta.config.sendEmailToBanned = 0;
|
||||||
await user.bans.unban(recipientUid);
|
await user.bans.unban(recipientUid);
|
||||||
|
|
||||||
Plugins.hooks.unregister('emailer-test', 'filter:email.send');
|
Plugins.hooks.unregister('emailer-test', 'filter:email.send', method);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user