2015-07-20 09:41:58 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var fs = require("fs");
|
|
|
|
var path = require("path");
|
2015-07-23 13:36:51 +00:00
|
|
|
var extend = require("extend");
|
2015-07-20 09:41:58 +00:00
|
|
|
|
|
|
|
var helpers = {}
|
|
|
|
|
2015-07-22 23:31:48 +00:00
|
|
|
helpers.server = require(path.join(__dirname, "../../index.js"));
|
|
|
|
|
|
|
|
helpers.app = helpers.server.app;
|
2015-07-20 09:41:58 +00:00
|
|
|
|
2015-07-23 13:36:51 +00:00
|
|
|
// Models
|
|
|
|
var User = helpers.User = require(path.join(__dirname, "../../lib/user/user"));
|
|
|
|
var Gather = helpers.Gather = require(path.join(__dirname, "../../lib/gather/gather"));
|
|
|
|
var Gatherer = helpers.Gatherer = require(path.join(__dirname, "../../lib/gather/gatherer"));
|
|
|
|
|
2015-08-17 13:50:59 +00:00
|
|
|
// ENSL Client
|
|
|
|
var EnslClient = helpers.EnslClient = require(path.join(__dirname, "../../lib/ensl/client"));
|
2015-07-23 13:36:51 +00:00
|
|
|
|
2015-08-05 00:41:43 +00:00
|
|
|
// Mongo & Associated Models
|
|
|
|
var db = require(path.join(__dirname, "../../db/index"));
|
|
|
|
var mongoose = require("mongoose");
|
2015-08-18 09:56:35 +00:00
|
|
|
var Message = helpers.Message = mongoose.model("Message");
|
|
|
|
var Session = helpers.Session = mongoose.model("Session");
|
2015-08-05 00:41:43 +00:00
|
|
|
|
|
|
|
var async = require("async");
|
|
|
|
helpers.clearDb = function (callback) {
|
|
|
|
async.series([
|
|
|
|
function (cb) {
|
|
|
|
Message.remove({}, cb)
|
|
|
|
}
|
|
|
|
], callback);
|
|
|
|
}
|
|
|
|
|
2015-07-23 13:36:51 +00:00
|
|
|
// Create User Method
|
|
|
|
// Each user will have unique ID, username and steam attributes
|
|
|
|
var createUser = helpers.createUser = (function () {
|
|
|
|
var counter = 0;
|
|
|
|
return function (o) {
|
|
|
|
counter++
|
|
|
|
var defaultUser = {
|
|
|
|
id: counter,
|
|
|
|
username: "User" + counter,
|
|
|
|
country: "CA",
|
|
|
|
time_zone: "Eastern Time (US & Canada)",
|
|
|
|
avatar: "/images/icons/noavatar.png",
|
|
|
|
admin: false,
|
|
|
|
steam: {
|
|
|
|
url: "http://steamcommunity.com/profiles/7656119806792633" + counter,
|
|
|
|
nickname: "SteamUser" + counter
|
|
|
|
}
|
|
|
|
};
|
2015-08-18 09:56:35 +00:00
|
|
|
if (o && typeof o === "object") {
|
2015-07-23 13:36:51 +00:00
|
|
|
defaultUser = extend(defaultUser, o);
|
|
|
|
}
|
|
|
|
return new User(defaultUser);
|
|
|
|
}
|
|
|
|
})()
|
|
|
|
|
2015-07-24 13:34:02 +00:00
|
|
|
var random = helpers.random = function (n) {
|
|
|
|
return Math.floor(Math.random () * n);
|
|
|
|
}
|
|
|
|
|
2015-08-07 00:47:23 +00:00
|
|
|
helpers.createMessage = function (options, callback) {
|
|
|
|
var content = options.content || "Test content";
|
|
|
|
var user = options.user || createUser();
|
|
|
|
Message.create({
|
|
|
|
author: {
|
|
|
|
username: user.username,
|
|
|
|
avatar: user.avatar
|
|
|
|
},
|
|
|
|
content: content
|
|
|
|
}, callback);
|
|
|
|
};
|
|
|
|
|
2015-07-20 09:41:58 +00:00
|
|
|
module.exports = helpers;
|