fix: removed methods

v1.18.x
Barış Soner Uşaklı 4 years ago
parent 05be1c6603
commit 647d3ba810

@ -5,8 +5,7 @@ const async = require('async');
const utils = require('../utils');
const plugins = require('.');
const Hooks = {};
module.exports = Hooks;
const Hooks = module.exports;
Hooks.deprecatedHooks = {
'filter:router.page': 'response:router.page', // 👋 @ 2.0.0

@ -12,7 +12,7 @@ const Write = module.exports;
Write.reload = async (params) => {
const router = params.router;
let apiSettings = await meta.settings.get('core.api');
plugins.registerHook('core', {
plugins.hooks.register('core', {
hook: 'action:settings.set',
method: async (data) => {
if (data.plugin === 'core.api') {

@ -85,8 +85,8 @@ describe('API', async () => {
}
after(async function () {
plugins.unregisterHook('core', 'filter:search.query', dummySearchHook);
plugins.unregisterHook('emailer-test', 'filter:email.send');
plugins.hooks.unregister('core', 'filter:search.query', dummySearchHook);
plugins.hooks.unregister('emailer-test', 'filter:email.send');
});
async function setupData() {
@ -163,12 +163,12 @@ describe('API', async () => {
await wait(5000);
// Attach a search hook so /api/search is enabled
plugins.registerHook('core', {
plugins.hooks.register('core', {
hook: 'filter:search.query',
method: dummySearchHook,
});
// Attach an emailer hook so related requests do not error
plugins.registerHook('emailer-test', {
plugins.hooks.register('emailer-test', {
hook: 'filter:email.send',
method: dummyEmailerHook,
});

@ -895,7 +895,7 @@ describe('Categories', function () {
callback(null, data);
}
plugins.registerHook('my-test-plugin', {
plugins.hooks.register('my-test-plugin', {
hook: 'filter:categories.getTopicIds',
method: method,
});
@ -907,7 +907,7 @@ describe('Categories', function () {
}, function (err, tids) {
assert.ifError(err);
assert.deepEqual(tids, [1, 2, 3]);
plugins.unregisterHook('my-test-plugin', 'filter:categories.getTopicIds', method);
plugins.hooks.unregister('my-test-plugin', 'filter:categories.getTopicIds', method);
done();
});
});

@ -649,7 +649,7 @@ describe('Admin Controllers', function () {
config.script = '</script>';
callback(null, config);
}
plugins.registerHook('somePlugin', { hook: 'filter:config.get', method: onConfigGet });
plugins.hooks.register('somePlugin', { hook: 'filter:config.get', method: onConfigGet });
request(nconf.get('url') + '/admin', { jar: jar }, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
@ -664,7 +664,7 @@ describe('Admin Controllers', function () {
assert(body.includes('"someValue":"\\\\"foo\\\\""'));
assert(body.includes('"otherValue":"\\\'123\\\'"'));
assert(body.includes('"script":"<\\/script>"'));
plugins.unregisterHook('somePlugin', 'filter:config.get', onConfigGet);
plugins.hooks.unregister('somePlugin', 'filter:config.get', onConfigGet);
done();
});
});

@ -104,7 +104,7 @@ describe('Controllers', function () {
var tplPath = path.join(nconf.get('views_dir'), name);
before(async () => {
plugins.registerHook('myTestPlugin', {
plugins.hooks.register('myTestPlugin', {
hook: 'action:homepage.get:mycustompage',
method: hookMethod,
});
@ -255,7 +255,7 @@ describe('Controllers', function () {
});
after(function () {
plugins.unregisterHook('myTestPlugin', 'action:homepage.get:custom', hookMethod);
plugins.hooks.unregister('myTestPlugin', 'action:homepage.get:custom', hookMethod);
fs.unlinkSync(tplPath);
fs.unlinkSync(tplPath.replace(/\.tpl$/, '.js'));
});
@ -303,7 +303,7 @@ describe('Controllers', function () {
next(null, data);
}
plugins.registerHook('myTestPlugin', {
plugins.hooks.register('myTestPlugin', {
hook: 'filter:register.interstitial',
method: hookMethod,
});
@ -343,7 +343,7 @@ describe('Controllers', function () {
assert(body.sections);
assert(body.errors);
assert(body.title);
plugins.unregisterHook('myTestPlugin', 'filter:register.interstitial', hookMethod);
plugins.hooks.unregister('myTestPlugin', 'filter:register.interstitial', hookMethod);
done();
});
});
@ -2244,7 +2244,7 @@ describe('Controllers', function () {
callback(null, hookData);
}
plugins.registerHook('myTestPlugin', {
plugins.hooks.register('myTestPlugin', {
hook: 'filter:composer.build',
method: hookMethod,
});
@ -2256,7 +2256,7 @@ describe('Controllers', function () {
assert.strictEqual(body.template.name, '');
assert.strictEqual(body.url, nconf.get('relative_path') + '/compose');
plugins.unregisterHook('myTestPlugin', 'filter:composer.build', hookMethod);
plugins.hooks.unregister('myTestPlugin', 'filter:composer.build', hookMethod);
done();
});
});
@ -2266,7 +2266,7 @@ describe('Controllers', function () {
hookData.next();
}
plugins.registerHook('myTestPlugin', {
plugins.hooks.register('myTestPlugin', {
hook: 'filter:composer.build',
method: hookMethod,
});
@ -2275,7 +2275,7 @@ describe('Controllers', function () {
assert.ifError(err);
assert.equal(res.statusCode, 404);
plugins.unregisterHook('myTestPlugin', 'filter:composer.build', hookMethod);
plugins.hooks.unregister('myTestPlugin', 'filter:composer.build', hookMethod);
done();
});
});

@ -48,7 +48,7 @@ describe('emailer', function () {
it('plugin hook should work', function (done) {
var error = new Error();
Plugins.registerHook('emailer-test', {
Plugins.hooks.register('emailer-test', {
hook: 'filter:email.send',
method: function (data, next) {
assert(data);
@ -62,7 +62,7 @@ describe('emailer', function () {
Emailer.sendToEmail(template, email, language, params, function (err) {
assert.equal(err, error);
Plugins.unregisterHook('emailer-test', 'filter:email.send');
Plugins.hooks.unregister('emailer-test', 'filter:email.send');
done();
});
});

@ -23,7 +23,7 @@ describe('Plugins', function () {
});
it('should return true if hook has listeners', function (done) {
assert(plugins.hasListeners('filter:parse.post'));
assert(plugins.hooks.hasListeners('filter:parse.post'));
done();
});
@ -37,10 +37,10 @@ describe('Plugins', function () {
callback(null, data);
}
plugins.registerHook('test-plugin', { hook: 'filter:test.hook', method: filterMethod1 });
plugins.registerHook('test-plugin', { hook: 'filter:test.hook', method: filterMethod2 });
plugins.hooks.register('test-plugin', { hook: 'filter:test.hook', method: filterMethod1 });
plugins.hooks.register('test-plugin', { hook: 'filter:test.hook', method: filterMethod2 });
plugins.fireHook('filter:test.hook', { foo: 1 }, function (err, data) {
plugins.hooks.fire('filter:test.hook', { foo: 1 }, function (err, data) {
assert.ifError(err);
assert.equal(data.foo, 7);
done();
@ -59,10 +59,10 @@ describe('Plugins', function () {
});
}
plugins.registerHook('test-plugin', { hook: 'filter:test.hook2', method: method1 });
plugins.registerHook('test-plugin', { hook: 'filter:test.hook2', method: method2 });
plugins.hooks.register('test-plugin', { hook: 'filter:test.hook2', method: method1 });
plugins.hooks.register('test-plugin', { hook: 'filter:test.hook2', method: method2 });
plugins.fireHook('filter:test.hook2', { foo: 1 }, function (err, data) {
plugins.hooks.fire('filter:test.hook2', { foo: 1 }, function (err, data) {
assert.ifError(err);
assert.equal(data.foo, 7);
done();
@ -76,8 +76,8 @@ describe('Plugins', function () {
reject(new Error('nope'));
});
}
plugins.registerHook('test-plugin', { hook: 'filter:test.hook3', method: method });
plugins.fireHook('filter:test.hook3', { foo: 1 }, function (err) {
plugins.hooks.register('test-plugin', { hook: 'filter:test.hook3', method: method });
plugins.hooks.fire('filter:test.hook3', { foo: 1 }, function (err) {
assert(err);
done();
});
@ -89,8 +89,8 @@ describe('Plugins', function () {
done();
}
plugins.registerHook('test-plugin', { hook: 'action:test.hook', method: actionMethod });
plugins.fireHook('action:test.hook', { bar: 'test' });
plugins.hooks.register('test-plugin', { hook: 'action:test.hook', method: actionMethod });
plugins.hooks.fire('action:test.hook', { bar: 'test' });
});
it('should register and fire a static hook', function (done) {
@ -99,8 +99,8 @@ describe('Plugins', function () {
callback();
}
plugins.registerHook('test-plugin', { hook: 'static:test.hook', method: actionMethod });
plugins.fireHook('static:test.hook', { bar: 'test' }, function (err) {
plugins.hooks.register('test-plugin', { hook: 'static:test.hook', method: actionMethod });
plugins.hooks.fire('static:test.hook', { bar: 'test' }, function (err) {
assert.ifError(err);
done();
});
@ -113,8 +113,8 @@ describe('Plugins', function () {
resolve();
});
}
plugins.registerHook('test-plugin', { hook: 'static:test.hook', method: method });
plugins.fireHook('static:test.hook', { bar: 'test' }, function (err) {
plugins.hooks.register('test-plugin', { hook: 'static:test.hook', method: method });
plugins.hooks.fire('static:test.hook', { bar: 'test' }, function (err) {
assert.ifError(err);
done();
});
@ -127,10 +127,10 @@ describe('Plugins', function () {
reject(new Error('just because'));
});
}
plugins.registerHook('test-plugin', { hook: 'static:test.hook', method: method });
plugins.fireHook('static:test.hook', { bar: 'test' }, function (err) {
plugins.hooks.register('test-plugin', { hook: 'static:test.hook', method: method });
plugins.hooks.fire('static:test.hook', { bar: 'test' }, function (err) {
assert.strictEqual(err.message, 'just because');
plugins.unregisterHook('test-plugin', 'static:test.hook', method);
plugins.hooks.unregister('test-plugin', 'static:test.hook', method);
done();
});
});
@ -142,10 +142,10 @@ describe('Plugins', function () {
setTimeout(resolve, 6000);
});
}
plugins.registerHook('test-plugin', { hook: 'static:test.hook', method: method });
plugins.fireHook('static:test.hook', { bar: 'test' }, function (err) {
plugins.hooks.register('test-plugin', { hook: 'static:test.hook', method: method });
plugins.hooks.fire('static:test.hook', { bar: 'test' }, function (err) {
assert.ifError(err);
plugins.unregisterHook('test-plugin', 'static:test.hook', method);
plugins.hooks.unregister('test-plugin', 'static:test.hook', method);
done();
});
});

@ -247,13 +247,13 @@ describe('socket.io', function () {
}
before(function () {
// Attach an emailer hook so related requests do not error
plugins.registerHook('emailer-test', {
plugins.hooks.register('emailer-test', {
hook: 'filter:email.send',
method: dummyEmailerHook,
});
});
after(function () {
plugins.unregisterHook('emailer-test', 'filter:email.send');
plugins.hooks.unregister('emailer-test', 'filter:email.send');
});
it('should validate emails', function (done) {

@ -2165,7 +2165,7 @@ describe('Topic\'s', function () {
it('should return results', function (done) {
var plugins = require('../src/plugins');
plugins.registerHook('myTestPlugin', {
plugins.hooks.register('myTestPlugin', {
hook: 'filter:topic.search',
method: function (data, callback) {
callback(null, [1, 2, 3]);

@ -32,7 +32,7 @@ describe('User', function () {
}
before(function (done) {
// Attach an emailer hook so related requests do not error
plugins.registerHook('emailer-test', {
plugins.hooks.register('emailer-test', {
hook: 'filter:email.send',
method: dummyEmailerHook,
});
@ -51,7 +51,7 @@ describe('User', function () {
});
});
after(function () {
plugins.unregisterHook('emailer-test', 'filter:email.send');
plugins.hooks.unregister('emailer-test', 'filter:email.send');
});
beforeEach(function () {
@ -743,12 +743,12 @@ describe('User', function () {
callback(null, data);
}
plugins.registerHook('test-plugin', { hook: 'filter:user.whitelistFields', method: filterMethod });
plugins.hooks.register('test-plugin', { hook: 'filter:user.whitelistFields', method: filterMethod });
User.getUserData(testUid, function (err, userData) {
assert.ifError(err);
assert(!userData.hasOwnProperty('fb_token'));
assert.equal(userData.another_secret, 'abcde');
plugins.unregisterHook('test-plugin', 'filter:user.whitelistFields', filterMethod);
plugins.hooks.unregister('test-plugin', 'filter:user.whitelistFields', filterMethod);
done();
});
});

Loading…
Cancel
Save