Added basic archivedGather model

This commit is contained in:
Chris Blanchard 2015-09-21 22:59:00 +01:00
parent 895aa826c1
commit 541facd1fd
4 changed files with 87 additions and 0 deletions

View file

@ -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;

View 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
View 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();
});
});
});
});

View file

@ -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) {