deno.land / x / mongoose@6.7.5 / test / document.unit.test.js

document.unit.test.js
نووسراو ببینە
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/** * Module dependencies. */
'use strict';
const start = require('./common');
const assert = require('assert');const storeShard = require('../lib/plugins/sharding').storeShard;
const mongoose = start.mongoose;
describe('sharding', function() { it('should handle shard keys properly (gh-2127)', function() { const mockSchema = { options: { shardKey: { date: 1 } } }; const Stub = function() { this.$__schema = mockSchema; this.$__ = {}; }; Object.setPrototypeOf(Stub.prototype, mongoose.Document.prototype); const d = new Stub(); const currentTime = new Date(); d._doc = { date: currentTime };
storeShard.call(d); assert.equal(d.$__.shardval.date, currentTime); });});
describe('toObject()', function() { let Stub;
beforeEach(function() { Stub = function() { const schema = this.$__schema = { options: { toObject: { minimize: false, virtuals: true } }, virtuals: { virtual: 'test' } }; this._doc = { empty: {} }; this.get = function(path) { return schema.virtuals[path]; }; this.$__ = {}; }; Stub.prototype = Object.create(mongoose.Document.prototype); });
it('should inherit options from schema', function() { const d = new Stub(); assert.deepEqual(d.toObject(), { empty: {}, virtual: 'test' }); });
it('can overwrite schema-set default options', function() { const d = new Stub(); assert.deepEqual(d.toObject({ minimize: true, virtuals: false }), {}); });
it('doesnt crash with empty object (gh-3130)', function() { const d = new Stub(); d._doc = undefined; assert.doesNotThrow(function() { d.toObject(); }); });});
mongoose

Version Info

Tagged at
a year ago