-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ls
87 lines (75 loc) · 2.1 KB
/
test.ls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
require! {
'expect.js'
'./index.js': body
highland: σ
}
Stream = σ!constructor # sigh
err = (e)-> σ (<| e)
export
"Body parser":
"returns a stream": ->
expect (body.raw σ ["hello"]) .to.be.a Stream
"resolves to the body": (done)->
body.raw σ ["hello"]
.to-array (xs)->
expect xs .to.eql <[hello]>
done!
"resolves to the parsed body": (done)->
body.json σ [JSON.stringify a:1]
.to-array (xs)->
expect xs.0 .to.have.property \a 1
done!
"passes stream errors to the stream": (done)->
body.json err new Error "hello"
.stop-on-error (err)->
expect err.message .to.be "hello"
done!
.each ->
"passes parse errors to the stream": (done)->
(body.json σ ["not json"])
.stop-on-error (err)->
expect err .to.be.a SyntaxError
done!
.each ->
"json parser":
"streams parsed json": (done)->
body.json-parse '{"a":1}' .to-array (xs)->
expect xs.0 .to.have.property \a 1
done!
"passes parse errors to the stream": (done)->
body.json-parse 'not json'
.stop-on-error (err)->
expect err .to.be.a SyntaxError
done!
.each ->
"query parser":
"streams parsed query strings": (done)->
body.query-parse 'a=1' .to-array (xs)->
expect xs.0 .to.have.property \a '1'
done!
"auto":
"parses json for application/json": (done)->
req = σ [JSON.stringify a:1]
req.headers = 'content-type': \application/json
body.auto req .to-array (xs)->
expect xs.0 .to.have.property \a 1
done!
"parses querystring for application/x-www-form-urlencoded": (done)->
req = σ ['a=1']
req.headers = 'content-type': \application/x-www-form-urlencoded
body.auto req .to-array (xs)->
expect xs.0 .to.have.property \a '1'
done!
"parses raw for other content types": (done)->
req = σ ['hello']
req.headers = 'content-type': \text/plain
body.auto req .to-array (xs)->
expect xs.0 .to.be 'hello'
done!
"calls setEncoding if it's there": (done)->
req = σ ['hello']
req.headers = 'content-type': \application/json
req.set-encoding = ->
expect it .to.be \utf8
done!
body.auto req .resume!