File tree Expand file tree Collapse file tree
packages/kitsu-core/src/deserialise Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import { linkRelationships } from '../linkRelationships'
1111function deserialiseArray ( array ) {
1212 for ( let value of array . data ) {
1313 if ( array . included ) value = linkRelationships ( value , array . included )
14+ if ( array . data ) value = linkRelationships ( value , array . data )
1415 if ( value . relationships ) value = linkRelationships ( value )
1516 if ( value . attributes ) value = deattribute ( value )
1617 array . data [ array . data . indexOf ( value ) ] = value
Original file line number Diff line number Diff line change @@ -670,5 +670,107 @@ describe('kitsu-core', () => {
670670 ]
671671 } )
672672 } )
673+
674+ it ( 'deserialises a relationship from the data key' , ( ) => {
675+ expect . assertions ( 1 )
676+
677+ const input = deserialise ( {
678+ data : [
679+ {
680+ id : '1' ,
681+ type : 'anime' ,
682+ attributes : { name : 'A' } ,
683+ relationships : {
684+ prequel : {
685+ data : {
686+ type : 'anime' ,
687+ id : '42'
688+ }
689+ }
690+ }
691+ } ,
692+ {
693+ id : '2' ,
694+ type : 'anime' ,
695+ attributes : { name : 'B' } ,
696+ relationships : {
697+ prequel : {
698+ data : {
699+ type : 'anime' ,
700+ id : '1'
701+ }
702+ }
703+ }
704+ } ,
705+ {
706+ id : '3' ,
707+ type : 'anime' ,
708+ attributes : { name : 'C' } ,
709+ relationships : {
710+ prequel : {
711+ data : {
712+ type : 'anime' ,
713+ id : '1'
714+ }
715+ }
716+ }
717+ }
718+ ]
719+ } )
720+
721+ const output = {
722+ data : [
723+ {
724+ id : '1' ,
725+ type : 'anime' ,
726+ name : 'A' ,
727+ prequel : {
728+ data : {
729+ id : '42' ,
730+ type : 'anime'
731+ }
732+ }
733+ } ,
734+ {
735+ id : '2' ,
736+ type : 'anime' ,
737+ name : 'B' ,
738+ prequel : {
739+ data : {
740+ id : '1' ,
741+ type : 'anime' ,
742+ name : 'A' ,
743+ prequel : {
744+ data : {
745+ id : '42' ,
746+ type : 'anime'
747+ }
748+ }
749+ }
750+ }
751+ } ,
752+ {
753+ id : '3' ,
754+ type : 'anime' ,
755+ name : 'C' ,
756+ prequel : {
757+ data : {
758+ id : '1' ,
759+ type : 'anime' ,
760+ name : 'A' ,
761+ prequel : {
762+ data : {
763+ id : '42' ,
764+ type : 'anime'
765+ }
766+ }
767+ }
768+ }
769+ }
770+ ]
771+ }
772+
773+ expect ( input ) . toEqual ( output )
774+ } )
673775 } )
674776} )
You can’t perform that action at this time.
0 commit comments