@@ -662,6 +662,7 @@ describe('a generate json patch function', () => {
662
662
fourthLevel : 'hello-world' ,
663
663
} ,
664
664
thirdLevelTwo : 'hello' ,
665
+ thirdLevelThree : [ 'hello' , 'world' ] ,
665
666
} ,
666
667
} ,
667
668
} ;
@@ -673,6 +674,7 @@ describe('a generate json patch function', () => {
673
674
fourthLevel : 'hello-brave-new-world' ,
674
675
} ,
675
676
thirdLevelTwo : 'hello' ,
677
+ thirdLevelThree : [ 'hello' , 'world' ] ,
676
678
} ,
677
679
} ,
678
680
} ;
@@ -688,13 +690,16 @@ describe('a generate json patch function', () => {
688
690
fourthLevel : 'hello-brave-new-world' ,
689
691
} ,
690
692
thirdLevelTwo : 'hello' ,
693
+ thirdLevelThree : [ 'hello' , 'world' ] ,
691
694
} ,
692
695
} ,
693
696
] ) ;
694
697
} ) ;
695
698
696
699
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 } ) ;
698
703
expect ( patch ) . to . eql ( [
699
704
{
700
705
op : 'replace' ,
@@ -703,6 +708,51 @@ describe('a generate json patch function', () => {
703
708
fourthLevel : 'hello-brave-new-world' ,
704
709
} ,
705
710
} ,
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
+ } ,
706
756
] ) ;
707
757
} ) ;
708
758
} ) ;
0 commit comments