@@ -168,7 +168,7 @@ describe("Utils", () => {
168168 assert . ok ( obj . first . second . third === "changed" ) ;
169169 } ) ;
170170
171- it ( "change object value, delete it" , ( ) => {
171+ it ( "change object value, change it but not delete " , ( ) => {
172172 let obj = {
173173 first : {
174174 second : {
@@ -179,8 +179,8 @@ describe("Utils", () => {
179179 }
180180 } ;
181181 let path = "first.second.third" ;
182- utils . mutateObjectProperty ( path , "changed" , obj , "third" ) ;
183- assert . ok ( ! obj . first . second . third ) ;
182+ utils . mutateObjectProperty ( path , "changed" , obj ) ;
183+ assert . ok ( obj . first . second . third === "changed" ) ;
184184 } ) ;
185185
186186 it ( "field not found, create it" , ( ) => {
@@ -334,5 +334,45 @@ describe("Utils", () => {
334334
335335 } ) ;
336336
337+ describe ( "#deleteNode" , ( ) => {
338+
339+ it ( "with nulls" , ( ) => {
340+ assert . doesNotThrow ( ( ) => {
341+ utils . deleteNode ( null , null , null ) ;
342+ utils . deleteNode ( "path.to.foo" , null , null ) ;
343+ let body = { } ;
344+ utils . deleteNode ( "path.to.foo" , body ) ;
345+ assert . ok ( JSON . stringify ( body ) === JSON . stringify ( { } ) ) ;
346+ } ) ;
347+ } ) ;
348+
349+ it ( "not found path, shouldn't remove it" , ( ) => {
350+ let body = { path : { to : { foo : { field : "value" } } } } ;
351+ let str = JSON . stringify ( body ) ;
352+ utils . deleteNode ( "path.to.notfound" , body , null ) ;
353+ assert . ok ( str === JSON . stringify ( body ) ) ;
354+ } ) ;
355+
356+ it ( "path found, should remove it" , ( ) => {
357+ let body = { path : { to : { foo : { field : "value" } } } } ;
358+ utils . deleteNode ( "path.to.foo" , body , null ) ;
359+ assert . ok ( JSON . stringify ( { path : { to : { } } } ) === JSON . stringify ( body ) ) ;
360+ } ) ;
361+
362+ it ( "root path, without properties, shouldn't remove" , ( ) => {
363+ let body = { path : { to : { foo : { field : "value" } } } } ;
364+ let str = JSON . stringify ( body ) ;
365+ utils . deleteNode ( "" , body , null ) ;
366+ assert . ok ( str === JSON . stringify ( body ) ) ;
367+ } ) ;
368+
369+ it ( "root path, with properties, should remove the properties" , ( ) => {
370+ let body = { path : { to : { foo : { field : "value" } } } , prop : "prop" , prop2 : "prop2" } ;
371+ utils . deleteNode ( "" , body , [ "prop" , "prop2" ] ) ;
372+ assert . ok ( JSON . stringify ( { "path" : { "to" : { "foo" : { "field" : "value" } } } } ) === JSON . stringify ( body ) ) ;
373+ } ) ;
374+
375+ } ) ;
376+
337377
338378} ) ;
0 commit comments