forked from mikeal/bent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* set name property to StatusError - mikeal#105 * pass on the actual statusMessage from the response instead of 'Incorrect statusCode ...' - mikeal#106
- Loading branch information
1 parent
d238da9
commit 14d306c
Showing
3 changed files
with
83 additions
and
36 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 |
---|---|---|
|
@@ -105,20 +105,37 @@ test('base PUT string', async () => { | |
} | ||
}) | ||
|
||
test('status 201', async () => { | ||
const request = bent('string', 201) | ||
const str = await request(u('/echo.js?statusCode=201&body=ok')) | ||
same(str, 'ok') | ||
|
||
try { | ||
await request(u('/echo.js?body=ok')) | ||
throw new Error('Call should have thrown.') | ||
} catch (e) { | ||
same(e.message, 'Incorrect statusCode: 200') | ||
// basic header test | ||
same(e.headers['content-length'], '2') | ||
} | ||
}) | ||
if (process.browser) { | ||
test('status 201', async () => { | ||
const request = bent('string', 201) | ||
const str = await request(u('/echo.js?statusCode=201&body=ok')) | ||
same(str, 'ok') | ||
|
||
try { | ||
await request(u('/echo.js?body=ok')) | ||
throw new Error('Call should have thrown.') | ||
} catch (e) { | ||
same(e.message, null) | ||
// basic header test | ||
same(e.headers['content-length'], '2') | ||
} | ||
}) | ||
} else { | ||
test('status 201', async () => { | ||
const request = bent('string', 201) | ||
const str = await request(u('/echo.js?statusCode=201&body=ok')) | ||
same(str, 'ok') | ||
|
||
try { | ||
await request(u('/echo.js?body=ok')) | ||
throw new Error('Call should have thrown.') | ||
} catch (e) { | ||
same(e.message, 'OK') | ||
// basic header test | ||
same(e.headers['content-length'], '2') | ||
} | ||
}) | ||
} | ||
|
||
test('PUT stream', async () => { | ||
const body = Buffer.from(Math.random().toString()) | ||
|
@@ -146,27 +163,55 @@ test('PUT JSON', async () => { | |
same(info.headers['content-type'], 'application/json') | ||
}) | ||
|
||
test('500 Response body', async () => { | ||
const request = bent() | ||
let body | ||
let _e | ||
try { | ||
await request(u('/echo.js?statusCode=500&body=ok')) | ||
} catch (e) { | ||
_e = e | ||
body = e.responseBody | ||
} | ||
const validate = buffer => { | ||
if (process.browser) { | ||
same(decode(buffer), 'ok') | ||
} else { | ||
same(buffer.toString(), 'ok') | ||
if (process.browser) { | ||
test('500 Response body and message', async () => { | ||
const request = bent() | ||
let body | ||
let _e | ||
try { | ||
await request(u('/echo.js?statusCode=500&body=ok')) | ||
} catch (e) { | ||
_e = e | ||
body = e.responseBody | ||
} | ||
} | ||
validate(await body) | ||
// should be able to access again | ||
validate(await _e.responseBody) | ||
}) | ||
const validate = buffer => { | ||
if (process.browser) { | ||
same(decode(buffer), 'ok') | ||
} else { | ||
same(buffer.toString(), 'ok') | ||
} | ||
} | ||
validate(await body) | ||
// should be able to access again | ||
validate(await _e.responseBody) | ||
|
||
same(_e.message, null) | ||
}) | ||
} else { | ||
test('500 Response body and message', async () => { | ||
const request = bent() | ||
let body | ||
let _e | ||
try { | ||
await request(u('/echo.js?statusCode=500&body=ok')) | ||
} catch (e) { | ||
_e = e | ||
body = e.responseBody | ||
} | ||
const validate = buffer => { | ||
if (process.browser) { | ||
same(decode(buffer), 'ok') | ||
} else { | ||
same(buffer.toString(), 'ok') | ||
} | ||
} | ||
validate(await body) | ||
// should be able to access again | ||
validate(await _e.responseBody) | ||
|
||
same(_e.message, 'Internal Server Error') | ||
}) | ||
} | ||
|
||
test('auth', async () => { | ||
const request = bent('https://test:[email protected]/basic-auth/test/pass', 'json') | ||
|