diff --git a/.travis.yml b/.travis.yml index 4e4cde7f5..d839ff4ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,12 @@ node_js: notifications: email: recipients: - - adam@apiary.io + - z@apiary.io - ladislav@apiary.io on_success: change on_failure: always + hipchat: + - secure: "pKDBboEmYne/Hs9qUSCQCgWZ9insdvgvB0DyMYYpO8RHgNOAhpcY1Kz/wTmFtm1k2HjGNGx1OVgVhOYXwIiJQZbmiUT4gVDEUtmpSgiW3/uQATgaPFUAsaIFqemTPgI6Q8RfsJZQk1kRMioZhk0ldQY5A+AUIKYKg1BFiOsrO1s=" after_success: - ./scripts/coveralls diff --git a/scripts/prepublish b/scripts/prepublish index e22687a59..a2ddb817c 100755 --- a/scripts/prepublish +++ b/scripts/prepublish @@ -1,3 +1,2 @@ #!/bin/sh -./scripts/test && ./scripts/build diff --git a/src/execute-transaction.coffee b/src/execute-transaction.coffee index e97f73ca6..b46ba7ce2 100644 --- a/src/execute-transaction.coffee +++ b/src/execute-transaction.coffee @@ -94,17 +94,20 @@ executeTransaction = (transaction, callback) -> configuration.emitter.emit 'test error', error, test if error res.on 'end', () -> - real = + + # The data models as used here must conform to Gavel.js + # as defined in `http-response.coffee` + real = + statusCode: res.statusCode headers: res.headers body: buffer - status: res.statusCode - expected = + expected = headers: flattenHeaders response['headers'] body: response['body'] - status: response['status'] + statusCode: response['status'] - expected['schema'] = response['schema'] if response['schema'] + expected['bodySchema'] = response['schema'] if response['schema'] gavel.isValid real, expected, 'response', (error, isValid) -> configuration.emitter.emit 'test error', error, test if error diff --git a/test/fixtures/schema.apib b/test/fixtures/schema.apib new file mode 100644 index 000000000..37bd38d99 --- /dev/null +++ b/test/fixtures/schema.apib @@ -0,0 +1,43 @@ +FORMAT: 1A + +# API +Demonstrates dredd schema test issue [#46](https://github.com/apiaryio/dredd/issues/46). Original API blueprint by @mgaut72. + +# Group Session + +## Session [/] + +### Log a user in [GET] ++ Response 200 (application/json) + + + Body + + { + "data": { + "token": "234khsdfs9d8fsdf", + "expires": 1424641830 + } + } + + + Schema + + { + "type":"object", + "required":true, + "properties":{ + "data": { + "type":"object", + "required":true, + "properties":{ + "expires": { + "type":"number", + "required":true + }, + "token": { + "type":"string", + "required":true + } + } + } + } + } diff --git a/test/fixtures/single_get.md b/test/fixtures/single-get.apib similarity index 78% rename from test/fixtures/single_get.md rename to test/fixtures/single-get.apib index b8f07f43d..ea678145f 100644 --- a/test/fixtures/single_get.md +++ b/test/fixtures/single-get.apib @@ -1,4 +1,4 @@ -FORMAT: X-1A +FORMAT: 1A # Machines API @@ -8,7 +8,7 @@ FORMAT: X-1A ## Get Machines [GET] -- Response 202 (application/json) +- Response 200 (application/json) [ { diff --git a/test/integration/cli-test.coffee b/test/integration/cli-test.coffee index 8a98c4d6f..c440a64f4 100644 --- a/test/integration/cli-test.coffee +++ b/test/integration/cli-test.coffee @@ -50,7 +50,7 @@ describe "Command line interface", () -> describe "when executing the command and the server is responding as specified in the blueprint", () -> before (done) -> - cmd = "./bin/dredd ./test/fixtures/single_get.md http://localhost:#{PORT}" + cmd = "./bin/dredd ./test/fixtures/single-get.apib http://localhost:#{PORT}" app = express() @@ -73,7 +73,7 @@ describe "Command line interface", () -> describe "when executing the command and the server is responding as specified in the blueprint, endpoint with path", () -> before (done) -> - cmd = "./bin/dredd ./test/fixtures/single_get.md http://localhost:#{PORT}/v2" + cmd = "./bin/dredd ./test/fixtures/single-get.apib http://localhost:#{PORT}/v2" app = express() @@ -96,7 +96,7 @@ describe "Command line interface", () -> describe "when executing the command and the server is sending different response", () -> before (done) -> - cmd = "./bin/dredd ./test/fixtures/single_get.md http://localhost:#{PORT}" + cmd = "./bin/dredd ./test/fixtures/single-get.apib http://localhost:#{PORT}" app = express() @@ -124,7 +124,7 @@ describe "Command line interface", () -> recievedRequest = {} before (done) -> - cmd = "./bin/dredd ./test/fixtures/single_get.md http://localhost:#{PORT} -r nyan" + cmd = "./bin/dredd ./test/fixtures/single-get.apib http://localhost:#{PORT} -r nyan" app = express() @@ -153,7 +153,7 @@ describe "Command line interface", () -> recievedRequest = {} before (done) -> - cmd = "./bin/dredd ./test/fixtures/single_get.md http://localhost:#{PORT} -r junit -o test_file_output.xml" + cmd = "./bin/dredd ./test/fixtures/single-get.apib http://localhost:#{PORT} -r junit -o test_file_output.xml" app = express() @@ -184,7 +184,7 @@ describe "Command line interface", () -> recievedRequest = {} before (done) -> - cmd = "./bin/dredd ./test/fixtures/single_get.md http://localhost:#{PORT} -h Accept:application/json" + cmd = "./bin/dredd ./test/fixtures/single-get.apib http://localhost:#{PORT} -h Accept:application/json" app = express() @@ -212,7 +212,7 @@ describe "Command line interface", () -> recievedRequest = {} before (done) -> - cmd = "./bin/dredd ./test/fixtures/single_get.md http://localhost:#{PORT} -u username:password" + cmd = "./bin/dredd ./test/fixtures/single-get.apib http://localhost:#{PORT} -u username:password" app = express() @@ -268,7 +268,7 @@ describe "Command line interface", () -> describe 'when displaying errors inline with -e', () -> before (done) -> - cmd = "./bin/dredd ./test/fixtures/single_get.md http://localhost:#{PORT} -e" + cmd = "./bin/dredd ./test/fixtures/single-get.apib http://localhost:#{PORT} -e" app = express() @@ -297,7 +297,7 @@ describe "Command line interface", () -> recievedRequest = {} before (done) -> - cmd = "./bin/dredd ./test/fixtures/single_get.md http://localhost:#{PORT} -d" + cmd = "./bin/dredd ./test/fixtures/single-get.apib http://localhost:#{PORT} -d" app = express() @@ -327,7 +327,7 @@ describe "Command line interface", () -> recievedRequest = {} before (done) -> - cmd = "./bin/dredd ./test/fixtures/single_get.md http://localhost:#{PORT} -m POST" + cmd = "./bin/dredd ./test/fixtures/single-get.apib http://localhost:#{PORT} -m POST" app = express() @@ -354,7 +354,7 @@ describe "Command line interface", () -> recievedRequest = {} before (done) -> - cmd = "./bin/dredd ./test/fixtures/single_get.md http://localhost:#{PORT} -m GET" + cmd = "./bin/dredd ./test/fixtures/single-get.apib http://localhost:#{PORT} -m GET" app = express() @@ -381,7 +381,7 @@ describe "Command line interface", () -> recievedRequest = {} before (done) -> - cmd = "./bin/dredd ./test/fixtures/single_get.md http://localhost:#{PORT} --no-color" + cmd = "./bin/dredd ./test/fixtures/single-get.apib http://localhost:#{PORT} --no-color" app = express() @@ -410,7 +410,7 @@ describe "Command line interface", () -> recievedRequest = {} before (done) -> - cmd = "./bin/dredd ./test/fixtures/single_get.md http://localhost:#{PORT} -l=error" + cmd = "./bin/dredd ./test/fixtures/single-get.apib http://localhost:#{PORT} -l=error" app = express() @@ -438,7 +438,7 @@ describe "Command line interface", () -> recievedRequest = {} before (done) -> - cmd = "./bin/dredd ./test/fixtures/single_get.md http://localhost:#{PORT} -t" + cmd = "./bin/dredd ./test/fixtures/single-get.apib http://localhost:#{PORT} -t" app = express() @@ -460,3 +460,54 @@ describe "Command line interface", () -> it 'should display timestamps', () -> # look for the prefix for cli output with timestamps assert.notEqual stdout.indexOf 'Z -', -1 + + describe "tests a blueprint containing an endpoint with schema", () -> + describe "and server is responding in accordance with the schema", () -> + + before (done) -> + cmd = "./bin/dredd ./test/fixtures/schema.apib http://localhost:#{PORT}" + + app = express() + + app.get '/', (req, res) -> + res.setHeader 'Content-Type', 'application/json' + response = + data: + expires: 1234, + token: 'this should pass since it is a string' + + res.send 200, response + + server = app.listen PORT, () -> + execCommand cmd, () -> + server.close() + + server.on 'close', done + + it 'exit status should be 0 (success)', () -> + assert.equal exitStatus, 0 + + describe "and server is NOT responding in accordance with the schema", () -> + + before (done) -> + cmd = "./bin/dredd ./test/fixtures/schema.apib http://localhost:#{PORT}" + + app = express() + + app.get '/', (req, res) -> + res.setHeader 'Content-Type', 'application/json' + response = + data: + expires: 'this should fail since it is a string', + token: 'this should pass since it is a string' + + res.send 200, response + + server = app.listen PORT, () -> + execCommand cmd, () -> + server.close() + + server.on 'close', done + + it 'exit status should be 1 (failure)', () -> + assert.equal exitStatus, 1