Skip to content

Commit

Permalink
tests for @ALL (zappajs#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
Radagaisus committed Sep 15, 2012
1 parent 6cc775c commit 1a9f94d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 50 deletions.
28 changes: 28 additions & 0 deletions tests/middleware.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,31 @@ port = 15500
c = t.client(zapp.server)
c.get '/foo.txt', (err, res) ->
t.equal 'static', res.body, 'intercepted!'

all: (t) ->
t.expect '1', '2', '3', '4'
t.wait 4000

zapp = zappa port++, ->

@all '/*', ->
if @query.hello is 'hi' then @next()
else @next 'Where is your manners?'

@get '/bonjour', ->
@send 'bonjour'

@get '/hola', ->
@send 'hola!'

c = t.client(zapp.server)
c.get '/bonjour?hello=hi', (err, res) ->
t.equal '1', res.body, 'bonjour'
c.get '/bonjour', (err, res) ->
t.equal '2', res.body, 'Where is your manners?'
c.get '/hola?hello=hi', (err, res) ->
t.equal '3', res.body, 'hola!'
c.get '/hola?hello=boo', (err, res) ->
t.equal '4', res.body, 'Where is your manners?'


50 changes: 0 additions & 50 deletions tests/routes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -92,53 +92,3 @@ port = 15000
c.get '/send/bob', (err, res) -> t.equal 3, res.body, 'send'
c.get '/send/bar', (err, res) -> t.equal 3, res.body, 'Failed to load user bar'

# Test for express app.param
param: (t) ->
t.expect 1,2,3,4,5,6
t.wait 4000
zapp = zappa port++, ->

@param 'user_id', ->
if not @param.match /^[0-9A-F]{24,24}$/i
@response.send "Invalid User ID"
else @next()

@param
'user': ->
if not @param.match /^[0-9A-F]{24,24}$/i
@response.send "Invalid User ID"
else @next()
'camper': ->
if not @param.match /^[0-9A-F]{24,24}$/i
@response.send "Invalid User ID"
else @next()

@get '/:user_id', ->
@send @params.user_id

@get '/camper/:camper', ->
@send @params.camper

@get '/user/:user', ->
@send @params.user


c = t.client(zapp.server)
c.get '/no-such-user-id', (err, res) ->
t.equal 1, res.body, 'Invalid User ID'

c.get '/123456789012345678901234', (err, res) ->
t.equal 2, res.body, '123456789012345678901234'

c.get '/camper/no-such-user-id', (err, res) ->
t.equal 3, res.body, 'Invalid User ID'

c.get '/camper/123456789012345678901234', (err, res) ->
t.equal 4, res.body, '123456789012345678901234'

c.get '/user/no-such-user-id', (err, res) ->
t.equal 5, res.body, 'Invalid User ID'

c.get '/user/123456789012345678901234', (err, res) ->
t.equal 6, res.body, '123456789012345678901234'

0 comments on commit 1a9f94d

Please sign in to comment.