Skip to content

Commit 90efdea

Browse files
committed
Merge pull request #63 from digitalsadhu/add/tests_for#61
Adds test to verify issue #61 is solved
2 parents 4feba03 + b8b9709 commit 90efdea

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/belongsTo.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,36 @@ describe('loopback json api belongsTo relationships', function () {
8383
});
8484
});
8585

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(/^http.*\/posts\/1\/comments$/);
109+
expect(res.body.data.relationships.post).to.be.undefined;
110+
done();
111+
});
112+
});
113+
});
114+
});
115+
86116
describe('Comment with an post', function (done) {
87117
beforeEach(function (done) {
88118
Comment.create({

0 commit comments

Comments
 (0)