From 1eea9406975bffd2edc0f5d342e25ad906cb2f82 Mon Sep 17 00:00:00 2001 From: Paul Warren Date: Thu, 16 Feb 2023 18:17:49 +0000 Subject: [PATCH 1/4] Filter to relationships with data property. --- src/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 191d3e74..3e88afa5 100644 --- a/src/index.js +++ b/src/index.js @@ -11,6 +11,7 @@ import { concat, insert, assocPath, + pickBy } from 'ramda'; import { mapIndexed, reduceIndexed, ensureArray, isArray } from 'ramda-adjunct'; @@ -24,7 +25,7 @@ import { mapIndexed, reduceIndexed, ensureArray, isArray } from 'ramda-adjunct'; // RelPath = {path: String, key: ResourceKey} // getRelationships :: Resource -> Relationships -const getRelationships = pipe(propOr({}, ['relationships']), keys); +const getRelationships = pipe(propOr({}, ['relationships']), pickBy(has('data')), keys); // resourceKey :: ResourceRel -> ResourceKey const resourceKey = ({ type, id }) => `${type}-${id}`; From 39c885858d3c0514849e9c679df3465d01573c39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Wed, 22 Feb 2023 17:13:19 +0100 Subject: [PATCH 2/4] Update src/index.js --- src/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 3e88afa5..70abd72b 100644 --- a/src/index.js +++ b/src/index.js @@ -25,7 +25,11 @@ import { mapIndexed, reduceIndexed, ensureArray, isArray } from 'ramda-adjunct'; // RelPath = {path: String, key: ResourceKey} // getRelationships :: Resource -> Relationships -const getRelationships = pipe(propOr({}, ['relationships']), pickBy(has('data')), keys); +const getRelationships = pipe( + propOr({}, ['relationships']), + pickBy(has('data')), + keys +); // resourceKey :: ResourceRel -> ResourceKey const resourceKey = ({ type, id }) => `${type}-${id}`; From b62de182af823aa782617ad6fba1b0a9392d1dd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Wed, 22 Feb 2023 17:14:52 +0100 Subject: [PATCH 3/4] Update index.js --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 70abd72b..72659975 100644 --- a/src/index.js +++ b/src/index.js @@ -11,7 +11,7 @@ import { concat, insert, assocPath, - pickBy + pickBy, } from 'ramda'; import { mapIndexed, reduceIndexed, ensureArray, isArray } from 'ramda-adjunct'; From 7295bdef12f3a2e9c2c457bfeb74f47354794769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Wed, 22 Feb 2023 17:18:15 +0100 Subject: [PATCH 4/4] test: align tests with changes in #778 Refs #778 --- test/index.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/test/index.js b/test/index.js index 44c423bd..06ecd565 100644 --- a/test/index.js +++ b/test/index.js @@ -763,10 +763,27 @@ describe('jsonApiMerge', function () { }; specify('should throw error', function () { - const included = jsonApiMerge(jsonApiData.included, jsonApiData.included); - const thunk = () => jsonApiMerge(included, jsonApiData.data); + const expected = { + id: 1, + type: 'resource', + attributes: { + name: 'Resource name', + }, + relationships: { + related: { + links: { + related: { + href: 'http://example.com/related-resource/', + title: 'Related', + }, + }, + }, + }, + }; - assert.throws(thunk, TypeError); + const actual = jsonApiMerge(jsonApiData.included, jsonApiData.data); + + assert.deepEqual(actual, expected); }); });