-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
gh-1408.test.js
84 lines (66 loc) · 2.22 KB
/
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
80
81
82
83
84
/**
* 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', function(done) {
this.timeout(process.env.TRAVIS ? 8000 : 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('gh-1408', 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: ''}
]
}
});
a.save(function(err, a) {
if (err) return done(err);
A.findById(a, function(err, doc) {
if (err) return done(err);
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
doc.save(function(err) {
if (err) return done(err);
A.findById(doc, function(err, doc) {
if (err) return done(err);
doc.settings.preferences.forEach(function(pref, i) {
assert.equal(pref.preference, newData.settings.preferences[i].preference);
assert.equal(pref.value, newData.settings.preferences[i].value);
});
db.close(done);
});
});
});
});
});
});