-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix reading of PUT / JSON POST requests - Catch & report errors for invalid POSTs - Make sure the internal request is always defined, so that we can use it in error reports - Add tests
- Loading branch information
Showing
3 changed files
with
72 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,41 @@ | ||
'use strict'; | ||
|
||
// mocha defines to avoid JSHint breakage | ||
/* global describe, it, before, beforeEach, after, afterEach */ | ||
|
||
var assert = require('../../utils/assert.js'); | ||
var preq = require('preq'); | ||
var server = require('../../utils/server.js'); | ||
|
||
describe('400 handling', function() { | ||
this.timeout(20000); | ||
|
||
before(function () { return server.start(); }); | ||
|
||
it('should return a proper 400 for an empty POST', function() { | ||
return preq.post({ | ||
uri: server.config.hostPort, | ||
headers: { | ||
'content-type': 'foo/bar' | ||
}, | ||
}) | ||
.catch(function(e) { | ||
assert.deepEqual(e.status, 400); | ||
assert.contentType(e, 'application/problem+json'); | ||
}); | ||
}); | ||
|
||
it('should return a proper 400 for an invalid POST', function() { | ||
return preq.post({ | ||
uri: server.config.hostPort, | ||
headers: { | ||
'content-type': 'foo/bar' | ||
}, | ||
body: 'baz' | ||
}) | ||
.catch(function(e) { | ||
assert.deepEqual(e.status, 400); | ||
assert.contentType(e, 'application/problem+json'); | ||
}); | ||
}); | ||
}); |