Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Neculau committed Jul 1, 2013
1 parent d18578c commit 98c7f94
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/_utils.coffee
38 changes: 38 additions & 0 deletions test/format.coffee
@@ -0,0 +1,38 @@
{
should
} = require './_utils'
format = require('../').format

describe 'format', () ->


describe '.normalizeHeaders', () ->
it 'should lowercase headers', () ->
reqres = {headers: {'Accept': '', 'Content-TyPe': ''}}
format.normalizeHeaders(reqres).should.eql
'accept': ''
'content-type': ''


describe '.headers', () ->
it 'should camelize headers', () ->
reqres = {headers: {'accept': '', 'content-TyPe': ''}}
format.headers(reqres).should.eql
'Accept': ''
'Content-Type': ''

it 'should sort headers', () ->
reqres = {headers: {'Content-Type': '', 'Accept': ''}}
format.headers(reqres).should.eql
'Accept': ''
'Content-Type': ''


describe '.json', () ->
it 'should ignore non-JSON Content-Types', () ->
reqres = {headers: {'content-type':'application/xml'}, body:''}
format.json(reqres, null, null, []).should.eql ''

it 'should return no error on valid JSON', () ->
reqres = {headers:{'content-type':'application/json'}, body:'{}'}
format.json(reqres, null, null, []).should.eql '{}'
22 changes: 22 additions & 0 deletions test/lint.coffee
@@ -0,0 +1,22 @@
{
should
} = require './_utils'
lint = require('../').lint

describe 'lint', () ->
it 'should return one error of type invalid_blueprint', () ->
lint('')[0].type.should.eql 'invalid_blueprint'


describe 'json', () ->
it 'should return one error of type invalid_json', () ->
reqres = {headers:{'content-type':'application/json'}, body:''}
lint.json(reqres, null, null, [])[0].type.should.eql 'invalid_json'

it 'should ignore non-JSON Content-Types', () ->
reqres = {headers:{'content-type':'application/xml'}, body:''}
lint.json(reqres, null, null, []).should.eql []

it 'should return no error on valid JSON', () ->
reqres = {headers:{'content-type':'application/json'}, body:'{}'}
lint.json(reqres, null, null, []).should.eql []
1 change: 1 addition & 0 deletions test/mocha.opts

0 comments on commit 98c7f94

Please sign in to comment.