-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
108 lines (95 loc) · 2.77 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
var Lab = require('lab');
var server = require("./chat");
Lab.test('Obtaining a valid token', function (done) {
var options = {
method: "POST",
url: "/connect",
payload: {
username: "Test User",
room: "TestRoom"
}
};
server.inject(options, function(response) {
var result = response.result,
payload = options.payload;
Lab.expect(response.statusCode).to.equal(200);
Lab.expect(result).to.have.length.above(0);
done();
});
});
Lab.test('Calling typing without an invalid token should return a propper response', function (done) {
var options = {
method: "POST",
url: "/typing",
payload: {
token: "SomeInvalidToken",
}
};
server.inject(options, function(response) {
Lab.expect(response.result.message).to.equal("Your token is invalid");
done();
});
});
Lab.test('Calling typing with an valid token should return a propper response', function (done) {
var requestTokenOptions = {
method: "POST",
url: "/connect",
payload: {
username: "Test User",
room: "Test Room"
}
};
server.inject(requestTokenOptions, function(response) {
var token = response.result;
var options = {
method: "POST",
url: "/typing",
payload: {
token: token,
}
};
server.inject(options, function(response) {
Lab.expect(response.result.message).to.equal("OK");
done();
});
});
});
Lab.test('Calling message without an invalid token should return a propper response', function (done) {
var options = {
method: "POST",
url: "/message",
payload: {
token: "SomeInvalidToken",
message: "Some Message"
}
};
server.inject(options, function(response) {
Lab.expect(response.result.message).to.equal("Your token is invalid");
done();
});
});
Lab.test('Calling message with an valid token should return a propper response', function (done) {
var requestTokenOptions = {
method: "POST",
url: "/connect",
payload: {
username: "Test User",
room: "Test Room"
}
};
server.inject(requestTokenOptions, function(response) {
var token = response.result;
var options = {
method: "POST",
url: "/message",
payload: {
token: token,
message: "Some Message"
}
};
server.inject(options, function(response) {
Lab.expect(response.result.message).to.equal("OK");
done();
});
});
});