Skip to content

Commit 061fac4

Browse files
committed
Add a test for the fix relationshipLinks on nested relationship
1 parent c85d114 commit 061fac4

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

test/serializer.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2501,4 +2501,63 @@ describe('JSON API Serializer', function () {
25012501
done(null, json);
25022502
});
25032503
});
2504+
2505+
describe('relationshipLinks', function () {
2506+
it('should set the relationshipLinks parameter when the nullIfMissing is used', function () {
2507+
var dataSet = {
2508+
id: '1',
2509+
firstName: 'Sandro',
2510+
lastName: 'Munda',
2511+
books: [{
2512+
id: '1',
2513+
createdAt: '2015-08-04T06:09:24.864Z',
2514+
publisher: {
2515+
id: '1',
2516+
name: 'hachette'
2517+
}
2518+
}, {
2519+
id: '2',
2520+
createdAt: '2015-08-04T07:09:24.864Z'
2521+
}]
2522+
};
2523+
2524+
var json = new JSONAPISerializer('users', {
2525+
topLevelLinks: {
2526+
self: 'http://localhost:3000/api/users'
2527+
},
2528+
attributes: ['firstName', 'lastName', 'books'],
2529+
books: {
2530+
ref: 'id',
2531+
attributes: ['createdAt', 'publisher'],
2532+
relationshipLinks: {
2533+
related: 'foo'
2534+
},
2535+
publisher: {
2536+
ref: 'id',
2537+
attributes: ['name'],
2538+
nullIfMissing: true,
2539+
relationshipLinks: {
2540+
related: 'bar'
2541+
},
2542+
}
2543+
}
2544+
}).serialize(dataSet);
2545+
2546+
expect(json.included).eql([{
2547+
type: 'publishers',
2548+
id: '1',
2549+
attributes: { name: 'hachette' }
2550+
}, {
2551+
type: 'books',
2552+
id: '1',
2553+
attributes: { 'created-at': '2015-08-04T06:09:24.864Z' },
2554+
relationships: { publisher: { data: { type: 'publishers', id: '1' }, links: { related: 'bar' } } }
2555+
}, {
2556+
type: 'books',
2557+
id: '2',
2558+
attributes: { 'created-at': '2015-08-04T07:09:24.864Z' },
2559+
relationships: { publisher: { data: null, links: { related: 'bar' } } }
2560+
}]);
2561+
});
2562+
});
25042563
});

0 commit comments

Comments
 (0)