Skip to content

Commit

Permalink
fix: cope with null relationships (#909)
Browse files Browse the repository at this point in the history
Refs #859
  • Loading branch information
char0n committed Aug 15, 2023
1 parent 5ce8943 commit 18766be
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ import {
insert,
assocPath,
pickBy,
both,
propSatisfies,
} from 'ramda';
import { mapIndexed, reduceIndexed, ensureArray, isArray } from 'ramda-adjunct';
import {
mapIndexed,
reduceIndexed,
ensureArray,
isArray,
isNotNull,
} from 'ramda-adjunct';

// Type definitions:
// Resource = Object
Expand All @@ -27,7 +35,7 @@ import { mapIndexed, reduceIndexed, ensureArray, isArray } from 'ramda-adjunct';
// getRelationships :: Resource -> Relationships
const getRelationships = pipe(
propOr({}, ['relationships']),
pickBy(has('data')),
pickBy(both(has('data'), propSatisfies(isNotNull, 'data'))),
keys
);

Expand Down
42 changes: 42 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,48 @@ describe('jsonApiMerge', function () {
});
});

context(
'given relationships have data property containing null',
function () {
const jsonApiData = {
data: {
id: 1,
type: 'resource',
attributes: {
name: 'Resource name',
},
relationships: {
related: {
links: {
related: {
href: 'http://example.com/related-resource/',
title: 'Related',
},
},
data: null,
},
},
},
included: [
{
id: 2,
type: 'related_resource',
attributes: {
name: 'Related resource name',
},
},
],
};

specify('should do nothing', function () {
const actual = jsonApiMerge(jsonApiData.included, jsonApiData.data);
const expected = actual;

assert.deepEqual(actual, expected);
});
}
);

it('should curry', function () {
const jsonApiData = {
data: {
Expand Down

0 comments on commit 18766be

Please sign in to comment.