@@ -662,6 +662,7 @@ describe('a generate json patch function', () => {
662662 fourthLevel : 'hello-world' ,
663663 } ,
664664 thirdLevelTwo : 'hello' ,
665+ thirdLevelThree : [ 'hello' , 'world' ] ,
665666 } ,
666667 } ,
667668 } ;
@@ -673,6 +674,7 @@ describe('a generate json patch function', () => {
673674 fourthLevel : 'hello-brave-new-world' ,
674675 } ,
675676 thirdLevelTwo : 'hello' ,
677+ thirdLevelThree : [ 'hello' , 'world' ] ,
676678 } ,
677679 } ,
678680 } ;
@@ -688,13 +690,16 @@ describe('a generate json patch function', () => {
688690 fourthLevel : 'hello-brave-new-world' ,
689691 } ,
690692 thirdLevelTwo : 'hello' ,
693+ thirdLevelThree : [ 'hello' , 'world' ] ,
691694 } ,
692695 } ,
693696 ] ) ;
694697 } ) ;
695698
696699 it ( 'detects changes as a given depth of 4' , ( ) => {
697- const patch = generateJSONPatch ( before , after , { maxDepth : 4 } ) ;
700+ const afterModified = structuredClone ( after ) ;
701+ afterModified . firstLevel . secondLevel . thirdLevelTwo = 'hello-world' ;
702+ const patch = generateJSONPatch ( before , afterModified , { maxDepth : 4 } ) ;
698703 expect ( patch ) . to . eql ( [
699704 {
700705 op : 'replace' ,
@@ -703,6 +708,51 @@ describe('a generate json patch function', () => {
703708 fourthLevel : 'hello-brave-new-world' ,
704709 } ,
705710 } ,
711+ {
712+ op : 'replace' ,
713+ path : '/firstLevel/secondLevel/thirdLevelTwo' ,
714+ value : 'hello-world' ,
715+ } ,
716+ ] ) ;
717+ } ) ;
718+
719+ it ( 'detects changes as a given depth of 4 for an array value' , ( ) => {
720+ const afterModified = structuredClone ( before ) ;
721+ afterModified . firstLevel . secondLevel . thirdLevelThree = [ 'test' ] ;
722+ const patch = generateJSONPatch ( before , afterModified , { maxDepth : 4 } ) ;
723+ expect ( patch ) . to . eql ( [
724+ {
725+ op : 'replace' ,
726+ path : '/firstLevel/secondLevel/thirdLevelThree' ,
727+ value : [ 'test' ] ,
728+ } ,
729+ ] ) ;
730+ } ) ;
731+
732+ it ( 'detects changes as a given depth of 4 for an removed array value' , ( ) => {
733+ const afterModified = structuredClone ( before ) ;
734+ // @ts -ignore
735+ delete afterModified . firstLevel . secondLevel . thirdLevelThree ;
736+ const patch = generateJSONPatch ( before , afterModified , { maxDepth : 4 } ) ;
737+ expect ( patch ) . to . eql ( [
738+ {
739+ op : 'remove' ,
740+ path : '/firstLevel/secondLevel/thirdLevelThree' ,
741+ } ,
742+ ] ) ;
743+ } ) ;
744+
745+ it ( 'detects changes as a given depth of 4 for an nullyfied array value' , ( ) => {
746+ const afterModified = structuredClone ( before ) ;
747+ // @ts -ignore
748+ afterModified . firstLevel . secondLevel . thirdLevelThree = null ;
749+ const patch = generateJSONPatch ( before , afterModified , { maxDepth : 4 } ) ;
750+ expect ( patch ) . to . eql ( [
751+ {
752+ op : 'replace' ,
753+ path : '/firstLevel/secondLevel/thirdLevelThree' ,
754+ value : null ,
755+ } ,
706756 ] ) ;
707757 } ) ;
708758 } ) ;
0 commit comments