@@ -565,6 +565,44 @@ describe('ResourceService', () => {
565565 } ) ;
566566
567567 describe ( 'update' , ( ) => {
568+ it ( 'should strip __typename recursively from update payload' , ( done ) => {
569+ const dirtyResource : any = {
570+ metadata : { name : 'test-name' , __typename : 'Meta' } ,
571+ spec : {
572+ __typename : 'Spec' ,
573+ items : [
574+ { key : 'a' , __typename : 'Item' } ,
575+ { key : 'b' , nested : { foo : 'bar' , __typename : 'Nested' } } ,
576+ ] ,
577+ map : {
578+ one : { val : 1 , __typename : 'Val' } ,
579+ two : [ { x : 1 , __typename : 'X' } , { y : 2 } ] ,
580+ } ,
581+ } ,
582+ } ;
583+
584+ mockApollo . mutate . mockReturnValue (
585+ of ( { data : { __typename : 'TestKind' } } ) ,
586+ ) ;
587+
588+ service
589+ . update ( dirtyResource , resourceDefinition , namespacedNodeContext )
590+ . subscribe ( ( ) => {
591+ const mutateCall = mockApollo . mutate . mock . calls [ 0 ] [ 0 ] ;
592+ const passedObject = mutateCall . variables . object ;
593+ expect ( passedObject ) . toEqual ( {
594+ metadata : { name : 'test-name' } ,
595+ spec : {
596+ items : [ { key : 'a' } , { key : 'b' , nested : { foo : 'bar' } } ] ,
597+ map : {
598+ one : { val : 1 } ,
599+ two : [ { x : 1 } , { y : 2 } ] ,
600+ } ,
601+ } ,
602+ } ) ;
603+ done ( ) ;
604+ } ) ;
605+ } ) ;
568606 it ( 'should update resource' , ( done ) => {
569607 mockApollo . mutate . mockReturnValue (
570608 of ( { data : { __typename : 'TestKind' } } ) ,
@@ -641,6 +679,33 @@ describe('ResourceService', () => {
641679 } ) ;
642680 } ) ;
643681
682+ describe ( 'stripTypename (private)' , ( ) => {
683+ it ( 'should return primitives as-is' , ( ) => {
684+ // @ts -ignore accessing private method for test
685+ expect ( ( service as any ) . stripTypename ( 42 ) ) . toBe ( 42 ) ;
686+ // @ts -ignore
687+ expect ( ( service as any ) . stripTypename ( 'x' ) ) . toBe ( 'x' ) ;
688+ // @ts -ignore
689+ expect ( ( service as any ) . stripTypename ( null ) ) . toBe ( null ) ;
690+ // @ts -ignore
691+ expect ( ( service as any ) . stripTypename ( undefined ) ) . toBe ( undefined ) ;
692+ } ) ;
693+
694+ it ( 'should clean nested objects and arrays' , ( ) => {
695+ const input = {
696+ __typename : 'Root' ,
697+ a : { __typename : 'A' , b : 1 } ,
698+ arr : [
699+ { __typename : 'X' , v : 1 } ,
700+ [ { __typename : 'Y' , z : 2 } , 3 ] ,
701+ ] ,
702+ } as any ;
703+ // @ts -ignore
704+ const output = ( service as any ) . stripTypename ( input ) ;
705+ expect ( output ) . toEqual ( { a : { b : 1 } , arr : [ { v : 1 } , [ { z : 2 } , 3 ] ] } ) ;
706+ } ) ;
707+ } ) ;
708+
644709 describe ( 'readAccountInfo' , ( ) => {
645710 it ( 'should read account info' , ( done ) => {
646711 const ca = 'cert-data' ;
0 commit comments