-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathadmin.js
More file actions
88 lines (82 loc) · 2.56 KB
/
admin.js
File metadata and controls
88 lines (82 loc) · 2.56 KB
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
var sinon = require('sinon');
var assert = require('chai').assert;
var rewire = require('rewire');
describe('Admin Module:', function() {
var admin;
var clients;
var options;
var adminModule;
before(function() {
options = {
MATH_PROGRAM: "MyProgram"
};
adminModule = rewire('../lib/admin.js');
});
beforeEach(function() {
clients = {
totalUsers: 17,
user16: {},
user12: {}
};
admin = adminModule(clients, options);
});
describe('Admin.stats()', function() {
it('should get the stats', function(done) {
var spy;
var response = {
writeHead: function(statusCode, headers) {
assert.equal(statusCode, 200);
assert.deepEqual(headers, {"Content-Type": "text/html"});
},
write: function() {
},
end: function() {
var arg = '<head>\n <link rel="stylesheet" ' +
'href="mathProgram.css" type="text/css"\n ' +
'media="screen">\n</head>\n<h1>\n MyProgram User ' +
'Statistics\n</h1>\nThere are currently 2 users using ' +
'MyProgram.\n<br>\nIn total, there were 17 new users ' +
'since\n the server started.\n<br>\nEnjoy MyProgram!';
assert.equal(spy.firstCall.args[0], arg);
done();
}
};
spy = sinon.spy(response, "write");
admin.stats(null, response);
});
});
describe('Number of current users', function() {
it('should be correct', function() {
var currentUsers = adminModule.__get__("currentUsers");
assert.equal(currentUsers(clients), 2);
});
});
describe('Number of total users', function() {
it('should be correct', function() {
var totalUsers = adminModule.__get__("totalUsers");
assert.equal(totalUsers(clients), 17);
});
});
describe('Adding new users', function() {
it('should change the stats', function() {
var newUserId = 'user100';
clients[newUserId] = {};
var currentUsers = adminModule.__get__("currentUsers");
assert.equal(currentUsers(clients), 3);
});
});
describe('Deleting users', function() {
it('should change the stats', function() {
delete clients.user12;
var currentUsers = adminModule.__get__("currentUsers");
assert.equal(currentUsers(clients), 1);
});
});
describe('Deleting users', function() {
it('should not change total users', function() {
delete clients.user12;
var totalUsers = adminModule.__get__("totalUsers");
assert.equal(totalUsers(clients), 17);
});
});
});