@@ -2614,7 +2614,7 @@ describe('JSON API Serializer', function () {
26142614 } ] ) ;
26152615 } ) ;
26162616
2617- it ( 'should not be set when the relationshipLinks return null' , function ( ) {
2617+ it ( 'should not be set when the related relationshipLinks return null' , function ( ) {
26182618 var dataSet = {
26192619 id : '54735750e16638ba1eee59cb' ,
26202620 firstName : 'Sandro' ,
@@ -2637,5 +2637,152 @@ describe('JSON API Serializer', function () {
26372637
26382638 expect ( json . data . relationships . address ) . eql ( { data : null } ) ;
26392639 } ) ;
2640+
2641+ it ( 'should not be set when the self relationshipLinks return null' , function ( ) {
2642+ var dataSet = {
2643+ id : '54735750e16638ba1eee59cb' ,
2644+ firstName : 'Sandro' ,
2645+ lastName : 'Munda' ,
2646+ address : null ,
2647+ } ;
2648+
2649+ var json = new JSONAPISerializer ( 'users' , {
2650+ attributes : [ 'firstName' , 'lastName' , 'address' ] ,
2651+ address : {
2652+ ref : 'id' ,
2653+ included : false ,
2654+ relationshipLinks : {
2655+ self : function ( ) {
2656+ return null ;
2657+ }
2658+ } ,
2659+ }
2660+ } ) . serialize ( dataSet ) ;
2661+
2662+ expect ( json . data . relationships . address ) . eql ( { data : null } ) ;
2663+ } ) ;
2664+
2665+ it ( 'should be set when the relationshipLinks returns a self link only' , function ( ) {
2666+ var dataSet = {
2667+ id : '54735750e16638ba1eee59cb' ,
2668+ firstName : 'Sandro' ,
2669+ lastName : 'Munda' ,
2670+ address : null ,
2671+ } ;
2672+
2673+ var json = new JSONAPISerializer ( 'users' , {
2674+ attributes : [ 'firstName' , 'lastName' , 'address' ] ,
2675+ address : {
2676+ ref : 'id' ,
2677+ included : false ,
2678+ relationshipLinks : {
2679+ self : function ( ) {
2680+ return 'self-relationship-link'
2681+ }
2682+ } ,
2683+ }
2684+ } ) . serialize ( dataSet ) ;
2685+
2686+ expect ( json . data . relationships . address ) . eql ( {
2687+ data : null ,
2688+ links : {
2689+ self : 'self-relationship-link'
2690+ }
2691+ } ) ;
2692+ } ) ;
2693+
2694+ it ( 'should be set when the relationshipLinks returns a related link only' , function ( ) {
2695+ var dataSet = {
2696+ id : '54735750e16638ba1eee59cb' ,
2697+ firstName : 'Sandro' ,
2698+ lastName : 'Munda' ,
2699+ address : null ,
2700+ } ;
2701+
2702+ var json = new JSONAPISerializer ( 'users' , {
2703+ attributes : [ 'firstName' , 'lastName' , 'address' ] ,
2704+ address : {
2705+ ref : 'id' ,
2706+ included : false ,
2707+ relationshipLinks : {
2708+ related : function ( ) {
2709+ return 'related-relationship-link'
2710+ }
2711+ } ,
2712+ }
2713+ } ) . serialize ( dataSet ) ;
2714+
2715+ expect ( json . data . relationships . address ) . eql ( {
2716+ data : null ,
2717+ links : {
2718+ related : 'related-relationship-link'
2719+ }
2720+ } ) ;
2721+ } ) ;
2722+
2723+ it ( 'should be set when the relationshipLinks returns a related link and null self link' , function ( ) {
2724+ var dataSet = {
2725+ id : '54735750e16638ba1eee59cb' ,
2726+ firstName : 'Sandro' ,
2727+ lastName : 'Munda' ,
2728+ address : null ,
2729+ } ;
2730+
2731+ var json = new JSONAPISerializer ( 'users' , {
2732+ attributes : [ 'firstName' , 'lastName' , 'address' ] ,
2733+ address : {
2734+ ref : 'id' ,
2735+ included : false ,
2736+ relationshipLinks : {
2737+ related : function ( ) {
2738+ return 'related-relationship-link'
2739+ } ,
2740+ self : function ( ) {
2741+ return null
2742+ }
2743+ } ,
2744+ }
2745+ } ) . serialize ( dataSet ) ;
2746+
2747+ expect ( json . data . relationships . address ) . eql ( {
2748+ data : null ,
2749+ links : {
2750+ related : 'related-relationship-link'
2751+ }
2752+ } ) ;
2753+ } ) ;
2754+
2755+
2756+ it ( 'should be set when the relationshipLinks returns a self link and null related link' , function ( ) {
2757+ var dataSet = {
2758+ id : '54735750e16638ba1eee59cb' ,
2759+ firstName : 'Sandro' ,
2760+ lastName : 'Munda' ,
2761+ address : null ,
2762+ } ;
2763+
2764+ var json = new JSONAPISerializer ( 'users' , {
2765+ attributes : [ 'firstName' , 'lastName' , 'address' ] ,
2766+ address : {
2767+ ref : 'id' ,
2768+ included : false ,
2769+ relationshipLinks : {
2770+ related : function ( ) {
2771+ return null
2772+ } ,
2773+ self : function ( ) {
2774+ return 'self-relationship-link'
2775+ }
2776+ } ,
2777+ }
2778+ } ) . serialize ( dataSet ) ;
2779+
2780+ expect ( json . data . relationships . address ) . eql ( {
2781+ data : null ,
2782+ links : {
2783+ self : 'self-relationship-link'
2784+ }
2785+ } ) ;
2786+ } ) ;
26402787 } ) ;
26412788} ) ;
0 commit comments