2013-07-26 17:09:54 -04:00
|
|
|
module("Discourse.User");
|
|
|
|
|
|
|
|
test('staff', function(){
|
|
|
|
var user = Discourse.User.create({id: 1, username: 'eviltrout'});
|
|
|
|
|
|
|
|
ok(!user.get('staff'), "user is not staff");
|
|
|
|
|
|
|
|
user.toggleProperty('moderator');
|
|
|
|
ok(user.get('staff'), "moderators are staff");
|
|
|
|
|
|
|
|
user.setProperties({moderator: false, admin: true});
|
|
|
|
ok(user.get('staff'), "admins are staff");
|
|
|
|
});
|
|
|
|
|
|
|
|
test('searchContext', function() {
|
|
|
|
var user = Discourse.User.create({id: 1, username: 'EvilTrout'});
|
|
|
|
|
|
|
|
deepEqual(user.get('searchContext'), {type: 'user', id: 'eviltrout', user: user}, "has a search context");
|
2013-09-07 04:49:11 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test("isAllowedToUploadAFile", function() {
|
|
|
|
var user = Discourse.User.create({ trust_level: 0, admin: true });
|
|
|
|
ok(user.isAllowedToUploadAFile("image"), "admin can always upload a file");
|
|
|
|
|
|
|
|
user.setProperties({ admin: false, moderator: true });
|
|
|
|
ok(user.isAllowedToUploadAFile("image"), "moderator can always upload a file");
|
|
|
|
});
|
2013-10-03 12:51:30 -04:00
|
|
|
|
2014-03-07 12:58:53 -05:00
|
|
|
test("homepage", function() {
|
|
|
|
var user = Discourse.User.create({ should_be_redirected_to_top: false });
|
|
|
|
var defaultHomepage = Discourse.Utilities.defaultHomepage();
|
2013-12-30 12:46:18 -05:00
|
|
|
|
2014-03-07 12:58:53 -05:00
|
|
|
equal(user.get("homepage"), defaultHomepage, "user's homepage is default when not redirected");
|
2013-12-30 12:46:18 -05:00
|
|
|
|
2014-03-07 12:58:53 -05:00
|
|
|
user.set("should_be_redirected_to_top", true);
|
2013-12-30 13:42:45 -05:00
|
|
|
|
2014-03-07 12:58:53 -05:00
|
|
|
equal(user.get("homepage"), "top", "user's homepage is top when redirected");
|
2013-12-30 12:46:18 -05:00
|
|
|
});
|
|
|
|
|
2013-10-03 12:51:30 -04:00
|
|
|
asyncTestDiscourse("findByUsername", function() {
|
|
|
|
expect(3);
|
|
|
|
|
|
|
|
Discourse.User.findByUsername('eviltrout').then(function (user) {
|
|
|
|
present(user);
|
|
|
|
equal(user.get('username'), 'eviltrout', 'it has the correct username');
|
|
|
|
equal(user.get('name'), 'Robin Ward', 'it has the full name since it has details');
|
|
|
|
start();
|
|
|
|
});
|
2013-12-30 12:46:18 -05:00
|
|
|
});
|