Skip to content

Commit

Permalink
fix validateMessage with message schema type string
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmehta committed Feb 22, 2018
1 parent 60a1df5 commit 7860f52
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A schema definition module for RabbitMQ graphs and messages",
"main": "index.js",
"scripts": {
"test": "lab --verbose --assert code --threshold 100",
"test": "lab --verbose --assert code --threshold 100 --globals Reflect,WebAssembly",
"test-watch": "nodemon -x npm test",
"lint": "standard",
"format": "standard --format"
Expand Down
39 changes: 39 additions & 0 deletions test/schema.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,45 @@ describe('rabbitmq-schema', function () {
done()
})
})

describe('direct queue w/ string message queue', function () {
beforeEach(function (done) {
ctx.queue = {
queue: 'string-queue-name',
options: {},
messageSchema: {
$schema: 'http://json-schema.org/draft-04/schema#',
description: 'string-queue-name message',
type: 'string',
}
}
ctx.validMessage = 'hello'
ctx.schema = new RabbitSchema(ctx.queue)
done()
})

it('should error if queue does not exist', function (done) {
var schema = ctx.schema
expect(
schema.validateMessage.bind(schema, '', 'non-existant-queue', {})
).to.throw(/queue.*does not exist/)
done()
})

it('should error if the message is invalid for any destination queues', function (done) {
var schema = ctx.schema
expect(
schema.validateMessage.bind(schema, 'string-queue-name', {})
).to.throw(/should be string/)
done()
})

it('should pass if the message is valid', function (done) {
// expect no errors
ctx.schema.validateMessage('', 'string-queue-name', ctx.validMessage)
done()
})
})
})

describe('largeSchema', function () {
Expand Down

0 comments on commit 7860f52

Please sign in to comment.