Skip to content

Commit 18766be

Browse files
authored
fix: cope with null relationships (#909)
Refs #859
1 parent 5ce8943 commit 18766be

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

src/index.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ import {
1212
insert,
1313
assocPath,
1414
pickBy,
15+
both,
16+
propSatisfies,
1517
} from 'ramda';
16-
import { mapIndexed, reduceIndexed, ensureArray, isArray } from 'ramda-adjunct';
18+
import {
19+
mapIndexed,
20+
reduceIndexed,
21+
ensureArray,
22+
isArray,
23+
isNotNull,
24+
} from 'ramda-adjunct';
1725

1826
// Type definitions:
1927
// Resource = Object
@@ -27,7 +35,7 @@ import { mapIndexed, reduceIndexed, ensureArray, isArray } from 'ramda-adjunct';
2735
// getRelationships :: Resource -> Relationships
2836
const getRelationships = pipe(
2937
propOr({}, ['relationships']),
30-
pickBy(has('data')),
38+
pickBy(both(has('data'), propSatisfies(isNotNull, 'data'))),
3139
keys
3240
);
3341

test/index.js

+42
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,48 @@ describe('jsonApiMerge', function () {
787787
});
788788
});
789789

790+
context(
791+
'given relationships have data property containing null',
792+
function () {
793+
const jsonApiData = {
794+
data: {
795+
id: 1,
796+
type: 'resource',
797+
attributes: {
798+
name: 'Resource name',
799+
},
800+
relationships: {
801+
related: {
802+
links: {
803+
related: {
804+
href: 'http://example.com/related-resource/',
805+
title: 'Related',
806+
},
807+
},
808+
data: null,
809+
},
810+
},
811+
},
812+
included: [
813+
{
814+
id: 2,
815+
type: 'related_resource',
816+
attributes: {
817+
name: 'Related resource name',
818+
},
819+
},
820+
],
821+
};
822+
823+
specify('should do nothing', function () {
824+
const actual = jsonApiMerge(jsonApiData.included, jsonApiData.data);
825+
const expected = actual;
826+
827+
assert.deepEqual(actual, expected);
828+
});
829+
}
830+
);
831+
790832
it('should curry', function () {
791833
const jsonApiData = {
792834
data: {

0 commit comments

Comments
 (0)