@@ -1769,6 +1769,43 @@ describe('JSONAPISerializer', function() {
1769
1769
done ( ) ;
1770
1770
} ) ;
1771
1771
1772
+ it ( 'should deserialize with missing included relationship and deserialize function' , function ( done ) {
1773
+ const Serializer = new JSONAPISerializer ( ) ;
1774
+ Serializer . register ( 'articles' , {
1775
+ relationships : {
1776
+ author : {
1777
+ type : 'people' ,
1778
+ deserialize : data => ( { id : data . id } )
1779
+ }
1780
+ }
1781
+ } ) ;
1782
+ Serializer . register ( 'people' , { } ) ;
1783
+
1784
+ const data = {
1785
+ data : {
1786
+ type : 'article' ,
1787
+ id : '1' ,
1788
+ attributes : {
1789
+ title : 'JSON API paints my bikeshed!' ,
1790
+ } ,
1791
+ relationships : {
1792
+ author : {
1793
+ data : {
1794
+ type : 'people' ,
1795
+ id : '1'
1796
+ }
1797
+ }
1798
+ }
1799
+ } ,
1800
+ included : [ ]
1801
+ }
1802
+
1803
+ const deserializedData = Serializer . deserialize ( 'articles' , data ) ;
1804
+ // People with id '1' is missing in included
1805
+ expect ( deserializedData ) . to . have . property ( 'author' ) . to . deep . eql ( { id : '1' } ) ;
1806
+ done ( ) ;
1807
+ } ) ;
1808
+
1772
1809
it ( 'should deserialize an array of data' , function ( done ) {
1773
1810
const Serializer = new JSONAPISerializer ( ) ;
1774
1811
Serializer . register ( 'articles' , { } ) ;
@@ -2083,7 +2120,7 @@ describe('JSONAPISerializer', function() {
2083
2120
2084
2121
it ( 'should deserializing relationship when alternativeKey is set and relationship data is not in the included array' , function ( done ) {
2085
2122
const Serializer = new JSONAPISerializer ( ) ;
2086
-
2123
+
2087
2124
Serializer . register ( 'article' , {
2088
2125
id : 'id' ,
2089
2126
relationships : {
@@ -2093,7 +2130,7 @@ describe('JSONAPISerializer', function() {
2093
2130
} ,
2094
2131
} ,
2095
2132
} ) ;
2096
-
2133
+
2097
2134
Serializer . register ( 'people' , {
2098
2135
id : 'id' ,
2099
2136
relationships : {
@@ -2103,9 +2140,9 @@ describe('JSONAPISerializer', function() {
2103
2140
} ,
2104
2141
} ,
2105
2142
} ) ;
2106
-
2143
+
2107
2144
Serializer . register ( 'role' , { } ) ;
2108
-
2145
+
2109
2146
const data = {
2110
2147
data : {
2111
2148
type : 'article' ,
@@ -2143,14 +2180,14 @@ describe('JSONAPISerializer', function() {
2143
2180
} ,
2144
2181
] ,
2145
2182
} ;
2146
-
2183
+
2147
2184
const deserializedData = Serializer . deserialize ( 'article' , data ) ;
2148
2185
expect ( deserializedData ) . to . have . property ( 'author_id' ) . to . eql ( '1' ) ;
2149
2186
expect ( deserializedData ) . to . have . property ( 'author' ) ;
2150
2187
expect ( deserializedData . author ) . to . have . property ( 'role_id' ) . to . eql ( '1' ) ;
2151
2188
expect ( deserializedData . author ) . to . not . have . property ( 'role' ) ;
2152
2189
done ( ) ;
2153
- } ) ;
2190
+ } ) ;
2154
2191
2155
2192
it ( 'should deserialize with \'deserialize\' option as a function' , function ( done ) {
2156
2193
const Serializer = new JSONAPISerializer ( ) ;
0 commit comments