UNPKG

1.69 kBtext/coffeescriptView Raw
1client = require('./client')
2server = require('connect').createServer()
3assert = require('assert')
4
5###
6Each of these routes that will be added to the test server, with a handler that
7returns the matched vars.
8
9Then each path below the route is requested and the client asserts that what was
10matched what we expected.
11###
12testRoutes =
13 '/simple/{param}': {
14 '/simple/blah': {param: 'blah'}
15 }
16 '/simpleList/{things*}': {
17 '/simpleList/one,two,three': {things: ['one', 'two', 'three']}
18 '/simpleList/just-one': {things: ['just-one']}
19 }
20 "/path{/scope,action,id}": {
21 '/path/cats/manage/petra': {scope: 'cats', action: 'manage', id: 'petra'}
22 }
23 "/suffixed/{param}.suffix": {
24 '/suffixed/value.suffix': {param: 'value'}
25 }
26 "/qsExplode{?params*}": {
27 '/qsExplode?a=ok&b=neat': {params: {a: 'ok', b: 'neat'}}
28 '/qsExplode?a=ok&b=neat&c': {params: {a: 'ok', b: 'neat', c: true}}
29 }
30 "/qs{?param}": {
31 '/qs?param=blarg': {param: 'blarg'}
32 '/qs?param=one,two,three': {param: 'one,two,three'}
33 }
34
35# The handler to be used by all routes above
36echo = -> @ok @req.vars
37
38server.use require('../lib/lazorse').app ->
39 routes = {}
40 routes[tpl] = {GET: echo} for tpl of testRoutes
41 @route routes
42
43describe "With URL parameters", ->
44 before (start) ->
45 server.listen 0, 'localhost', ->
46 client.usePort server.address().port
47 start()
48
49 after -> server.close()
50
51 for _, exp of testRoutes
52 do (exp) ->
53 for path, vars of exp
54 do (path, vars) ->
55 it "GET #{path}", (done) ->
56 client.GET path, (res, data) ->
57 assert.equal res.statusCode, 200
58 assert.deepEqual vars, data
59 done()