@@ -3731,6 +3731,11 @@ describe('document', function() {
3731
3731
3732
3732
assert . deepEqual (
3733
3733
kitty . modifiedPaths ( ) ,
3734
+ [ 'surnames' ]
3735
+ ) ;
3736
+
3737
+ assert . deepEqual (
3738
+ kitty . modifiedPaths ( { includeChildren : true } ) ,
3734
3739
[ 'surnames' , 'surnames.docarray' ]
3735
3740
) ;
3736
3741
} ) ;
@@ -9239,6 +9244,49 @@ describe('document', function() {
9239
9244
assert . ok ( foo . isModified ( 'subdoc.bar' ) ) ;
9240
9245
} ) ;
9241
9246
9247
+ it ( 'does not unmark modified if there is no initial value (gh-9396)' , async function ( ) {
9248
+ const IClientSchema = new Schema ( {
9249
+ jwt : {
9250
+ token_crypt : { type : String , template : false , maxSize : 8 * 1024 } ,
9251
+ token_salt : { type : String , template : false }
9252
+ }
9253
+ } ) ;
9254
+
9255
+ const encrypt = function ( doc , path , value ) {
9256
+ doc . set ( path + '_crypt' , value + '_crypt' ) ;
9257
+ doc . set ( path + '_salt' , value + '_salt' ) ;
9258
+ } ;
9259
+
9260
+ const decrypt = function ( doc , path ) {
9261
+ return doc . get ( path + '_crypt' ) . replace ( '_crypt' , '' ) ;
9262
+ } ;
9263
+
9264
+ IClientSchema . virtual ( 'jwt.token' )
9265
+ . get ( function ( ) {
9266
+ return decrypt ( this , 'jwt.token' ) ;
9267
+ } )
9268
+ . set ( function ( value ) {
9269
+ encrypt ( this , 'jwt.token' , value ) ;
9270
+ } ) ;
9271
+
9272
+
9273
+ const iclient = db . model ( 'Test' , IClientSchema ) ;
9274
+ const test = new iclient ( {
9275
+ jwt : {
9276
+ token : 'firstToken'
9277
+ }
9278
+ } ) ;
9279
+
9280
+ await test . save ( ) ;
9281
+ const entry = await iclient . findById ( test . _id ) . orFail ( ) ;
9282
+ entry . set ( 'jwt.token' , 'secondToken' ) ;
9283
+ entry . set ( entry . toJSON ( ) ) ;
9284
+ await entry . save ( ) ;
9285
+
9286
+ const { jwt } = await iclient . findById ( test . _id ) . orFail ( ) ;
9287
+ assert . strictEqual ( jwt . token , 'secondToken' ) ;
9288
+ } ) ;
9289
+
9242
9290
it ( 'correctly tracks saved state for deeply nested objects (gh-10773) (gh-9396)' , async function ( ) {
9243
9291
const PaymentSchema = Schema ( { status : String } , { _id : false } ) ;
9244
9292
const OrderSchema = new Schema ( {
@@ -12312,6 +12360,29 @@ describe('document', function() {
12312
12360
const nestedProjectionDoc = await User . findOne ( { } , { name : 1 , 'sub.propertyA' : 1 , 'sub.propertyB' : 1 } ) ;
12313
12361
assert . strictEqual ( nestedProjectionDoc . sub . propertyA , 'A' ) ;
12314
12362
} ) ;
12363
+
12364
+ it ( 'avoids adding nested paths to markModified() output if adding a new field (gh-14024)' , async function ( ) {
12365
+ const eventSchema = new Schema ( {
12366
+ name : { type : String } ,
12367
+ __stateBeforeSuspension : {
12368
+ field1 : { type : String } ,
12369
+ field2 : { type : String } ,
12370
+ jsonField : {
12371
+ name : { type : String } ,
12372
+ name1 : { type : String }
12373
+ }
12374
+ }
12375
+ } ) ;
12376
+ const Event = db . model ( 'Event' , eventSchema ) ;
12377
+ const eventObj = new Event ( { name : 'event object' , __stateBeforeSuspension : { field1 : 'test' , jsonField : { name : 'test3' } } } ) ;
12378
+ await eventObj . save ( ) ;
12379
+ const newObject = { field1 : 'test' , jsonField : { name : 'test3' , name1 : 'test4' } } ;
12380
+ eventObj . set ( '__stateBeforeSuspension' , newObject ) ;
12381
+ assert . deepEqual (
12382
+ eventObj . modifiedPaths ( ) ,
12383
+ [ '__stateBeforeSuspension' , '__stateBeforeSuspension.jsonField' ]
12384
+ ) ;
12385
+ } ) ;
12315
12386
} ) ;
12316
12387
12317
12388
describe ( 'Check if instance function that is supplied in schema option is availabe' , function ( ) {
0 commit comments