ensl_gathers/spec/user.js

181 lines
4 KiB
JavaScript
Raw Normal View History

"use strict";
var helper = require("./helpers/index.js");
var User = helper.User;
var assert = require("chai").assert;
2015-09-17 19:59:05 +00:00
var Profile = helper.Profile;
var async = require("async");
var userCount = 0;
describe("User", () => {
var user, userAttributes;
before(() => {
userCount++;
userAttributes = {
id: userCount,
username: "FearLess90",
country: "CA",
time_zone: "Eastern Time (US & Canada)",
2016-01-22 10:12:23 +00:00
avatar: "/icons/" + userCount + ".png",
admin: false,
steam: {
url: "http://steamcommunity.com/profiles/76561198076460617",
nickname: "FearLess90"
},
bans: {
gather: false,
mute: false,
site: false
},
team: {
id: 622,
name: "National Gamers"
}
}
});
describe("#getSteamId", () => {
beforeEach(() => {
user = new User(userAttributes);
});
it ("returns steamid", () => {
assert.equal(user.getSteamId(), "STEAM_0:1:58097444");
});
it ("returns null if no steamid", () => {
user.steam.url = null;
assert.isNull(user.getSteamId());
});
});
2015-09-17 19:59:05 +00:00
2015-10-20 22:40:40 +00:00
describe("Abilities", () => {
describe("isChatAdmin", () => {
it ("returns true if admin", () => {
user.admin = true;
user.moderator = false;
assert.isTrue(user.isChatAdmin());
});
it ("returns true if moderator", () => {
user.admin = false;
user.moderator = true;
assert.isTrue(user.isChatAdmin());
});
it ("returns true if neither admin nor moderator", () => {
user.admin = false;
user.moderator = false;
assert.isFalse(user.isChatAdmin());
});
});
describe("isGatherAdmin", () => {
it ("returns true if admin", () => {
user.admin = true;
user.moderator = false;
assert.isTrue(user.isGatherAdmin());
});
it ("returns true if moderator", () => {
user.admin = false;
user.moderator = true;
assert.isTrue(user.isGatherAdmin());
});
it ("returns true if neither admin nor moderator", () => {
user.admin = false;
user.moderator = false;
assert.isFalse(user.isGatherAdmin());
});
});
describe("isUserAdmin", () => {
it ("returns true if admin", () => {
user.admin = true;
user.moderator = false;
assert.isTrue(user.isUserAdmin());
});
2015-10-22 13:42:33 +00:00
it ("returns false if moderator", () => {
2015-10-20 22:40:40 +00:00
user.admin = false;
user.moderator = true;
assert.isFalse(user.isUserAdmin());
2015-10-20 22:40:40 +00:00
});
it ("returns true if neither admin nor moderator", () => {
user.admin = false;
user.moderator = false;
assert.isFalse(user.isUserAdmin());
});
});
});
2015-09-17 19:59:05 +00:00
describe("#updateProfile", () => {
var profile, user;
beforeEach(done => {
user = helper.createUser();
Profile.create({
userId: user.id
}, (error, result) => {
if (error) return done(error);
profile = result;
done();
});
});
after(done => helper.clearDb(done));
it ("updates profile", done => {
var attrs = {
enslo: 88,
division: "Foo",
2015-09-18 11:53:01 +00:00
skill: "Bar",
gatherMusic: "Baz"
2015-09-17 19:59:05 +00:00
};
user.updateProfile(attrs, (error, profile) => {
if (error) return done(error);
assert.equal(profile.enslo, attrs.enslo);
assert.equal(profile.division, attrs.division);
2015-09-18 11:53:01 +00:00
assert.equal(profile.skill, attrs.skill);
assert.equal(profile.gatherMusic, attrs.gatherMusic);
2015-09-17 19:59:05 +00:00
done();
});
});
it ("updates abilities", done => {
var attrs = {
abilities: {
"skulk": true,
"lerk": true,
"fade": true,
"gorge": true,
"onos": true,
"commander": true
}
};
user.updateProfile(attrs, (error, profile) => {
if (error) return done(error);
for (let attr in attrs.abilities) {
assert.isTrue(profile.abilities[attr])
}
done();
});
});
it ("does not update userId", done => {
user.updateProfile({
userId: 80808080
}, (error, result) => {
if (error) return done(error);
assert.equal(result.userId, user.id);
done();
});
});
it ("does not update _id", done => {
user.updateProfile({
_id: "FOOOO"
}, (error, result) => {
if (error) return done(error);
assert.equal(result._id.toString(), profile._id.toString());
done();
});
});
});
2015-09-04 13:49:49 +00:00
});