File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,36 @@ describe('loopback json api belongsTo relationships', function () {
83
83
} ) ;
84
84
} ) ;
85
85
86
+ describe ( 'Comment with a post and relationship back to comment' , function ( done ) {
87
+ beforeEach ( function ( done ) {
88
+ Post . hasMany ( Comment , { as : 'comments' , foreignKey : 'postId' } ) ;
89
+ Comment . create ( {
90
+ title : 'my comment' ,
91
+ comment : 'my post comment'
92
+ } , function ( err , comment ) {
93
+ expect ( err ) . to . equal ( null ) ;
94
+ comment . post . create ( {
95
+ title : 'My post' ,
96
+ content : 'My post content'
97
+ } , done ) ;
98
+ } ) ;
99
+ } ) ;
100
+
101
+ describe ( 'GET /comments/1/post' , function ( ) {
102
+ it ( 'should display correct relationships' , function ( done ) {
103
+ request ( app ) . get ( '/comments/1/post' )
104
+ . end ( function ( err , res ) {
105
+ expect ( err ) . to . equal ( null ) ;
106
+ expect ( res . body . data . relationships . comments ) . to . be . an ( 'object' ) ;
107
+ expect ( res . body . data . relationships . comments . links ) . to . be . an ( 'object' ) ;
108
+ 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 $ / ) ;
109
+ expect ( res . body . data . relationships . post ) . to . be . undefined ;
110
+ done ( ) ;
111
+ } ) ;
112
+ } ) ;
113
+ } ) ;
114
+ } ) ;
115
+
86
116
describe ( 'Comment with an post' , function ( done ) {
87
117
beforeEach ( function ( done ) {
88
118
Comment . create ( {
You can’t perform that action at this time.
0 commit comments