Fix Model.exists() to work with remote connector

This commit is contained in:
Maxim Sharai 2019-01-22 16:12:19 +03:00 committed by Miroslav Bajtoš
parent ae3fff9e7b
commit e8d115bdc2
No known key found for this signature in database
GPG Key ID: 6F2304BA9361C7E3
2 changed files with 23 additions and 1 deletions

View File

@ -724,7 +724,8 @@ module.exports = function(registry) {
description: 'Check whether a model instance exists in the data source.',
accessType: 'READ',
accepts: [
{arg: 'id', type: 'any', description: 'Model id', required: true},
{arg: 'id', type: 'any', description: 'Model id', required: true,
http: {source: 'path'}},
{arg: 'options', type: 'object', http: 'optionsFromRequest'},
],
returns: {arg: 'exists', type: 'boolean'},

View File

@ -235,6 +235,27 @@ module.exports = function defineModelTestsWithDataSource(options) {
});
});
describe('Model.exists(id, [callback])', function() {
it('returns true when the model with the given id exists', function(done) {
User.create({first: 'max'}, function(err, user) {
if (err) return done(err);
User.exists(user.id, function(err, exist) {
if (err) return done(err);
assert.equal(exist, true);
done();
});
});
});
it('returns false when there is no model with the given id', function(done) {
User.exists('user-id-does-not-exist', function(err, exist) {
if (err) return done(err);
assert.equal(exist, false);
done();
});
});
});
describe('Model.findById(id, callback)', function() {
it('Find an instance by id', function(done) {
User.create({first: 'michael', last: 'jordan', id: 23}, function() {