-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
77 lines (75 loc) · 2 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var test = require("tape");
var Chats = require("./");
test("chats", function (t) {
var chats = null;
t.test("init", function (t) {
chats = Chats();
t.ok(chats);
t.end();
});
t.test("speak", function (t) {
chats
.speak("hello", "user")
.then(function (result) {
t.ok(result);
t.end();
})
.catch(t.end);
});
t.test("speak a lot", function (t) {
var times = 1000;
function speak(count) {
if (count >= times) return t.end();
chats
.speak("test" + count, "user" + count)
.then(function (result) {
t.ok(result.chat.length <= 100);
speak(count + 1);
})
.catch(t.end);
}
speak(0);
});
t.test("create room", function (t) {
chats
.createRoom("tests")
.then(function (result) {
t.ok(result);
t.end();
})
.catch(t.end);
});
t.test("list rooms", function (t) {
chats
.listRooms()
.then(function (result) {
t.equal(result.length, 2);
t.end();
})
.catch(t.end);
});
t.test("get room", function (t) {
chats
.getRoom("tests")
.then(function (result) {
t.ok(result);
t.end();
})
.catch(t.end);
});
t.test("remove message", function (t) {
var length = 0;
chats
.getRoom()
.then(function (result) {
length = result.chat.length;
var message = result.chat[10];
return chats.removeMessage(message.id);
})
.then(function (result) {
t.equal(length - 1, result.chat.length);
t.end();
})
.catch(t.end);
});
});