1 | client = require('./client')
|
2 | server = require('connect').createServer()
|
3 | assert = require('assert')
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | testResources =
|
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 |
|
36 | echo = -> @ok @req.vars
|
37 |
|
38 | server.use require('../lib/lazorse').app ->
|
39 | resources = {}
|
40 | resources[tpl] = {GET: echo} for tpl of testResources
|
41 | @resource resources
|
42 |
|
43 | describe "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 testResources
|
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()
|