diff --git a/index.js b/index.js index bb81eaf..4d0ebc1 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,7 @@ const validOptions = Joi.array().items(Joi.object({ function register(server, opts) { const value = Joi.attempt(opts, validOptions); - const snsInstances = []; + const snsInstances = (server.plugins.hookido && server.plugins.hookido.snsInstances) || []; value.forEach((config) => init(config)); server.expose('snsInstances', snsInstances); return; @@ -80,5 +80,6 @@ function register(server, opts) { module.exports = { name: 'hookido', - register + register, + multiple: true }; diff --git a/test/index.test.js b/test/index.test.js index 76f22be..202858f 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -382,4 +382,41 @@ describe('Hookido Hapi Plugin', () => { expect(server.plugins.hookido.snsInstances).to.have.a.lengthOf(2); }); + + it('supports to load multiple times', async () => { + + const server = new Hapi.Server(); + + await server.register({ + plugin, + options: { + route: { + path: '/foobar' + }, + handlers: { + notification: () => {} + } + } + }); + + await server.register({ + plugin, + options: { + route: { + path: '/foobar2' + }, + handlers: { + notification: () => {} + } + } + }); + + const table = server.table(); + + expect(table[0].path).to.equal('/foobar'); + expect(table[1].path).to.equal('/foobar2'); + expect(server.plugins.hookido.snsInstances).to.have.a.lengthOf(2); + + }); + });