Skip to content

Commit

Permalink
Add parent test
Browse files Browse the repository at this point in the history
  • Loading branch information
tfoxy committed Jan 18, 2016
1 parent e2f53c4 commit e9a882e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/find.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,33 @@ describe('DSHttpAdapter.find(resourceConfig, id, options)', function () {
return otherAdapter.find(Post, 1);
});
});

it('should use parent', function () {
var _this = this;

var Thing = datastore.defineResource({
name: 'thing',
endpoint: 'things',
relations: {
belongsTo: {
user: {
localKey: 'userId',
localField: 'user',
parent: true
}
}
}
});

setTimeout(function () {
assert.equal(1, _this.requests.length);
assert.equal(_this.requests[0].url, 'user/2/things/1');
assert.equal(_this.requests[0].method, 'GET');
_this.requests[0].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ id: 1 }));
}, 30);

return dsHttpAdapter.find(Thing, 1, { params: { userId: 2 } }).then(function (data) {
assert.deepEqual(data, { id: 1 }, 'thing should have been found');
});
});
});

0 comments on commit e9a882e

Please sign in to comment.