@@ -5,6 +5,7 @@ var query = require('./util/query')
55var JSONAPIComponent = require ( '../' )
66var app
77var Post
8+ var Comment
89
910describe ( 'loopback json api component create method' , function ( ) {
1011 beforeEach ( function ( ) {
@@ -17,6 +18,13 @@ describe('loopback json api component create method', function () {
1718 content : String
1819 } )
1920 app . model ( Post )
21+
22+ Comment = ds . createModel ( 'comment' , {
23+ id : { type : Number , id : true } ,
24+ content : String
25+ } )
26+ app . model ( Comment )
27+
2028 app . use ( loopback . rest ( ) )
2129 JSONAPIComponent ( app , { restApiRoot : '' } )
2230 } )
@@ -152,5 +160,33 @@ describe('loopback json api component create method', function () {
152160 done ( )
153161 } )
154162 } )
163+
164+ it ( 'POST /models with null relationship data' , function ( done ) {
165+ request ( app ) . post ( '/posts' ) . send ( {
166+ data : {
167+ type : 'posts' ,
168+ attributes : {
169+ title : 'my post' ,
170+ content : 'my post content'
171+ } ,
172+ relationships : {
173+ comments : {
174+ data : null
175+ }
176+ }
177+ }
178+ } )
179+ . set ( 'Content-Type' , 'application/json' )
180+ . end ( function ( err , res ) {
181+ expect ( err ) . to . equal ( null )
182+ expect ( res . body ) . to . have . all . keys ( 'data' )
183+ expect ( res . body . data ) . to . have . all . keys ( 'id' , 'type' , 'attributes' , 'links' )
184+ expect ( res . body . data . id ) . to . equal ( '1' )
185+ expect ( res . body . data . type ) . to . equal ( 'posts' )
186+ expect ( res . body . data . attributes ) . to . have . all . keys ( 'title' , 'content' )
187+ expect ( res . body . data . attributes ) . to . not . have . keys ( 'id' )
188+ done ( )
189+ } )
190+ } )
155191 } )
156192} )
0 commit comments