This repository was archived by the owner on Nov 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathtest.admin-users.selenium.js
178 lines (167 loc) · 6.74 KB
/
test.admin-users.selenium.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
var expect = require('expect.js'),
common = require('./common');
describe("ADMIN USERS SELENIUM", function() {
var browser = null;
if (process.env.SKIP_SELENIUM_TESTS) {
return;
}
this.timeout(60000); // Extra long timeout for selenium :(
before(function(done) {
this.timeout(240000);
common.getSeleniumBrowser(function (theBrowser) {
browser = theBrowser;
common.standardSetup(done);
});
});
after(function(done) {
browser.quit().then(function() {
common.standardShutdown(done);
});
});
it("Can't access user page unauthenticated", function(done) {
browser.get(common.URL + "/admin/users/");
browser.getCurrentUrl().then(function(url) {
expect(url).to.not.eql(common.URL + "/admin/users/");
done();
});
});
it("Can't access user page as non-superuser", function(done) {
browser.mockAuthenticate("admin1");
browser.get(common.URL + "/admin/users/")
browser.getPageSource().then(function(source) {
expect(source.indexOf("Permission denied")).to.not.eql(-1);
done();
});
});
it("Shows admin link for admins", function(done) {
browser.mockAuthenticate("admin1");
browser.get(common.URL);
browser.waitForSelector("#user-menu-label");
browser.byCss("#user-menu-label").click();
browser.waitForSelector("[href='/logout']")
browser.byCss("[href='/myevents/']").click();
browser.getCurrentUrl().then(function(url) {
expect(url).to.eql(common.URL + "/myevents/");
done();
});
});
it("Shows admin link for superusers", function(done) {
browser.mockAuthenticate("superuser1");
browser.get(common.URL);
browser.waitForSelector("#user-menu-label");
browser.byCss("#user-menu-label").click();
browser.waitForSelector("[href='/logout']")
browser.byCss("[href='/myevents/']").click();
browser.getCurrentUrl().then(function(url) {
expect(url).to.eql(common.URL + "/myevents/");
done();
});
});
it("Manages superusers", function(done) {
var user = common.server.db.users.findWhere({superuser: false});
browser.mockAuthenticate("superuser1");
browser.get(common.URL + "/admin/users/")
browser.getCurrentUrl().then(function(url) {
expect(url).to.eql(common.URL + "/admin/users/");
});
var selector = "tr[data-user-id='" + user.id + "'] input[type='checkbox']";
browser.waitForSelector(selector);
browser.byCss(selector).click().then(function() {
browser.wait(function() {
return user.isSuperuser() === true;
});
});
browser.byCss(selector).click().then(function() {
browser.wait(function() {
return user.isSuperuser() === false;
});
});
browser.then(function() {
done();
});
});
it("Manages admins", function(done) {
var user = common.server.db.users.findWhere({"sock-key": 'regular1'});
var event = common.server.db.events.findWhere({shortName: "writers-at-work"});
var eventUrl = common.URL + "/admin/event/" + event.id;
var addSelector = "tr[data-user-id='" + user.id + "'] .add-event";
var removeSelector = "[data-event-id='" + event.id + "'][data-user-id='" + user.id + "'].remove-event";
browser.mockAuthenticate("superuser1");
browser.get(common.URL + "/admin/users/")
browser.getCurrentUrl().then(function(url) {
expect(url).to.eql(common.URL + "/admin/users/");
});
// Pull up the add event modal, and add an event.
browser.waitForSelector(addSelector);
browser.byCss(addSelector).click();
// Wait for modal to fade in...
browser.waitForSelector(".modal-body select");
browser.selectOption(".modal-body select", event.get("title"));
browser.byCss(".add").click();
browser.wait(function() {
return user.isAdminOf(event) === true;
});
// Ensure the new admin can access the admin page.
browser.mockAuthenticate(user.get("sock-key"));
browser.get(eventUrl);
browser.getCurrentUrl().then(function(url) {
expect(url).to.eql(eventUrl);
});
// Remove admin-ship for this event.
browser.mockAuthenticate("superuser1");
browser.get(common.URL + "/admin/users/");
browser.waitForSelector(removeSelector);
browser.byCss(removeSelector).click().then(function() {
return common.await(function() {
expect(user.isAdminOf(event)).to.be(false);
});
});
// Ensure the new admin can no longer access the admin page.
browser.mockAuthenticate(user.get("sock-key"));
browser.get(eventUrl);
browser.getCurrentUrl().then(function(url) {
expect(url).to.eql(common.URL + "/");
done();
});
});
it("Manages perms", function(done) {
var user = common.server.db.users.findWhere({"sock-key": 'regular1'});
var permSelector = "tr[data-user-id='" + user.id + "']" +
" input.perm[data-perm='createEvents']";
expect(user.hasPerm("createEvents")).to.be(false);
browser.mockAuthenticate("superuser1");
browser.get(common.URL + "/admin/users/");
browser.waitForSelector(permSelector);
browser.byCss(permSelector).click();
browser.wait(function() {
if (user.hasPerm("createEvents") === true) {
return true;
}
});
browser.get(common.URL + "/admin/users/");
browser.waitForScript("$");
browser.executeScript('return $("'+permSelector+'").is(":checked");').then(function(checked) {
expect(checked).to.be(true);
});
browser.byCss(permSelector).click();
browser.wait(function() {
return user.hasPerm("createEvents") === false;
});
browser.get(common.URL + "/admin/users/");
browser.waitForScript("$");
browser.executeScript('return $("'+permSelector+'").is(":checked");').then(function(checked) {
expect(checked).to.be(false);
done();
});
});
it("Filters users", function(done) {
browser.mockAuthenticate("superuser1");
browser.get(common.URL + "/admin/users/");
browser.waitForSelector("input.filter-name");
browser.byCss("input.filter-name").sendKeys("Regular");
browser.byCsss("tr").then(function(els) {
expect(els.length).to.be(3);
done();
});
});
});