diff --git a/lib/context.js b/lib/context.js index 2cffee5..6fbe699 100644 --- a/lib/context.js +++ b/lib/context.js @@ -5,6 +5,10 @@ module.exports = class Context { this.payload = event.payload; } + halt() { + return Promise.reject(new Error('halted')); + } + toRepo(object) { const repo = this.payload.repository; diff --git a/lib/plugins/filter.js b/lib/plugins/filter.js index 648069c..80acfcf 100644 --- a/lib/plugins/filter.js +++ b/lib/plugins/filter.js @@ -1,13 +1,9 @@ const Plugin = require('../plugin'); -function halt() { - return Promise.reject(new Error('halted')); -} - module.exports = class Filter extends Plugin { filter(context, fn) { const result = fn(context.event, context); - return result === false ? halt() : result; + return result === false ? context.halt() : result; } then(context, fn) { @@ -21,6 +17,6 @@ module.exports = class Filter extends Plugin { return name === event.event && (!action || action === event.payload.action); }); - return res ? Promise.resolve(res) : halt(); + return res ? Promise.resolve(res) : context.halt(); } }; diff --git a/test/plugins/filter.js b/test/plugins/filter.js index 53e78b0..163369b 100644 --- a/test/plugins/filter.js +++ b/test/plugins/filter.js @@ -5,7 +5,10 @@ const createSpy = expect.createSpy; describe('filter plugin', () => { const event = {}; - const context = {event}; + const context = { + event, + halt: createSpy().andReturn(Promise.reject(new Error('halted'))) + }; let filter;