Skip to content

Commit 1d341ba

Browse files
committed
Add 'with' tests for DSSqlAdapter#find
1 parent 1ca1541 commit 1d341ba

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/find.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,32 @@ describe('DSSqlAdapter#find', function () {
5454
assert.equal(err.message, 'Not Found!');
5555
}
5656
});
57+
58+
it('should load belongsTo relations', function* () {
59+
var profile = yield adapter.create(Profile, { email: '[email protected]' });
60+
var user = yield adapter.create(User, {name: 'John', profileId: profile.id});
61+
var post = yield adapter.create(Post, {content: 'foo', userId: user.id});
62+
var comment = yield adapter.create(Comment, { content: 'test2', postId: post.id, userId: post.userId });
63+
64+
var comment = yield adapter.find(Comment, comment.id, {'with': ['user', 'user.profile', 'post', 'post.user']});
65+
assert.isDefined(comment);
66+
assert.isDefined(comment.post);
67+
assert.isDefined(comment.post.user);
68+
assert.isDefined(comment.user);
69+
assert.isDefined(comment.user.profile);
70+
});
71+
72+
it('should load hasMany and belongsTo relations', function* () {
73+
var profile = yield adapter.create(Profile, { email: '[email protected]' });
74+
var user = yield adapter.create(User, {name: 'John', profileId: profile.id});
75+
var post = yield adapter.create(Post, {content: 'foo', userId: user.id});
76+
var comment = yield adapter.create(Comment, { content: 'test2', postId: post.id, userId: post.userId });
77+
78+
var foundPost = yield adapter.find(Post, post.id, {'with': ['user', 'comment', 'comment.user', 'comment.user.profile']});
79+
assert.isDefined(foundPost.comments);
80+
assert.isDefined(foundPost.comments[0].user);
81+
assert.isDefined(foundPost.comments[0].user.profile);
82+
assert.isDefined(foundPost.user);
83+
});
84+
5785
});

0 commit comments

Comments
 (0)