deno.land / x / mongoose@6.7.5 / test / gh-1408.test.js

gh-1408.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

/** * Test dependencies. */
'use strict';
const start = require('./common');
const assert = require('assert');
const mongoose = start.mongoose;const Schema = mongoose.Schema;
describe('documents should not be converted to _id (gh-1408)', function() { it('if an embedded doc', async function() { this.timeout(4500);
const db = start();
const PreferenceSchema = new Schema({ _id: { type: Schema.ObjectId, auto: true }, preference: { type: String, required: true }, value: { type: Schema.Types.Mixed } }, { versionKey: false });
const BrandSchema = new Schema({ settings: { preferences: [PreferenceSchema] } });
const A = db.model('Test', BrandSchema);
const a = new A({ settings: { preferences: [ { preference: 'group_colors', value: false }, { preference: 'can_force_orders', value: true }, { preference: 'hide_from_buyers', value: true }, { preference: 'no_orders', value: '' } ] } });
await a.save();
const doc = await A.findById(a);
const newData = { settings: { preferences: [ { preference: 'group_colors', value: true }, { preference: 'can_force_orders', value: true }, { preference: 'custom_csv', value: '' }, { preference: 'hide_from_buyers', value: false }, { preference: 'nozoom', value: false }, { preference: 'no_orders', value: false } ] } };
doc.set('settings', newData.settings, { merge: true }); doc.markModified('settings'); // <== this caused the bug await doc.save();
const doc2 = await A.findById(doc);

doc2.settings.preferences.forEach(function(pref, i) { assert.equal(pref.preference, newData.settings.preferences[i].preference); assert.equal(pref.value, newData.settings.preferences[i].value); });
await db.close(); });});
mongoose

Version Info

Tagged at
a year ago