@@ -86,21 +86,36 @@ describe('loopback json api belongsTo relationships', function () {
8686 describe ( 'Comment with a post and relationship back to comment' , function ( done ) {
8787 beforeEach ( function ( done ) {
8888 Post . hasMany ( Comment , { as : 'comments' , foreignKey : 'postId' } ) ;
89- Comment . create ( {
90- title : 'my comment' ,
91- comment : 'my post comment'
92- } , function ( err , comment ) {
89+ Comment . create ( [ {
90+ title : 'my comment 1' ,
91+ comment : 'my post comment 1'
92+ } , {
93+ title : 'my comment 2' ,
94+ comment : 'my post comment 2'
95+ } ] , function ( err , comments ) {
9396 expect ( err ) . to . equal ( null ) ;
94- comment . post . create ( {
97+ comments [ 1 ] . post . create ( {
9598 title : 'My post' ,
9699 content : 'My post content'
97100 } , done ) ;
98101 } ) ;
99102 } ) ;
100103
101- describe ( 'GET /comments/1/post' , function ( ) {
102- it ( 'should display correct relationships' , function ( done ) {
103- request ( app ) . get ( '/comments/1/post' )
104+ describe ( 'should display correct relationships' , function ( ) {
105+ it ( 'GET /comments/2/post' , function ( done ) {
106+ request ( app ) . get ( '/comments/2/post' )
107+ . end ( function ( err , res ) {
108+ expect ( err ) . to . equal ( null ) ;
109+ expect ( res . body . data . relationships . comments ) . to . be . an ( 'object' ) ;
110+ expect ( res . body . data . relationships . comments . links ) . to . be . an ( 'object' ) ;
111+ expect ( res . body . data . relationships . comments . links . related ) . to . match ( / ^ h t t p .* \/ p o s t s \/ 1 \/ c o m m e n t s $ / ) ;
112+ expect ( res . body . data . relationships . post ) . to . be . undefined ;
113+ done ( ) ;
114+ } ) ;
115+ } ) ;
116+
117+ it ( 'GET /posts/1' , function ( done ) {
118+ request ( app ) . get ( '/posts/1' )
104119 . end ( function ( err , res ) {
105120 expect ( err ) . to . equal ( null ) ;
106121 expect ( res . body . data . relationships . comments ) . to . be . an ( 'object' ) ;
0 commit comments