2017-03-14 11:44:52 +08:00
|
|
|
import User from "discourse/models/user";
|
|
|
|
import Group from "discourse/models/group";
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.module("model:user");
|
2013-07-27 05:09:54 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("staff", assert => {
|
2017-03-14 11:44:52 +08:00
|
|
|
var user = User.create({ id: 1, username: "eviltrout" });
|
2013-07-27 05:09:54 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.ok(!user.get("staff"), "user is not staff");
|
2013-07-27 05:09:54 +08:00
|
|
|
|
|
|
|
user.toggleProperty("moderator");
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.ok(user.get("staff"), "moderators are staff");
|
2013-07-27 05:09:54 +08:00
|
|
|
|
|
|
|
user.setProperties({ moderator: false, admin: true });
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.ok(user.get("staff"), "admins are staff");
|
2013-07-27 05:09:54 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("searchContext", assert => {
|
2017-03-14 11:44:52 +08:00
|
|
|
var user = User.create({ id: 1, username: "EvilTrout" });
|
2013-07-27 05:09:54 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.deepEqual(
|
|
|
|
user.get("searchContext"),
|
|
|
|
{ type: "user", id: "eviltrout", user: user },
|
|
|
|
"has a search context"
|
|
|
|
);
|
2013-09-07 16:49:11 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("isAllowedToUploadAFile", assert => {
|
2017-03-14 11:44:52 +08:00
|
|
|
var user = User.create({ trust_level: 0, admin: true });
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.ok(
|
|
|
|
user.isAllowedToUploadAFile("image"),
|
|
|
|
"admin can always upload a file"
|
|
|
|
);
|
2013-09-07 16:49:11 +08:00
|
|
|
|
|
|
|
user.setProperties({ admin: false, moderator: true });
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.ok(
|
|
|
|
user.isAllowedToUploadAFile("image"),
|
|
|
|
"moderator can always upload a file"
|
|
|
|
);
|
2013-09-07 16:49:11 +08:00
|
|
|
});
|
2017-03-14 11:44:52 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("canMangeGroup", assert => {
|
2017-03-14 11:44:52 +08:00
|
|
|
let user = User.create({ admin: true });
|
|
|
|
let group = Group.create({ automatic: true });
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(
|
|
|
|
user.canManageGroup(group),
|
|
|
|
false,
|
|
|
|
"automatic groups cannot be managed."
|
|
|
|
);
|
2017-03-14 11:44:52 +08:00
|
|
|
|
|
|
|
group.set("automatic", false);
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(
|
|
|
|
user.canManageGroup(group),
|
|
|
|
true,
|
|
|
|
"an admin should be able to manage the group"
|
|
|
|
);
|
2017-03-14 11:44:52 +08:00
|
|
|
|
|
|
|
user.set("admin", false);
|
|
|
|
group.setProperties({ is_group_owner: true });
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(
|
|
|
|
user.canManageGroup(group),
|
|
|
|
true,
|
|
|
|
"a group owner should be able to manage the group"
|
|
|
|
);
|
|
|
|
});
|