@@ -77,7 +77,7 @@ describe('loopback json api belongsTo relationships', function () {
7777 . end ( function ( err , res ) {
7878 expect ( err ) . to . equal ( null )
7979 Comment . findById ( 1 , function ( err , comment ) {
80- expect ( err ) . to . equal ( undefined )
80+ expect ( err ) . to . equal ( null )
8181 expect ( comment ) . not . to . equal ( null )
8282 expect ( comment . postId ) . to . equal ( 2 )
8383
@@ -91,15 +91,26 @@ describe('loopback json api belongsTo relationships', function () {
9191 it ( 'should update model linkages' , function ( done ) {
9292 request ( app ) . patch ( '/posts/1' )
9393 . send ( {
94- data : { type : 'posts' , id : '1' , attributes : { title : 'my post' , content : 'my post content' } ,
95- relationships : { comments : { data : [ ] } } }
94+ data : {
95+ type : 'posts' ,
96+ id : '1' ,
97+ attributes : {
98+ title : 'my post' ,
99+ content : 'my post content'
100+ } ,
101+ relationships : {
102+ comments : {
103+ data : [ ]
104+ }
105+ }
106+ }
96107 } )
97108 . set ( 'Accept' , 'application/vnd.api+json' )
98109 . set ( 'Content-Type' , 'application/json' )
99110 . end ( function ( err , res ) {
100111 expect ( err ) . to . equal ( null )
101112 Comment . findById ( 1 , function ( err , comment ) {
102- expect ( err ) . to . equal ( undefined )
113+ expect ( err ) . to . equal ( null )
103114 expect ( comment ) . not . to . equal ( null )
104115 expect ( comment . postId ) . to . equal ( null )
105116
@@ -129,7 +140,7 @@ describe('loopback json api belongsTo relationships', function () {
129140 . end ( function ( err , res ) {
130141 expect ( err ) . to . equal ( null )
131142 Comment . find ( { postId : 1 } , function ( err , comments ) {
132- expect ( err ) . to . equal ( undefined )
143+ expect ( err ) . to . equal ( null )
133144 expect ( comments . length ) . to . equal ( 2 )
134145
135146 done ( )
@@ -150,7 +161,7 @@ describe('loopback json api belongsTo relationships', function () {
150161 . end ( function ( err , res ) {
151162 expect ( err ) . to . equal ( null )
152163 Comment . findById ( 1 , function ( err , comment ) {
153- expect ( err ) . to . equal ( undefined )
164+ expect ( err ) . to . equal ( null )
154165 expect ( comment ) . not . to . equal ( null )
155166 expect ( comment . postId ) . to . equal ( null )
156167
@@ -180,7 +191,7 @@ describe('loopback json api belongsTo relationships', function () {
180191 . end ( function ( err , res ) {
181192 expect ( err ) . to . equal ( null )
182193 Comment . find ( { postId : 1 } , function ( err , comments ) {
183- expect ( err ) . to . equal ( undefined )
194+ expect ( err ) . to . equal ( null )
184195 expect ( comments . length ) . not . to . equal ( 2 )
185196
186197 done ( )
@@ -236,7 +247,7 @@ describe('loopback json api belongsTo relationships', function () {
236247 expect ( err ) . to . equal ( null )
237248
238249 Comment . find ( { } , function ( err , comments ) {
239- expect ( err ) . to . equal ( undefined )
250+ expect ( err ) . to . equal ( null )
240251 _ . each ( comments , function ( comment ) {
241252 expect ( comment . postId ) . not . to . equal ( null )
242253 } )
@@ -269,9 +280,10 @@ describe('loopback json api hasOne relationships', function () {
269280 postId : Number ,
270281 name : String
271282 } )
283+ Person . settings . plural = 'people'
272284 app . model ( Person )
285+
273286 Post . hasOne ( Person , { as : 'author' , foreignKey : 'postId' } )
274- Person . settings . plural = 'people'
275287
276288 app . use ( loopback . rest ( ) )
277289 JSONAPIComponent ( app )
@@ -304,7 +316,7 @@ describe('loopback json api hasOne relationships', function () {
304316 expect ( res . body ) . not . to . have . keys ( 'errors' )
305317 expect ( res . status ) . to . equal ( 201 )
306318 Person . findById ( 1 , function ( err , person ) {
307- expect ( err ) . to . equal ( undefined )
319+ expect ( err ) . to . equal ( null )
308320 expect ( person ) . not . to . equal ( null )
309321 expect ( person . postId ) . to . equal ( 2 )
310322
@@ -328,7 +340,7 @@ describe('loopback json api hasOne relationships', function () {
328340 expect ( res . body ) . not . to . have . keys ( 'errors' )
329341 expect ( res . status ) . to . equal ( 200 )
330342 Person . findById ( 1 , function ( err , person ) {
331- expect ( err ) . to . equal ( undefined )
343+ expect ( err ) . to . equal ( null )
332344 expect ( person ) . not . to . equal ( null )
333345 expect ( person . postId ) . to . equal ( null )
334346 done ( )
@@ -339,27 +351,40 @@ describe('loopback json api hasOne relationships', function () {
339351
340352 describe ( 'replace linkages as part of an update operation' , function ( ) {
341353 beforeEach ( function ( done ) {
342- Person . create ( { name : 'Rachel McAdams' } , done )
354+ Person . create ( { id : 191 , name : 'Rachel McAdams' } , done )
343355 } )
344356 it ( 'should update model linkages' , function ( done ) {
345357 request ( app ) . patch ( '/posts/1' ) . send ( {
346- data : { type : 'posts' , id : '1' , attributes : { title : 'my post' , content : 'my post content' } ,
347- relationships : { author : { data : { type : 'people' , id : 2 } } } }
358+ data : {
359+ type : 'posts' ,
360+ id : '1' ,
361+ attributes : {
362+ title : 'my post' ,
363+ content : 'my post content'
364+ } ,
365+ relationships : {
366+ author : {
367+ data : {
368+ type : 'people' ,
369+ id : 191
370+ }
371+ }
372+ }
373+ }
348374 } )
349375 . set ( 'Accept' , 'application/vnd.api+json' )
350376 . set ( 'Content-Type' , 'application/json' )
351377 . end ( function ( err , res ) {
352378 expect ( err ) . to . equal ( null )
353379 Person . find ( { where : { postId : 1 } } , function ( err , people ) {
354- expect ( err ) . to . equal ( undefined )
380+ expect ( err ) . to . equal ( null )
355381 expect ( people . length ) . to . equal ( 1 )
356- expect ( people [ 0 ] . id ) . to . equal ( 2 )
382+ expect ( people [ 0 ] . id ) . to . equal ( 191 )
357383 done ( )
358384 } )
359385 } )
360386 } )
361387 } )
362-
363388 } )
364389} )
365390
@@ -417,7 +442,7 @@ describe('loopback json api hasMany relationships', function () {
417442 . end ( function ( err , res ) {
418443 expect ( err ) . to . equal ( null )
419444 Comment . findById ( 1 , function ( err , comment ) {
420- expect ( err ) . to . equal ( undefined )
445+ expect ( err ) . to . equal ( null )
421446 expect ( comment ) . not . to . equal ( null )
422447 expect ( comment . postId ) . to . equal ( 2 )
423448 done ( )
@@ -438,7 +463,7 @@ describe('loopback json api hasMany relationships', function () {
438463 . end ( function ( err , res ) {
439464 expect ( err ) . to . equal ( null )
440465 Comment . findById ( 1 , function ( err , comment ) {
441- expect ( err ) . to . equal ( undefined )
466+ expect ( err ) . to . equal ( null )
442467 expect ( comment ) . not . to . equal ( null )
443468 expect ( comment . postId ) . to . equal ( null )
444469 done ( )
@@ -467,7 +492,7 @@ describe('loopback json api hasMany relationships', function () {
467492 . end ( function ( err , res ) {
468493 expect ( err ) . to . equal ( null )
469494 Comment . find ( { postId : 1 } , function ( err , comments ) {
470- expect ( err ) . to . equal ( undefined )
495+ expect ( err ) . to . equal ( null )
471496 expect ( comments . length ) . to . equal ( 2 )
472497 done ( )
473498 } )
0 commit comments