deno.land / x / mongoose@6.7.5 / test / types.subdocument.test.js

types.subdocument.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

/** * Module dependencies. */
'use strict';
const start = require('./common');
const assert = require('assert');
const mongoose = start.mongoose;const Schema = mongoose.Schema;
/** * Test. */
describe('types.subdocument', function() { let GrandChildSchema; let ChildSchema; let ParentSchema; let db;
before(function() { GrandChildSchema = new Schema({ name: String });
ChildSchema = new Schema({ name: String, child: GrandChildSchema });
ParentSchema = new Schema({ name: String, children: [ChildSchema] });
mongoose.model('Parent-3589-Sub', ParentSchema); db = start(); });
after(async function() { await db.close(); });
it('returns a proper ownerDocument (gh-3589)', function() { const Parent = mongoose.model('Parent-3589-Sub'); const p = new Parent({ name: 'Parent Parentson', children: [ { name: 'Child Parentson', child: { name: 'GrandChild Parentson' } } ] });
assert.equal(p._id, p.children[0].child.ownerDocument()._id); });
it('not setting timestamps in subdocuments', function() { const Thing = db.model('Test', new Schema({ subArray: [{ testString: String }] }, { timestamps: true }));
const thingy = new Thing({ subArray: [{ testString: 'Test 1' }] }); let id; return thingy.save(). then(function() { id = thingy._id; }). then(function() { const thingy2 = { subArray: [{ testString: 'Test 2' }] }; return Thing.updateOne({ _id: id }, { $set: thingy2 }); }); });
describe('#isModified', function() { it('defers to parent isModified (gh-8223)', function() { const childSchema = Schema({ id: Number, text: String }); const parentSchema = Schema({ child: childSchema }); const Model = db.model('Test1', parentSchema);
const doc = new Model({ child: { text: 'foo' } }); assert.ok(doc.isModified('child.id')); assert.ok(doc.child.isModified('id')); }); });});
mongoose

Version Info

Tagged at
a year ago