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 utils = require('../utils');
const plugins = require('.'); const plugins = require('.');
const Hooks = {}; const Hooks = module.exports;
module.exports = Hooks;
Hooks.deprecatedHooks = { Hooks.deprecatedHooks = {
'filter:router.page': 'response:router.page', // 👋 @ 2.0.0 'filter:router.page': 'response:router.page', // 👋 @ 2.0.0

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save