File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments