-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1194 from ricardo-devis-agullo/available-plugins
Available plugins
- Loading branch information
Showing
7 changed files
with
121 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
module.exports = function(conf) { | ||
return function(req, res) { | ||
if (conf.discovery) { | ||
const plugins = Object.entries(conf.plugins).map( | ||
([pluginName, pluginFn]) => ({ | ||
name: pluginName, | ||
description: pluginFn.toString() | ||
}) | ||
); | ||
|
||
res.status(200).json(plugins); | ||
} else { | ||
res.status(401); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module.exports = vm => { | ||
const pluginRow = ([ | ||
name, | ||
description | ||
]) => `<div class="componentRow row table"> | ||
<p class="release"> | ||
<span style="font-weight: bold">${name + | ||
(description ? ':' : '')}</span>${description} | ||
</p> | ||
</div> | ||
`; | ||
|
||
const plugins = Object.entries( | ||
vm.availablePlugins | ||
).map(([pluginName, fn]) => [pluginName, fn.toString()]); | ||
|
||
return `<div id="components-plugins" class="box">${ | ||
plugins.length ? plugins.map(pluginRow).join('') : 'No plugins registered' | ||
}</div>`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const sinon = require('sinon'); | ||
|
||
describe('registry : routes : plugins', () => { | ||
const PluginsRoute = require('../../src/registry/routes/plugins'); | ||
let resJsonStub, statusStub, pluginsRoute, plugins; | ||
|
||
const initialise = function() { | ||
resJsonStub = sinon.stub(); | ||
statusStub = sinon.stub().returns({ json: resJsonStub }); | ||
const plugin1 = () => {}; | ||
plugin1.toString = () => 'Description plugin 1'; | ||
const plugin2 = () => {}; | ||
plugin2.toString = () => ''; | ||
plugins = { | ||
plugin1, | ||
plugin2 | ||
}; | ||
}; | ||
|
||
describe('when is not discoverable', () => { | ||
before(() => { | ||
initialise(); | ||
const conf = { | ||
plugins, | ||
discovery: false | ||
}; | ||
pluginsRoute = new PluginsRoute(conf); | ||
|
||
pluginsRoute({ headers: {} }, { conf, status: statusStub }); | ||
}); | ||
|
||
it('should return 401 status code', () => { | ||
expect(statusStub.args[0][0]).to.be.equal(401); | ||
}); | ||
}); | ||
|
||
describe('when is discoverable', () => { | ||
before(() => { | ||
initialise(); | ||
const conf = { | ||
plugins, | ||
discovery: true | ||
}; | ||
pluginsRoute = new PluginsRoute(conf); | ||
|
||
pluginsRoute({ headers: {} }, { conf, status: statusStub }); | ||
}); | ||
|
||
it('should return the list of plugins', () => { | ||
expect(resJsonStub.args[0][0]).to.eql([ | ||
{ name: 'plugin1', description: 'Description plugin 1' }, | ||
{ name: 'plugin2', description: '' } | ||
]); | ||
}); | ||
}); | ||
}); |