Skip to content

Commit a6e0c49

Browse files
committed
fix(kitsu-core): fix deserialisation of relationships from primary data
1 parent d5e20ac commit a6e0c49

2 files changed

Lines changed: 103 additions & 1 deletion

File tree

packages/kitsu-core/src/deserialise/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { linkRelationships } from '../linkRelationships'
1111
function deserialiseArray (array) {
1212
for (let value of array.data) {
1313
if (array.included) value = linkRelationships(value, array.included)
14-
if (value.relationships) value = linkRelationships(value)
14+
value = linkRelationships(value, array.data)
1515
if (value.attributes) value = deattribute(value)
1616
array.data[array.data.indexOf(value)] = value
1717
}

packages/kitsu-core/src/deserialise/index.spec.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff 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
})

0 commit comments

Comments
 (0)