-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathindex_test.js
More file actions
49 lines (42 loc) · 1.33 KB
/
index_test.js
File metadata and controls
49 lines (42 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* @list dependencies
**/
var mocha = require('mocha');
var should = require('should');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var timestamps = require('../');
mongoose = mongoose.createConnection('mongodb://localhost/mongoose_timestamps')
mongoose.on('error', function (err) {
console.error('MongoDB error: ' + err.message);
console.error('Make sure a mongoDB server is running and accessible by this application')
});
var TimeCopSchema = new Schema({
email: String,
nemesis: String
});
TimeCopSchema.plugin(timestamps);
var TimeCop = mongoose.model('TimeCop', TimeCopSchema);
describe('timestamps', function() {
it('should be set to the same value on creation', function(done) {
var cop = new TimeCop({ email: 'brian@brian.com' });
cop.save( function (err) {
cop.createdAt.should.eql(cop.updatedAt);
done();
});
})
it('should have updatedAt greater than createdAt upon updating', function(done) {
TimeCop.findOne({email: 'brian@brian.com'}, function (err, found) {
found.email = 'jeanclaude@vandamme.com';
setTimeout( function () {
found.save( function (err, updated) {
updated.updatedAt.should.be.above(updated.createdAt);
done();
});
}, 1000);
});
})
after(function() {
mongoose.close();
});
})