Skip to content

Commit

Permalink
add test for onServerPreHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
StarpTech committed Nov 5, 2017
1 parent 6225f40 commit a5f80dd
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/hemera/server-extension-errors.spec.js
Expand Up @@ -121,6 +121,58 @@ describe('Server Extension error', function() {
})
})

it('Should be able to pass an error to onServerPreHandler', function(done) {
const nats = require('nats').connect(authUrl)

const hemera = new Hemera(nats)

let plugin = function(hemera, options, done) {
hemera.ext('onServerPreHandler', function(ctx, req, res, next) {
next(new Error('test'))
})

hemera.add(
{
cmd: 'add',
topic: 'math'
},
(resp, cb) => {
cb(null, resp.a + resp.b)
}
)

done()
}

hemera.use({
plugin: plugin,
options: {
name: 'myPlugin'
}
})

hemera.ready(() => {
hemera.act(
{
topic: 'math',
cmd: 'add',
a: 1,
b: 2
},
(err, resp) => {
expect(err).to.be.exists()
expect(err.name).to.be.equals('Error')
expect(err.message).to.be.equals('test')
expect(err.hops).to.be.exists()
expect(err.hops.length).to.be.equals(1)
expect(err.hops[0].service).to.be.equals('math')
expect(err.hops[0].method).to.be.equals('a:1,b:2,cmd:add,topic:math')
hemera.close(done)
}
)
})
})

it('Should be able to pass a custom super error to onServerPreResponse', function(
done
) {
Expand Down

0 comments on commit a5f80dd

Please sign in to comment.