Merge pull request #4120 from angfal/fix/remote_exists

Fix Model.exists() to work with remote connector
This commit is contained in:
Miroslav Bajtoš 2019-05-13 15:55:45 +02:00 committed by GitHub
commit 4b3a3a347c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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() {