This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #616 from apiaryio/honzajavorek/use-just-1st-req-res
- Loading branch information
Showing
8 changed files
with
217 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FORMAT: 1A | ||
|
||
# Beehive API | ||
|
||
## Honey [/honey] | ||
|
||
### Retrieve [GET] | ||
|
||
+ Request (application/json) | ||
+ Request (application/xml) | ||
+ Response 200 | ||
+ Response 500 | ||
|
||
### Remove [DELETE] | ||
|
||
+ Request (application/json) | ||
+ Response 200 | ||
+ Response 403 | ||
+ Response 500 | ||
|
||
+ Request (text/plain) | ||
+ Response 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
var hooks = require('hooks'); | ||
|
||
|
||
function logTransactionName(transaction, done) { | ||
hooks.log(transaction.name); | ||
done(); | ||
} | ||
|
||
|
||
hooks.before('/honey > GET > 400 > application/json', logTransactionName); | ||
hooks.before('/honey > GET > 500 > application/json', logTransactionName); | ||
hooks.before('/honey > GET > 200 > application/json', logTransactionName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
{assert} = require 'chai' | ||
{exec} = require 'child_process' | ||
express = require 'express' | ||
clone = require 'clone' | ||
|
||
|
||
PORT = 3333 | ||
DREDD_BIN = require.resolve '../../bin/dredd' | ||
|
||
|
||
runDredd = (descriptionFile, cb) -> | ||
result = {} | ||
cmd = "#{DREDD_BIN} #{descriptionFile} http://localhost:#{PORT} -ed --no-color" | ||
|
||
cli = exec cmd, (err, stdout, stderr) -> | ||
result.exitStatus = err?.code or null | ||
result.stdout = '' + stdout | ||
result.stderr = '' + stderr | ||
|
||
cli.on 'close', (code) -> | ||
result.exitStatus ?= code if code | ||
cb null, result | ||
|
||
|
||
parseJSON = (body) -> | ||
return undefined unless body | ||
try | ||
JSON.parse body | ||
catch | ||
body | ||
|
||
|
||
# This can be removed once https://github.com/apiaryio/dredd/issues/341 is done | ||
parseOutput = (output) -> | ||
# Parse individual entries (deals also with multi-line entries) | ||
entries = [] | ||
entry = undefined | ||
for line in output.split /\r?\n/ | ||
match = line.match /^(\w+): (.+)?$/ | ||
if match | ||
if entry | ||
entry.body = entry.body.trim() | ||
entries.push entry | ||
entry = {label: match[1], body: match[2] or ''} | ||
else | ||
entry.body += "\n#{line.trim()}" | ||
|
||
# Correction of following situation: | ||
# | ||
# fail: POST /customers duration: 13ms | ||
# fail: body: At '/name' Invalid type: null (expected string) | ||
# body: At '/shoeSize' Invalid type: string (expected number) | ||
entries = entries.filter (entry, i) -> | ||
previousEntry = entries[i - 1] | ||
if entry.label is 'body' and previousEntry.label is 'fail' | ||
previousEntry.body += '\n' + entry.body | ||
return false | ||
return true | ||
|
||
# Re-arrange data from entries | ||
results = {summary: '', failures: []} | ||
for entry in entries | ||
switch entry.label | ||
when 'complete' then results.summary = entry.body | ||
when 'fail' then results.failures.push entry.body | ||
return results | ||
|
||
|
||
describe 'Regression: Issue #615', -> | ||
requests = [] | ||
results = undefined | ||
|
||
beforeEach (done) -> | ||
app = express() | ||
|
||
# Attaching endpoint for each testing scenario | ||
app.all '/honey', (req, res) -> | ||
res.status(200).send '' | ||
|
||
# Spinning up the Express server, running Dredd, and saving results | ||
server = app.listen PORT, -> | ||
runDredd './test/fixtures/regression-615.apib', (err, result) -> | ||
results = parseOutput result.stdout | ||
server.close done | ||
|
||
it 'outputs no failures', -> | ||
# Intentionally not testing just '.length' as this approach will output the difference | ||
assert.deepEqual results.failures, [] | ||
it 'results in exactly three tests', -> | ||
assert.include results.summary, '3 total' | ||
it 'results in three passing tests', -> | ||
# Ensures just the 200 responses were selected, because the server returns only 200s | ||
assert.include results.summary, '3 passing' |