This repository has been archived by the owner on Jun 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
53 additions
and
5 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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
http = require 'http' | ||
https = require 'https' | ||
|
||
class RequestProcessor | ||
constructor: (@request) -> | ||
|
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,11 @@ | ||
http = require 'http' | ||
|
||
statusCodes = {} | ||
statusCodes[http.STATUS_CODES[code].toLowerCase()] = code for code in Object.keys(http.STATUS_CODES) | ||
|
||
translate = (statusCode) -> | ||
key = statusCode.toLowerCase() | ||
return parseInt statusCodes[key] if statusCodes[key]? | ||
return statusCode | ||
|
||
module.exports = translate |
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,36 @@ | ||
require 'coffee-errors' | ||
{assert} = require 'chai' | ||
|
||
translate = require '../../src/status-code-translator' | ||
|
||
describe 'status code translation', () -> | ||
describe 'translate ok', () -> | ||
it 'should return 200', () -> | ||
assert.strictEqual translate('ok'), 200 | ||
|
||
it 'should be case insensitive', () -> | ||
assert.strictEqual translate('OK'), 200 | ||
|
||
describe 'translate not found', () -> | ||
it 'should return 404', () -> | ||
assert.strictEqual translate('not found'), 404 | ||
|
||
it 'should be case insensitive', () -> | ||
assert.strictEqual translate('Not Found'), 404 | ||
|
||
describe 'translate internal server error', () -> | ||
it 'should return 500', () -> | ||
assert.strictEqual translate('internal server error'), 500 | ||
|
||
it 'should be case insensitive', () -> | ||
assert.strictEqual translate('Internal Server Error'), 500 | ||
|
||
describe 'translate other', () -> | ||
it 'should return given code', () -> | ||
assert.strictEqual translate('unknown code'), 'unknown code' | ||
|
||
it 'should not change letter case', () -> | ||
assert.strictEqual translate('Unknown Code'), 'Unknown Code' | ||
|
||
it 'should return every unknown type', () -> | ||
assert.strictEqual translate('quick brown fox jumps over lazy dog'), 'quick brown fox jumps over lazy dog' |