mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2024-11-22 12:41:11 +00:00
180 lines
4 KiB
JavaScript
180 lines
4 KiB
JavaScript
"use strict";
|
|
|
|
var helper = require("./helpers/index.js");
|
|
var User = helper.User;
|
|
var assert = require("chai").assert;
|
|
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)",
|
|
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());
|
|
});
|
|
});
|
|
|
|
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());
|
|
});
|
|
it ("returns false if moderator", () => {
|
|
user.admin = false;
|
|
user.moderator = true;
|
|
assert.isFalse(user.isUserAdmin());
|
|
});
|
|
it ("returns true if neither admin nor moderator", () => {
|
|
user.admin = false;
|
|
user.moderator = false;
|
|
assert.isFalse(user.isUserAdmin());
|
|
});
|
|
});
|
|
});
|
|
|
|
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",
|
|
skill: "Bar",
|
|
gatherMusic: "Baz"
|
|
};
|
|
user.updateProfile(attrs, (error, profile) => {
|
|
if (error) return done(error);
|
|
assert.equal(profile.enslo, attrs.enslo);
|
|
assert.equal(profile.division, attrs.division);
|
|
assert.equal(profile.skill, attrs.skill);
|
|
assert.equal(profile.gatherMusic, attrs.gatherMusic);
|
|
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();
|
|
});
|
|
});
|
|
});
|
|
});
|