Skip to content

Commit

Permalink
test: add tests when relationship.data is missing
Browse files Browse the repository at this point in the history
Refs #778
  • Loading branch information
char0n committed Feb 22, 2023
1 parent 29da7a7 commit c7da0f5
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ describe('jsonApiMerge', function () {
],
};

context('should create full linkage', function () {
specify('should create full linkage', function () {
const expected = [
{
type: 'articles',
Expand Down Expand Up @@ -732,6 +732,44 @@ describe('jsonApiMerge', function () {
});
});

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

specify('should throw error', function () {
const included = jsonApiMerge(jsonApiData.included, jsonApiData.included);
const thunk = () => jsonApiMerge(included, jsonApiData.data);

assert.throws(thunk, "Cannot read property 'type' of undefined");
});
});

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

0 comments on commit c7da0f5

Please sign in to comment.