Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Fix Dredd / Gavel.js interface. Closes #46 #49

Merged
merged 7 commits into from
Mar 3, 2014
Merged
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
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ node_js:
notifications:
email:
recipients:
- adam@apiary.io
- z@apiary.io
- [email protected]
on_success: change
on_failure: always
hipchat:
- secure: "pKDBboEmYne/Hs9qUSCQCgWZ9insdvgvB0DyMYYpO8RHgNOAhpcY1Kz/wTmFtm1k2HjGNGx1OVgVhOYXwIiJQZbmiUT4gVDEUtmpSgiW3/uQATgaPFUAsaIFqemTPgI6Q8RfsJZQk1kRMioZhk0ldQY5A+AUIKYKg1BFiOsrO1s="
after_success:
- ./scripts/coveralls

1 change: 0 additions & 1 deletion scripts/prepublish
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/bin/sh
./scripts/test &&
./scripts/build
13 changes: 8 additions & 5 deletions src/execute-transaction.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions test/fixtures/schema.apib
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
}
4 changes: 2 additions & 2 deletions test/fixtures/single_get.md → test/fixtures/single-get.apib
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FORMAT: X-1A
FORMAT: 1A

# Machines API

Expand All @@ -8,7 +8,7 @@ FORMAT: X-1A

## Get Machines [GET]

- Response 202 (application/json)
- Response 200 (application/json)

[
{
Expand Down
79 changes: 65 additions & 14 deletions test/integration/cli-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand All @@ -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