Skip to content

Commit

Permalink
fix: don't allow repeated names (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoRBaquero committed Mar 21, 2020
1 parent 56ed2c5 commit 682d445
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ module.exports = (_manifest) => {

const minions = manifest.workers.reduce((minionsByName, worker) => {

if (minionsByName[worker.config.name]) {
throw new Error(`Repeated ${worker.config.name} worker name`);
}

const handlerWithValidation = validatorFactory(worker.handler, worker.validate || Joi.any());
const workerConfig = {
autoStart: false,
Expand Down
34 changes: 34 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,40 @@ Test('Creates army from manifest and workers work', async (t) => {
t.is(await army.minions.trueing.handle('hola'), true);
});

Test('Fails to create army from manifest with repeated names', (t) => {

const manifest = {
connection: {
rabbit: {
topic: () => ({
publish: () => {}
})
}
},
defaults: {
exchangeName: 'my-exchange-name'
},
workers: [
{
handler: (message) => message,
config: {
name: 'logging',
key: 'events.something.happened'
}
},
{
handler: (message) => message,
config: {
name: 'logging',
key: 'events.something.happened'
}
}
]
};

t.throws(() => Army(manifest));
});

Test('Creates army from manifest and workers start', async (t) => {

const emitter = new EventEmitter();
Expand Down

0 comments on commit 682d445

Please sign in to comment.