mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2025-01-19 16:11:01 +00:00
Added basic archivedGather model
This commit is contained in:
parent
895aa826c1
commit
541facd1fd
4 changed files with 87 additions and 0 deletions
|
@ -10,5 +10,6 @@ mongoose.connect(config.mongo.uri);
|
|||
require(path.join(__dirname, "/models/message"));
|
||||
require(path.join(__dirname, "/models/session"));
|
||||
require(path.join(__dirname, "/models/profile"));
|
||||
require(path.join(__dirname, "/models/archivedGather"));
|
||||
|
||||
module.exports = mongoose;
|
17
db/models/archivedGather.js
Normal file
17
db/models/archivedGather.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
"use strict";
|
||||
|
||||
var mongoose = require("mongoose");
|
||||
var Schema = mongoose.Schema;
|
||||
|
||||
var archivedGatherSchema = new Schema({
|
||||
createdAt: { type: Date, default: Date.now },
|
||||
gather: { type: Schema.Types.Mixed, required: true }
|
||||
});
|
||||
|
||||
archivedGatherSchema.index({ createdAt: -1 });
|
||||
|
||||
archivedGatherSchema.static('recent', function (callback) {
|
||||
|
||||
});
|
||||
|
||||
module.exports = mongoose.model("ArchivedGather", archivedGatherSchema);
|
68
spec/archivedGather.js
Normal file
68
spec/archivedGather.js
Normal file
|
@ -0,0 +1,68 @@
|
|||
"use strict";
|
||||
|
||||
var helper = require("./helpers/index.js");
|
||||
var Gather = helper.Gather;
|
||||
var ArchivedGather = helper.ArchivedGather;
|
||||
var assert = require("chai").assert;
|
||||
var async = require("async");
|
||||
|
||||
var generateCompletedGather = () => {
|
||||
var user, gather, gatherers;
|
||||
user = helper.createUser();
|
||||
gatherers = [];
|
||||
for (var i = 0; i < 12; i++)
|
||||
gatherers.push(helper.createUser());
|
||||
gather = Gather();
|
||||
|
||||
// Add gatherers
|
||||
gatherers.forEach((gatherer) => {
|
||||
gather.addGatherer(gatherer);
|
||||
});
|
||||
|
||||
// Assign votes
|
||||
let leaderA = gatherers[0];
|
||||
let leaderB = gatherers[1];
|
||||
gatherers.forEach((voter, index) => {
|
||||
if (index % 2 === 0) {
|
||||
gather.selectLeader(voter, leaderA);
|
||||
} else {
|
||||
gather.selectLeader(voter, leaderB);
|
||||
}
|
||||
});
|
||||
|
||||
// Assign teams
|
||||
gatherers.forEach((gatherer, index) => {
|
||||
if (gatherer.leader) return;
|
||||
if (index % 2 === 0) {
|
||||
gather.moveToAlien(gatherer);
|
||||
} else {
|
||||
gather.moveToMarine(gatherer);
|
||||
}
|
||||
});
|
||||
gather.confirmSelection();
|
||||
assert.equal(gather.current, "done");
|
||||
return gather;
|
||||
}
|
||||
|
||||
describe("ArchivedGather", () => {
|
||||
var gather;
|
||||
|
||||
beforeEach(() => {
|
||||
gather = generateCompletedGather();
|
||||
});
|
||||
|
||||
describe("Create", () => {
|
||||
it ("creates an archived gather", () => {
|
||||
ArchivedGather.create({
|
||||
gather: gather.toJson()
|
||||
}, (error, result) => {
|
||||
if (error) return done(error);
|
||||
assert.isDefined(result.createdAt);
|
||||
let gather = result.gather;
|
||||
assert.equal(gather.gatherers.length, 12);
|
||||
assert.equal(gather.state, "done");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -25,6 +25,7 @@ var mongoose = require("mongoose");
|
|||
var Message = helpers.Message = mongoose.model("Message");
|
||||
var Session = helpers.Session = mongoose.model("Session");
|
||||
var Profile = helpers.Profile = mongoose.model("Profile");
|
||||
var ArchivedGather = helpers.ArchivedGather = mongoose.model("ArchivedGather");
|
||||
|
||||
var async = require("async");
|
||||
helpers.clearDb = function (callback) {
|
||||
|
|
Loading…
Reference in a new issue