2017-12-04 02:50:26 +01:00
|
|
|
set_global('blueslip', {});
|
2017-12-19 20:39:56 +01:00
|
|
|
set_global('page_params', {});
|
2017-12-04 02:50:26 +01:00
|
|
|
|
2018-03-04 17:44:12 +01:00
|
|
|
zrequire('dict');
|
2017-12-04 02:50:26 +01:00
|
|
|
zrequire('user_groups');
|
|
|
|
|
|
|
|
(function test_user_groups() {
|
2017-12-19 20:39:56 +01:00
|
|
|
var students = {
|
|
|
|
name: 'Students',
|
|
|
|
id: 0,
|
2018-03-04 17:44:12 +01:00
|
|
|
members: [1, 2],
|
2017-12-19 20:39:56 +01:00
|
|
|
};
|
|
|
|
global.page_params.realm_user_groups = [students];
|
|
|
|
|
|
|
|
user_groups.initialize();
|
|
|
|
assert.equal(user_groups.get_user_group_from_id(students.id), students);
|
|
|
|
|
2017-12-04 02:50:26 +01:00
|
|
|
var admins = {
|
|
|
|
name: 'Admins',
|
|
|
|
id: 1,
|
2018-03-04 17:44:12 +01:00
|
|
|
members: [3],
|
2017-12-04 02:50:26 +01:00
|
|
|
};
|
|
|
|
var all = {
|
|
|
|
name: 'Everyone',
|
|
|
|
id: 2,
|
2018-03-04 17:44:12 +01:00
|
|
|
members: [1, 2, 3],
|
2017-12-04 02:50:26 +01:00
|
|
|
};
|
2017-12-19 20:39:56 +01:00
|
|
|
|
2017-12-04 02:50:26 +01:00
|
|
|
user_groups.add(admins);
|
|
|
|
assert.equal(user_groups.get_user_group_from_id(admins.id), admins);
|
2017-12-19 20:39:56 +01:00
|
|
|
|
2017-12-04 02:50:26 +01:00
|
|
|
var called = false;
|
|
|
|
global.blueslip.error = function (msg) {
|
|
|
|
assert.equal(msg, "Unknown group_id in get_user_group_from_id: " + all.id);
|
|
|
|
called = true;
|
|
|
|
};
|
2017-12-19 20:39:56 +01:00
|
|
|
|
2017-12-04 02:50:26 +01:00
|
|
|
assert.equal(user_groups.get_user_group_from_id(all.id), undefined);
|
|
|
|
assert(called);
|
|
|
|
|
2017-12-19 20:39:56 +01:00
|
|
|
user_groups.remove(students);
|
|
|
|
global.blueslip.error = function (msg) {
|
|
|
|
assert.equal(msg, "Unknown group_id in get_user_group_from_id: " + students.id);
|
|
|
|
};
|
|
|
|
assert.equal(user_groups.get_user_group_from_id(students.id), undefined);
|
|
|
|
}());
|