UNPKG

mongoose-utilities

Version:
74 lines (64 loc) 2.02 kB
// Dependencies var util = require('util') , assert = require('assert') , mongoose = require('mongoose') , timestamp = require('../lib/timestamp') , common = require('./support/common') , db = common.db , Schema = mongoose.Schema , ObjectId = Schema.ObjectId // Run tests describe('Timestamp', function () { describe('#default()', function () { var FooSchema = new Schema() FooSchema.plugin(timestamp) var FooModel = db.model('timeFoo', FooSchema) , bar = new FooModel() before(function () { FooModel.remove(function (err) { assert.strictEqual(err, null) }) }) it('should have custom properties', function (done) { assert.strictEqual(typeof FooSchema.virtuals.created, 'object') assert.strictEqual(typeof FooSchema.paths.modified, 'object') done() }) it('should create the default attributes', function (done) { bar.save(function (err, doc) { assert.strictEqual(err, null) assert.strictEqual(util.isDate(doc.created), true) assert.strictEqual(util.isDate(doc.modified), true) done() }) }) }) describe('#custom()', function () { var FooSchema = new Schema() FooSchema.plugin(timestamp, { createdPath: 'oh' , modifiedPath: 'hai' , useVirtual: false }) var BarModel = db.model('timeBar', FooSchema) , bar = new BarModel() before(function () { BarModel.remove(function (err) { assert.strictEqual(err, null) }) }) it('should have custom properties', function (done) { assert.strictEqual(typeof FooSchema.paths.oh, 'object') assert.strictEqual(typeof FooSchema.paths.hai, 'object') done() }) it('should create custom attributes', function (done) { bar.save(function (err, doc) { assert.strictEqual(err, null) assert.strictEqual(util.isDate(doc.oh), true) assert.strictEqual(util.isDate(doc.hai), true) done() }) }) }) })