Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more verbose JSON schema validation messages #70

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/test-runner.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,21 @@ class TestRunner
test.request.server = server
_.extend(test.request.headers, options.header)

addTestToMocha test, hooks
# added hacky support for multiple test cased per api endpoint
# credit: https://github.com/lovelybooks/abao/commit/b6c79e14332e73b2ccd6d5e0531a1541d6dea076
regex = new RegExp('^' + test.name, 'i')
found = false
_.each _.keys(hooks.beforeHooks), (key) ->
if regex.test(key)
newTest = _.clone(test)
newTest.name = key
addTestToMocha newTest, hooks
found = true
return

if !found
addTestToMocha test, hooks

done()
, callback
, # Run mocha
Expand Down
14 changes: 12 additions & 2 deletions lib/test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Test

options = _.pick @request, 'headers', 'method'
options['url'] = @url()
options['body'] = JSON.stringify @request.body
options['body'] = JSON.stringify @request.body if options['method'] != 'HEAD'
options['qs'] = @request.query

async.waterfall [
Expand All @@ -80,6 +80,9 @@ class Test
assert.isNull error
assert.isNotNull response, 'Response'

# Headers
@response.headers = response.headers

# Status code
assert.equal response.statusCode, @response.status, """
Got unexpected response code:
Expand All @@ -101,8 +104,15 @@ class Test

json = validateJson()
result = tv4.validateResult json, schema

assert.lengthOf result.missing, 0, """
Missing / unresolved JSON schema $refs (#{result.missing?.join(', ')}) in schema:
#{JSON.stringify(schema, null, 4)}
Error
"""

assert.ok result.valid, """
Got unexpected response body:
Got unexpected response body: #{result.error?.message}
#{JSON.stringify(json, null, 4)}
Error
"""
Expand Down
Loading