-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
58 lines (49 loc) · 1.26 KB
/
test.js
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
var pico = require('./pico.js')
var test = require('blue-tape')
pico.loadAsync('http://127.0.0.1:4242/api')
.then(function (api) {
test('hello test', function (t) {
return api.hello('world')
.then(function (value) {
t.isEqual(value, 'Hello world')
})
})
test('exception test', function (t) {
return t.shouldFail(api.fail())
})
test('stream test', function (t) {
var stream = api.countdown(3)
var i = 0
var results = ['2', '1', '0']
stream.each(function (message) {
t.isEqual(message, results[i])
i += 1
})
.then(function () {
t.end()
})
})
test('pico.importModule test', function (t) {
var m = pico.importModule('api')
t.isEqual(m, api)
return m.hello('Tester')
.then(function (value) {
t.isEqual(value, 'Hello Tester')
})
})
test('pico.setAuthentication test', function (t) {
api.current_user().then(function (value) {
t.notOk(value)
})
pico.setAuthentication(api, 'bob', 'wrongpassword')
t.shouldFail(api.current_user())
pico.clearAuthentication(api)
pico.setAuthentication(api, 'bob', 'secret')
api.current_user()
.then(function (value) {
t.isEqual(value, 'bob')
})
pico.clearAuthentication(api)
t.end()
})
})