mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2025-01-31 13:30:37 +00:00
Update
This commit is contained in:
parent
541facd1fd
commit
38a312001f
3 changed files with 46 additions and 3 deletions
|
@ -10,8 +10,14 @@ var archivedGatherSchema = new Schema({
|
|||
|
||||
archivedGatherSchema.index({ createdAt: -1 });
|
||||
|
||||
archivedGatherSchema.static('recent', function (callback) {
|
||||
|
||||
archivedGatherSchema.static({
|
||||
recent: function (callback) {
|
||||
this
|
||||
.where({})
|
||||
.sort({createdAt: -1})
|
||||
.limit(5)
|
||||
.exec(callback);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = mongoose.model("ArchivedGather", archivedGatherSchema);
|
||||
|
|
|
@ -52,7 +52,7 @@ describe("ArchivedGather", () => {
|
|||
});
|
||||
|
||||
describe("Create", () => {
|
||||
it ("creates an archived gather", () => {
|
||||
it ("creates an archived gather", done => {
|
||||
ArchivedGather.create({
|
||||
gather: gather.toJson()
|
||||
}, (error, result) => {
|
||||
|
@ -65,4 +65,38 @@ describe("ArchivedGather", () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe(".recent", () => {
|
||||
var gathers;
|
||||
beforeEach(done => {
|
||||
async.timesSeries(7, (n, next) => {
|
||||
ArchivedGather.create({
|
||||
gather: generateCompletedGather()
|
||||
}, (error, result) => {
|
||||
setTimeout(() => {
|
||||
next(error, result);
|
||||
}, 30);
|
||||
});
|
||||
}, (error, results) => {
|
||||
if (error) return done(error);
|
||||
gathers = results;
|
||||
done();
|
||||
});
|
||||
});
|
||||
// it ("returns an empty array if no recent gathers", done => {
|
||||
|
||||
// });
|
||||
// it ("returns 5 most recent gathers", done => {
|
||||
// let lastFive = gathers.slice(Math.max(gathers.length - 5, 1));
|
||||
// ArchivedGather.recent((error, results) => {
|
||||
// if (error) return done(error);
|
||||
// assert.equal(results.length, 5);
|
||||
// lastFive.forEach(recent => {
|
||||
// assert.isTrue(results.some(result => {
|
||||
// return result.gather.done.time === recent.done.time;
|
||||
// }));
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
});
|
||||
});
|
|
@ -38,6 +38,9 @@ helpers.clearDb = function (callback) {
|
|||
},
|
||||
function (cb) {
|
||||
Profile.remove({}, cb)
|
||||
},
|
||||
function (cb) {
|
||||
ArchivedGather.remove({}, cb)
|
||||
}
|
||||
], callback);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue