Merge pull request #1609 from strongloop/update-eslint-config
Upgrade eslint-config-loopback + fix formatting
This commit is contained in:
commit
3e5c805418
|
@ -109,8 +109,10 @@ Physician.create({name: 'Dr John'}, function(err, physician1) {
|
||||||
patient1.physicians.create({name: 'Dr X'}, function(err, patient4) {
|
patient1.physicians.create({name: 'Dr X'}, function(err, patient4) {
|
||||||
console.log('Physician 4: ', patient4, patient4.constructor.modelName);
|
console.log('Physician 4: ', patient4, patient4.constructor.modelName);
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
});
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -43,7 +43,8 @@ KeyValueMemoryConnector.prototype._setupRegularCleanup = function() {
|
||||||
clearInterval(timer);
|
clearInterval(timer);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
1000);
|
1000
|
||||||
|
);
|
||||||
this._cleanupTimer.unref();
|
this._cleanupTimer.unref();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
15
lib/dao.js
15
lib/dao.js
|
@ -135,14 +135,16 @@ function invokeConnectorMethod(connector, method, Model, args, options, cb) {
|
||||||
// If the DataSource is a transaction and no transaction object is provide in
|
// If the DataSource is a transaction and no transaction object is provide in
|
||||||
// the options yet, add it to the options, see: DataSource#transaction()
|
// the options yet, add it to the options, see: DataSource#transaction()
|
||||||
var opts = dataSource.isTransaction && !options.transaction ? Object.assign(
|
var opts = dataSource.isTransaction && !options.transaction ? Object.assign(
|
||||||
options, {transaction: dataSource.currentTransaction}) : options;
|
options, {transaction: dataSource.currentTransaction}
|
||||||
|
) : options;
|
||||||
var optionsSupported = connector[method].length >= args.length + 3;
|
var optionsSupported = connector[method].length >= args.length + 3;
|
||||||
var transaction = opts.transaction;
|
var transaction = opts.transaction;
|
||||||
if (transaction) {
|
if (transaction) {
|
||||||
if (!optionsSupported) {
|
if (!optionsSupported) {
|
||||||
return process.nextTick(function() {
|
return process.nextTick(function() {
|
||||||
cb(new Error(g.f(
|
cb(new Error(g.f(
|
||||||
'The connector does not support {{method}} within a transaction', method)));
|
'The connector does not support {{method}} within a transaction', method
|
||||||
|
)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// transaction isn't always a Transaction instance. Some tests provide a
|
// transaction isn't always a Transaction instance. Some tests provide a
|
||||||
|
@ -1749,7 +1751,8 @@ DataAccessObject._coerce = function(where, options) {
|
||||||
'The %s property has invalid clause %j: Expected precisely 2 values, received %d',
|
'The %s property has invalid clause %j: Expected precisely 2 values, received %d',
|
||||||
p,
|
p,
|
||||||
where[p],
|
where[p],
|
||||||
val.length));
|
val.length
|
||||||
|
));
|
||||||
err.statusCode = 400;
|
err.statusCode = 400;
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
@ -1762,7 +1765,8 @@ DataAccessObject._coerce = function(where, options) {
|
||||||
err = new Error(g.f(
|
err = new Error(g.f(
|
||||||
'The %s property has invalid clause %j: Expected a string or RegExp',
|
'The %s property has invalid clause %j: Expected a string or RegExp',
|
||||||
p,
|
p,
|
||||||
where[p]));
|
where[p]
|
||||||
|
));
|
||||||
err.statusCode = 400;
|
err.statusCode = 400;
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
@ -2998,7 +3002,8 @@ DataAccessObject.replaceById = function(id, data, options, cb) {
|
||||||
err = new Error(g.f(
|
err = new Error(g.f(
|
||||||
'The connector %s does not support {{replaceById}} operation. This is not a bug in LoopBack. ' +
|
'The connector %s does not support {{replaceById}} operation. This is not a bug in LoopBack. ' +
|
||||||
'Please contact the authors of the connector, preferably via GitHub issues.',
|
'Please contact the authors of the connector, preferably via GitHub issues.',
|
||||||
connector.name));
|
connector.name
|
||||||
|
));
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -413,7 +413,8 @@ DataSource.prototype.setup = function(dsName, settings) {
|
||||||
console.warn(
|
console.warn(
|
||||||
'A datasource is created with name %j, which is different from the name in settings (%j). ' +
|
'A datasource is created with name %j, which is different from the name in settings (%j). ' +
|
||||||
'Please adjust your configuration to ensure these names match.',
|
'Please adjust your configuration to ensure these names match.',
|
||||||
dsName, settings.name);
|
dsName, settings.name
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disconnected by default
|
// Disconnected by default
|
||||||
|
@ -2339,7 +2340,8 @@ DataSource.prototype.transaction = function(execute, options, cb) {
|
||||||
if (!transaction) {
|
if (!transaction) {
|
||||||
process.nextTick(function() {
|
process.nextTick(function() {
|
||||||
cb(new Error(g.f(
|
cb(new Error(g.f(
|
||||||
'Transaction is not ready, wait for the returned promise to resolve')));
|
'Transaction is not ready, wait for the returned promise to resolve'
|
||||||
|
)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return transaction;
|
return transaction;
|
||||||
|
|
|
@ -114,8 +114,8 @@ function preventFkOverride(inst, data, fkProp) {
|
||||||
'Cannot override foreign key %s from %s to %s',
|
'Cannot override foreign key %s from %s to %s',
|
||||||
fkProp,
|
fkProp,
|
||||||
inst[fkProp],
|
inst[fkProp],
|
||||||
data[fkProp])
|
data[fkProp]
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -1825,7 +1825,8 @@ HasOne.prototype.create = function(targetModelData, options, cb) {
|
||||||
} else {
|
} else {
|
||||||
cb && cb(new Error(g.f(
|
cb && cb(new Error(g.f(
|
||||||
'{{HasOne}} relation cannot create more than one instance of %s',
|
'{{HasOne}} relation cannot create more than one instance of %s',
|
||||||
modelTo.modelName)));
|
modelTo.modelName
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return cb.promise;
|
return cb.promise;
|
||||||
|
|
|
@ -149,8 +149,7 @@ if (Transaction) {
|
||||||
// The connection should have been released back the pool
|
// The connection should have been released back the pool
|
||||||
this.connection = null;
|
this.connection = null;
|
||||||
cb(err);
|
cb(err);
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return cb.promise;
|
return cb.promise;
|
||||||
};
|
};
|
||||||
|
@ -189,8 +188,7 @@ if (Transaction) {
|
||||||
// The connection should have been released back the pool
|
// The connection should have been released back the pool
|
||||||
this.connection = null;
|
this.connection = null;
|
||||||
cb(err);
|
cb(err);
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return cb.promise;
|
return cb.promise;
|
||||||
};
|
};
|
||||||
|
|
|
@ -571,7 +571,8 @@ function uniq(a) {
|
||||||
}
|
}
|
||||||
assert(Array.isArray(a), 'array argument is required');
|
assert(Array.isArray(a), 'array argument is required');
|
||||||
var comparableA = a.map(
|
var comparableA = a.map(
|
||||||
item => item.hasOwnProperty('_bsontype') ? item.toString() : item);
|
item => item.hasOwnProperty('_bsontype') ? item.toString() : item
|
||||||
|
);
|
||||||
for (var i = 0, n = comparableA.length; i < n; i++) {
|
for (var i = 0, n = comparableA.length; i < n; i++) {
|
||||||
if (comparableA.indexOf(comparableA[i]) === i) {
|
if (comparableA.indexOf(comparableA[i]) === i) {
|
||||||
uniqArray.push(a[i]);
|
uniqArray.push(a[i]);
|
||||||
|
|
|
@ -38,8 +38,8 @@
|
||||||
"async-iterators": "^0.2.2",
|
"async-iterators": "^0.2.2",
|
||||||
"bson": "^1.0.4",
|
"bson": "^1.0.4",
|
||||||
"coveralls": "^3.0.1",
|
"coveralls": "^3.0.1",
|
||||||
"eslint": "^4.19.1",
|
"eslint": "^5.1.0",
|
||||||
"eslint-config-loopback": "^10.0.0",
|
"eslint-config-loopback": "^11.0.0",
|
||||||
"loopback-connector-throwing": "file:./test/fixtures/loopback-connector-throwing",
|
"loopback-connector-throwing": "file:./test/fixtures/loopback-connector-throwing",
|
||||||
"mocha": "^5.2.0",
|
"mocha": "^5.2.0",
|
||||||
"nyc": "^12.0.2",
|
"nyc": "^12.0.2",
|
||||||
|
|
|
@ -51,13 +51,15 @@ var operations = [
|
||||||
function findOrCreate_found(ds) {
|
function findOrCreate_found(ds) {
|
||||||
return ds.TestModel.findOrCreate(
|
return ds.TestModel.findOrCreate(
|
||||||
{where: {name: ds.existingInstance.name}},
|
{where: {name: ds.existingInstance.name}},
|
||||||
{name: ds.existingInstance.name});
|
{name: ds.existingInstance.name}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
function findOrCreate_create(ds) {
|
function findOrCreate_create(ds) {
|
||||||
return ds.TestModel.findOrCreate(
|
return ds.TestModel.findOrCreate(
|
||||||
{where: {name: 'new-record'}},
|
{where: {name: 'new-record'}},
|
||||||
{name: 'new-record'});
|
{name: 'new-record'}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
function updateOrCreate_create(ds) {
|
function updateOrCreate_create(ds) {
|
||||||
|
@ -66,7 +68,8 @@ var operations = [
|
||||||
|
|
||||||
function updateOrCreate_update(ds) {
|
function updateOrCreate_update(ds) {
|
||||||
return ds.TestModel.updateOrCreate(
|
return ds.TestModel.updateOrCreate(
|
||||||
{id: ds.existingInstance.id, name: 'new name'});
|
{id: ds.existingInstance.id, name: 'new name'}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
function replaceOrCreate_create(ds) {
|
function replaceOrCreate_create(ds) {
|
||||||
|
@ -75,13 +78,15 @@ var operations = [
|
||||||
|
|
||||||
function replaceOrCreate_update(ds) {
|
function replaceOrCreate_update(ds) {
|
||||||
return ds.TestModel.replaceOrCreate(
|
return ds.TestModel.replaceOrCreate(
|
||||||
{id: ds.existingInstance.id, name: 'new name'});
|
{id: ds.existingInstance.id, name: 'new name'}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
function replaceById(ds) {
|
function replaceById(ds) {
|
||||||
return ds.TestModel.replaceById(
|
return ds.TestModel.replaceById(
|
||||||
ds.existingInstance.id,
|
ds.existingInstance.id,
|
||||||
{name: 'new name'});
|
{name: 'new name'}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
function updateAll(ds) {
|
function updateAll(ds) {
|
||||||
|
|
|
@ -322,7 +322,8 @@ describe('async observer', function() {
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
err.should.eql(testError);
|
err.should.eql(testError);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -126,9 +126,11 @@ describe('basic-querying', function() {
|
||||||
return u.name;
|
return u.name;
|
||||||
});
|
});
|
||||||
names.should.eql(
|
names.should.eql(
|
||||||
[createdUsers[2].name, createdUsers[1].name, createdUsers[0].name]);
|
[createdUsers[2].name, createdUsers[1].name, createdUsers[0].name]
|
||||||
|
);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should query by ids and condition', function(done) {
|
it('should query by ids and condition', function(done) {
|
||||||
|
|
|
@ -89,7 +89,8 @@ describe('crud-with-options', function() {
|
||||||
function(done) {
|
function(done) {
|
||||||
User.findById(undefined, {}, function(err, u) {
|
User.findById(undefined, {}, function(err, u) {
|
||||||
err.should.be.eql(
|
err.should.be.eql(
|
||||||
new Error('Model::findById requires the id argument'));
|
new Error('Model::findById requires the id argument')
|
||||||
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -194,7 +194,8 @@ describe('datatypes', function() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
persistUndefinedAsNull: true,
|
persistUndefinedAsNull: true,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
isStrict = TestModel.definition.settings.strict;
|
isStrict = TestModel.definition.settings.strict;
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,8 @@ describe('Memory connector with mocked discovery', function() {
|
||||||
var s = schemas['STRONGLOOP.INVENTORY'];
|
var s = schemas['STRONGLOOP.INVENTORY'];
|
||||||
s.name.should.be.eql('Inventory');
|
s.name.should.be.eql('Inventory');
|
||||||
Object.keys(s.properties).should.be.eql(
|
Object.keys(s.properties).should.be.eql(
|
||||||
['productId', 'locationId', 'available', 'total']);
|
['productId', 'locationId', 'available', 'total']
|
||||||
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -97,7 +98,8 @@ describe('Memory connector with mocked discovery', function() {
|
||||||
var s = schemas['STRONGLOOP.INVENTORY'];
|
var s = schemas['STRONGLOOP.INVENTORY'];
|
||||||
s.name.should.be.eql('inventory');
|
s.name.should.be.eql('inventory');
|
||||||
Object.keys(s.properties).should.be.eql(
|
Object.keys(s.properties).should.be.eql(
|
||||||
['product_id', 'location_id', 'available', 'total']);
|
['product_id', 'location_id', 'available', 'total']
|
||||||
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -110,7 +112,8 @@ describe('Memory connector with mocked discovery', function() {
|
||||||
var s = schemas['STRONGLOOP.INVENTORY'];
|
var s = schemas['STRONGLOOP.INVENTORY'];
|
||||||
s.name.should.be.eql('INVENTORY');
|
s.name.should.be.eql('INVENTORY');
|
||||||
Object.keys(s.properties).should.be.eql(
|
Object.keys(s.properties).should.be.eql(
|
||||||
['PRODUCT_ID', 'LOCATION_ID', 'AVAILABLE', 'TOTAL']);
|
['PRODUCT_ID', 'LOCATION_ID', 'AVAILABLE', 'TOTAL']
|
||||||
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -411,7 +411,8 @@ describe('hooks', function() {
|
||||||
it('should describe isValid sequence', function(done) {
|
it('should describe isValid sequence', function(done) {
|
||||||
should.not.exist(
|
should.not.exist(
|
||||||
user.constructor._validations,
|
user.constructor._validations,
|
||||||
'Expected user to have no validations, but she have');
|
'Expected user to have no validations, but she have'
|
||||||
|
);
|
||||||
user.isValid(function(valid) {
|
user.isValid(function(valid) {
|
||||||
valid.should.be.true;
|
valid.should.be.true;
|
||||||
life.should.eql([
|
life.should.eql([
|
||||||
|
|
|
@ -1633,8 +1633,7 @@ describe('Model instance with included relation .toJSON()', function() {
|
||||||
foreignKey: '',
|
foreignKey: '',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
);
|
|
||||||
GameParticipationModel = db.createModel('GameParticipation',
|
GameParticipationModel = db.createModel('GameParticipation',
|
||||||
{
|
{
|
||||||
date: Date,
|
date: Date,
|
||||||
|
@ -1652,8 +1651,7 @@ describe('Model instance with included relation .toJSON()', function() {
|
||||||
foreignKey: '',
|
foreignKey: '',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
);
|
|
||||||
ResultModel = db.createModel('Result', {
|
ResultModel = db.createModel('Result', {
|
||||||
points: Number,
|
points: Number,
|
||||||
}, {
|
}, {
|
||||||
|
|
|
@ -49,7 +49,8 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
function(err) {
|
function(err) {
|
||||||
err.message.should.match(/expired-key/);
|
err.message.should.match(/expired-key/);
|
||||||
err.should.have.property('statusCode', 404);
|
err.should.have.property('statusCode', 404);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns error when key does not exist', function() {
|
it('returns error when key does not exist', function() {
|
||||||
|
@ -58,7 +59,8 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
function(err) {
|
function(err) {
|
||||||
err.message.should.match(/key-does-not-exist/);
|
err.message.should.match(/key-does-not-exist/);
|
||||||
err.should.have.property('statusCode', 404);
|
err.should.have.property('statusCode', 404);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
function setupCacheItem() {
|
function setupCacheItem() {
|
||||||
|
|
|
@ -26,7 +26,8 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
it('gets TTL when key with unexpired TTL exists - Promise API',
|
it('gets TTL when key with unexpired TTL exists - Promise API',
|
||||||
function() {
|
function() {
|
||||||
return Promise.resolve(
|
return Promise.resolve(
|
||||||
CacheItem.set('a-key', 'a-value', {ttl: INITIAL_TTL}))
|
CacheItem.set('a-key', 'a-value', {ttl: INITIAL_TTL})
|
||||||
|
)
|
||||||
.delay(SMALL_DELAY)
|
.delay(SMALL_DELAY)
|
||||||
.then(function() { return CacheItem.ttl('a-key'); })
|
.then(function() { return CacheItem.ttl('a-key'); })
|
||||||
.then(function(ttl) { ttl.should.be.within(1, INITIAL_TTL); });
|
.then(function(ttl) { ttl.should.be.within(1, INITIAL_TTL); });
|
||||||
|
@ -52,7 +53,8 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
|
|
||||||
it('fails when getting TTL for a key with expired TTL', function() {
|
it('fails when getting TTL for a key with expired TTL', function() {
|
||||||
return Promise.resolve(
|
return Promise.resolve(
|
||||||
CacheItem.set('expired-key', 'a-value', {ttl: TTL_PRECISION}))
|
CacheItem.set('expired-key', 'a-value', {ttl: TTL_PRECISION})
|
||||||
|
)
|
||||||
.delay(2 * TTL_PRECISION)
|
.delay(2 * TTL_PRECISION)
|
||||||
.then(function() {
|
.then(function() {
|
||||||
return CacheItem.ttl('expired-key');
|
return CacheItem.ttl('expired-key');
|
||||||
|
@ -62,7 +64,8 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
function(err) {
|
function(err) {
|
||||||
err.message.should.match(/expired-key/);
|
err.message.should.match(/expired-key/);
|
||||||
err.should.have.property('statusCode', 404);
|
err.should.have.property('statusCode', 404);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails when key does not exist', function() {
|
it('fails when key does not exist', function() {
|
||||||
|
@ -71,7 +74,8 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
function(err) {
|
function(err) {
|
||||||
err.message.should.match(/key-does-not-exist/);
|
err.message.should.match(/key-does-not-exist/);
|
||||||
err.should.have.property('statusCode', 404);
|
err.should.have.property('statusCode', 404);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
function setupCacheItem() {
|
function setupCacheItem() {
|
||||||
|
|
|
@ -741,9 +741,11 @@ describe('Model loaded with a base', function() {
|
||||||
Customer1.definition.properties.should.have.property('name');
|
Customer1.definition.properties.should.have.property('name');
|
||||||
Customer2.definition.properties.should.have.property('name');
|
Customer2.definition.properties.should.have.property('name');
|
||||||
Customer1.definition.properties.name.should.not.be.equal(
|
Customer1.definition.properties.name.should.not.be.equal(
|
||||||
Customer2.definition.properties.name);
|
Customer2.definition.properties.name
|
||||||
|
);
|
||||||
Customer1.definition.properties.name.should.eql(
|
Customer1.definition.properties.name.should.eql(
|
||||||
Customer2.definition.properties.name);
|
Customer2.definition.properties.name
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can remove properties from base model', function() {
|
it('can remove properties from base model', function() {
|
||||||
|
|
|
@ -351,7 +351,8 @@ describe('manipulation', function() {
|
||||||
should.equal(result.gender, null);
|
should.equal(result.gender, null);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
bdd.itIf(connectorCapabilities.refuseDuplicateInsert !== false, 'should refuse to create ' +
|
bdd.itIf(connectorCapabilities.refuseDuplicateInsert !== false, 'should refuse to create ' +
|
||||||
|
@ -914,8 +915,10 @@ describe('manipulation', function() {
|
||||||
should.equal(result.gender, null);
|
should.equal(result.gender, null);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
});
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('updates specific instances when PK is not an auto-generated id', function(done) {
|
it('updates specific instances when PK is not an auto-generated id', function(done) {
|
||||||
|
@ -961,7 +964,8 @@ describe('manipulation', function() {
|
||||||
function(err, inst) {
|
function(err, inst) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
inst.save(done);
|
inst.save(done);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1562,7 +1566,8 @@ describe('manipulation', function() {
|
||||||
p.gender.should.equal('male');
|
p.gender.should.equal('male');
|
||||||
created.should.equal(false);
|
created.should.equal(false);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create a record with if new (promise variant)', function(done) {
|
it('should create a record with if new (promise variant)', function(done) {
|
||||||
|
@ -1585,7 +1590,8 @@ describe('manipulation', function() {
|
||||||
it('should find a record if exists (promise variant)', function(done) {
|
it('should find a record if exists (promise variant)', function(done) {
|
||||||
Person.findOrCreate(
|
Person.findOrCreate(
|
||||||
{where: {name: 'Jed'}},
|
{where: {name: 'Jed'}},
|
||||||
{name: 'Jed', gender: 'male'})
|
{name: 'Jed', gender: 'male'}
|
||||||
|
)
|
||||||
.then(function(res) {
|
.then(function(res) {
|
||||||
res.should.be.instanceOf(Array);
|
res.should.be.instanceOf(Array);
|
||||||
res.should.have.lengthOf(2);
|
res.should.have.lengthOf(2);
|
||||||
|
@ -2371,7 +2377,8 @@ describe('manipulation', function() {
|
||||||
should.equal(result.city, null);
|
should.equal(result.city, null);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow save() of the created instance', function(done) {
|
it('should allow save() of the created instance', function(done) {
|
||||||
|
|
|
@ -235,8 +235,7 @@ describe('Model class inheritance', function() {
|
||||||
model: 'Order',
|
model: 'Order',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
assert.deepEqual(User.settings, {
|
assert.deepEqual(User.settings, {
|
||||||
// forceId is set to 'auto' in memory if idProp.generated && forceId !== false
|
// forceId is set to 'auto' in memory if idProp.generated && forceId !== false
|
||||||
|
|
|
@ -73,7 +73,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
function(err, result) {
|
function(err, result) {
|
||||||
if (err) reject(err);
|
if (err) reject(err);
|
||||||
else resolve(result);
|
else resolve(result);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
function(err, result) {
|
function(err, result) {
|
||||||
if (err) reject(err);
|
if (err) reject(err);
|
||||||
else resolve(result);
|
else resolve(result);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,8 @@ describe('optional-validation', function() {
|
||||||
ModelWithForceId = db.createModel(
|
ModelWithForceId = db.createModel(
|
||||||
'ModelWithForceId',
|
'ModelWithForceId',
|
||||||
{name: String},
|
{name: String},
|
||||||
{forceId: true});
|
{forceId: true}
|
||||||
|
);
|
||||||
User = db.define('User', {
|
User = db.define('User', {
|
||||||
seq: {type: Number, index: true},
|
seq: {type: Number, index: true},
|
||||||
name: {type: String, index: true, sort: true},
|
name: {type: String, index: true, sort: true},
|
||||||
|
|
|
@ -109,7 +109,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
'loaded',
|
'loaded',
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers the loaded hook multiple times when multiple instances exist', function(done) {
|
it('triggers the loaded hook multiple times when multiple instances exist', function(done) {
|
||||||
|
@ -136,7 +137,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
hookMonitor.names.should.be.empty();
|
hookMonitor.names.should.be.empty();
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers the loaded hook multiple times when multiple instances exist when near filter is used',
|
it('triggers the loaded hook multiple times when multiple instances exist when near filter is used',
|
||||||
|
@ -242,7 +244,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
hookMonitor.names.should.be.empty();
|
hookMonitor.names.should.be.empty();
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should apply updates from `access` hook', function(done) {
|
it('should apply updates from `access` hook', function(done) {
|
||||||
|
@ -340,7 +343,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
|
|
||||||
list[0].should.have.property('extra', 'hook data');
|
list[0].should.have.property('extra', 'hook data');
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('emits error when `loaded` hook fails', function(done) {
|
it('emits error when `loaded` hook fails', function(done) {
|
||||||
|
@ -350,7 +354,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
function(err, list) {
|
function(err, list) {
|
||||||
[err].should.eql([expectedError]);
|
[err].should.eql([expectedError]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -370,7 +375,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
'after save',
|
'after save',
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('aborts when `after save` fires when option to notify is false', function(done) {
|
it('aborts when `after save` fires when option to notify is false', function(done) {
|
||||||
|
@ -446,7 +452,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('validates model after `before save` hook', function(done) {
|
it('validates model after `before save` hook', function(done) {
|
||||||
|
@ -474,7 +481,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates from `persist` hook', function(done) {
|
it('applies updates from `persist` hook', function(done) {
|
||||||
|
@ -507,7 +515,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `loaded` hook', function(done) {
|
it('triggers `loaded` hook', function(done) {
|
||||||
|
@ -529,7 +538,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('emits error when `loaded` hook fails', function(done) {
|
it('emits error when `loaded` hook fails', function(done) {
|
||||||
|
@ -539,7 +549,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
function(err, instance) {
|
function(err, instance) {
|
||||||
[err].should.eql([expectedError]);
|
[err].should.eql([expectedError]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates from `loaded` hook', function(done) {
|
it('applies updates from `loaded` hook', function(done) {
|
||||||
|
@ -560,7 +571,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
|
|
||||||
instance.should.have.property('extra', 'hook data');
|
instance.should.have.property('extra', 'hook data');
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `after save` hook', function(done) {
|
it('triggers `after save` hook', function(done) {
|
||||||
|
@ -625,7 +637,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('emits `after save` when some models were not saved', function(done) {
|
it('emits `after save` when some models were not saved', function(done) {
|
||||||
|
@ -654,7 +667,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
isNewInstance: true,
|
isNewInstance: true,
|
||||||
}));
|
}));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -674,7 +688,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
skip: 0,
|
skip: 0,
|
||||||
}}));
|
}}));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (dataSource.connector.findOrCreate) {
|
if (dataSource.connector.findOrCreate) {
|
||||||
|
@ -696,7 +711,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
isNewInstance: true,
|
isNewInstance: true,
|
||||||
}));
|
}));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -717,7 +733,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
isNewInstance: true,
|
isNewInstance: true,
|
||||||
}));
|
}));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('validates model after `before save` hook', function(done) {
|
it('validates model after `before save` hook', function(done) {
|
||||||
|
@ -730,7 +747,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
(err || {}).should.be.instanceOf(ValidationError);
|
(err || {}).should.be.instanceOf(ValidationError);
|
||||||
(err.details.codes || {}).should.eql({name: ['presence']});
|
(err.details.codes || {}).should.eql({name: ['presence']});
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers hooks in the correct order when not found', function(done) {
|
it('triggers hooks in the correct order when not found', function(done) {
|
||||||
|
@ -749,7 +767,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
'after save',
|
'after save',
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers hooks in the correct order when found', function(done) {
|
it('triggers hooks in the correct order when found', function(done) {
|
||||||
|
@ -775,7 +794,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('aborts when `access` hook fails', function(done) {
|
it('aborts when `access` hook fails', function(done) {
|
||||||
|
@ -787,7 +807,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
function(err, instance) {
|
function(err, instance) {
|
||||||
[err].should.eql([expectedError]);
|
[err].should.eql([expectedError]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('aborts when `before save` hook fails', function(done) {
|
it('aborts when `before save` hook fails', function(done) {
|
||||||
|
@ -799,7 +820,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
function(err, instance) {
|
function(err, instance) {
|
||||||
[err].should.eql([expectedError]);
|
[err].should.eql([expectedError]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (dataSource.connector.findOrCreate) {
|
if (dataSource.connector.findOrCreate) {
|
||||||
|
@ -835,7 +857,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -875,7 +898,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (dataSource.connector.findOrCreate) {
|
if (dataSource.connector.findOrCreate) {
|
||||||
|
@ -909,7 +933,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
});
|
});
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -948,7 +973,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (dataSource.connector.findOrCreate) {
|
if (dataSource.connector.findOrCreate) {
|
||||||
|
@ -975,7 +1001,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -997,7 +1024,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('emits error when `loaded` hook fails', function(done) {
|
it('emits error when `loaded` hook fails', function(done) {
|
||||||
|
@ -1008,7 +1036,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
function(err, instance) {
|
function(err, instance) {
|
||||||
[err].should.eql([expectedError]);
|
[err].should.eql([expectedError]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (dataSource.connector.findOrCreate) {
|
if (dataSource.connector.findOrCreate) {
|
||||||
|
@ -1027,7 +1056,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
instance.should.have.property('extra', 'hook data');
|
instance.should.have.property('extra', 'hook data');
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1053,7 +1083,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
|
|
||||||
instance.should.have.property('extra', 'hook data');
|
instance.should.have.property('extra', 'hook data');
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `after save` hook when not found', function(done) {
|
it('triggers `after save` hook when not found', function(done) {
|
||||||
|
@ -1073,7 +1104,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
isNewInstance: true,
|
isNewInstance: true,
|
||||||
}));
|
}));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not trigger `after save` hook when found', function(done) {
|
it('does not trigger `after save` hook when found', function(done) {
|
||||||
|
@ -1086,7 +1118,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
ctxRecorder.records.should.eql('hook not called');
|
ctxRecorder.records.should.eql('hook not called');
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1131,7 +1164,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
'after save',
|
'after save',
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `before save` hook', function(done) {
|
it('triggers `before save` hook', function(done) {
|
||||||
|
@ -1249,7 +1283,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
function(err, instance) {
|
function(err, instance) {
|
||||||
[err].should.eql([expectedError]);
|
[err].should.eql([expectedError]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates from `loaded` hook', function(done) {
|
it('applies updates from `loaded` hook', function(done) {
|
||||||
|
@ -1292,7 +1327,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
// PersistedModel.create and force it to call connector.save()
|
// PersistedModel.create and force it to call connector.save()
|
||||||
var instance = new TestModel(
|
var instance = new TestModel(
|
||||||
{id: 'new-id', name: 'created'},
|
{id: 'new-id', name: 'created'},
|
||||||
{persisted: true});
|
{persisted: true}
|
||||||
|
);
|
||||||
|
|
||||||
instance.save(function(err, instance) {
|
instance.save(function(err, instance) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
@ -1348,7 +1384,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
'after save',
|
'after save',
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `before save` hook', function(done) {
|
it('triggers `before save` hook', function(done) {
|
||||||
|
@ -1508,7 +1545,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1544,7 +1582,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
function(err, instance) {
|
function(err, instance) {
|
||||||
[err].should.eql([expectedError]);
|
[err].should.eql([expectedError]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates from `loaded` hook updateAttributes', function(done) {
|
it('applies updates from `loaded` hook updateAttributes', function(done) {
|
||||||
|
@ -1625,7 +1664,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
'after save',
|
'after save',
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `before save` hook', function(done) {
|
it('triggers `before save` hook', function(done) {
|
||||||
|
@ -1768,7 +1808,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1796,7 +1837,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
function(err, instance) {
|
function(err, instance) {
|
||||||
[err].should.eql([expectedError]);
|
[err].should.eql([expectedError]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates from `loaded` hook replaceAttributes', function(done) {
|
it('applies updates from `loaded` hook replaceAttributes', function(done) {
|
||||||
|
@ -1871,7 +1913,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
'after save',
|
'after save',
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers hooks in the correct order on update', function(done) {
|
it('triggers hooks in the correct order on update', function(done) {
|
||||||
|
@ -1889,7 +1932,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
'after save',
|
'after save',
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `access` hook on create', function(done) {
|
it('triggers `access` hook on create', function(done) {
|
||||||
|
@ -1903,7 +1947,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
where: {id: 'not-found'},
|
where: {id: 'not-found'},
|
||||||
}}));
|
}}));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `access` hook on update', function(done) {
|
it('triggers `access` hook on update', function(done) {
|
||||||
|
@ -1917,7 +1962,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
where: {id: existingInstance.id},
|
where: {id: existingInstance.id},
|
||||||
}}));
|
}}));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not trigger `access` on missing id', function(done) {
|
it('does not trigger `access` on missing id', function(done) {
|
||||||
|
@ -1929,7 +1975,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
ctxRecorder.records.should.equal('hook not called');
|
ctxRecorder.records.should.equal('hook not called');
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates from `access` hook when found', function(done) {
|
it('applies updates from `access` hook when found', function(done) {
|
||||||
|
@ -1950,7 +1997,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates from `access` hook when not found', function(done) {
|
it('applies updates from `access` hook when not found', function(done) {
|
||||||
|
@ -1972,7 +2020,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers hooks only once', function(done) {
|
it('triggers hooks only once', function(done) {
|
||||||
|
@ -1989,7 +2038,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
hookMonitor.names.should.eql(['access', 'before save']);
|
hookMonitor.names.should.eql(['access', 'before save']);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `before save` hook on update', function(done) {
|
it('triggers `before save` hook on update', function(done) {
|
||||||
|
@ -2018,7 +2068,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `before save` hook on create', function(done) {
|
it('triggers `before save` hook on create', function(done) {
|
||||||
|
@ -2047,7 +2098,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
}
|
}
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates from `before save` hook on update', function(done) {
|
it('applies updates from `before save` hook on update', function(done) {
|
||||||
|
@ -2063,7 +2115,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
instance.name.should.equal('hooked');
|
instance.name.should.equal('hooked');
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates from `before save` hook on create', function(done) {
|
it('applies updates from `before save` hook on create', function(done) {
|
||||||
|
@ -2083,7 +2136,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
instance.name.should.equal('hooked');
|
instance.name.should.equal('hooked');
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// FIXME(bajtos) this fails with connector-specific updateOrCreate
|
// FIXME(bajtos) this fails with connector-specific updateOrCreate
|
||||||
|
@ -2097,7 +2151,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
(err || {}).should.be.instanceOf(ValidationError);
|
(err || {}).should.be.instanceOf(ValidationError);
|
||||||
(err.details.codes || {}).should.eql({name: ['presence']});
|
(err.details.codes || {}).should.eql({name: ['presence']});
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// FIXME(bajtos) this fails with connector-specific updateOrCreate
|
// FIXME(bajtos) this fails with connector-specific updateOrCreate
|
||||||
|
@ -2111,7 +2166,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
(err || {}).should.be.instanceOf(ValidationError);
|
(err || {}).should.be.instanceOf(ValidationError);
|
||||||
(err.details.codes || {}).should.eql({name: ['presence']});
|
(err.details.codes || {}).should.eql({name: ['presence']});
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `persist` hook on create', function(done) {
|
it('triggers `persist` hook on create', function(done) {
|
||||||
|
@ -2147,7 +2203,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `persist` hook on update', function(done) {
|
it('triggers `persist` hook on update', function(done) {
|
||||||
|
@ -2179,7 +2236,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
|
|
||||||
ctxRecorder.records.should.eql(expectedContext);
|
ctxRecorder.records.should.eql(expectedContext);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `loaded` hook on create', function(done) {
|
it('triggers `loaded` hook on create', function(done) {
|
||||||
|
@ -2205,7 +2263,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `loaded` hook on update', function(done) {
|
it('triggers `loaded` hook on update', function(done) {
|
||||||
|
@ -2223,7 +2282,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
isNewInstance: isNewInstanceFlag ? false : undefined,
|
isNewInstance: isNewInstanceFlag ? false : undefined,
|
||||||
}));
|
}));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('emits error when `loaded` hook fails', function(done) {
|
it('emits error when `loaded` hook fails', function(done) {
|
||||||
|
@ -2233,7 +2293,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
function(err, instance) {
|
function(err, instance) {
|
||||||
[err].should.eql([expectedError]);
|
[err].should.eql([expectedError]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `after save` hook on update', function(done) {
|
it('triggers `after save` hook on update', function(done) {
|
||||||
|
@ -2252,7 +2313,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
isNewInstance: isNewInstanceFlag ? false : undefined,
|
isNewInstance: isNewInstanceFlag ? false : undefined,
|
||||||
}));
|
}));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('aborts when `after save` fires on update or create when option to notify is false', function(done) {
|
it('aborts when `after save` fires on update or create when option to notify is false', function(done) {
|
||||||
|
@ -2282,7 +2344,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
isNewInstance: isNewInstanceFlag ? true : undefined,
|
isNewInstance: isNewInstanceFlag ? true : undefined,
|
||||||
}));
|
}));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2305,7 +2368,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
'after save',
|
'after save',
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers hooks in the correct order on replace', function(done) {
|
it('triggers hooks in the correct order on replace', function(done) {
|
||||||
|
@ -2323,7 +2387,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
'after save',
|
'after save',
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `access` hook on create', function(done) {
|
it('triggers `access` hook on create', function(done) {
|
||||||
|
@ -2337,7 +2402,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
where: {id: 'not-found'},
|
where: {id: 'not-found'},
|
||||||
}}));
|
}}));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `access` hook on replace', function(done) {
|
it('triggers `access` hook on replace', function(done) {
|
||||||
|
@ -2351,7 +2417,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
where: {id: existingInstance.id},
|
where: {id: existingInstance.id},
|
||||||
}}));
|
}}));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not trigger `access` on missing id', function(done) {
|
it('does not trigger `access` on missing id', function(done) {
|
||||||
|
@ -2363,7 +2430,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
ctxRecorder.records.should.equal('hook not called');
|
ctxRecorder.records.should.equal('hook not called');
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates from `access` hook when found', function(done) {
|
it('applies updates from `access` hook when found', function(done) {
|
||||||
|
@ -2384,7 +2452,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates from `access` hook when not found', function(done) {
|
it('applies updates from `access` hook when not found', function(done) {
|
||||||
|
@ -2406,7 +2475,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers hooks only once', function(done) {
|
it('triggers hooks only once', function(done) {
|
||||||
|
@ -2423,7 +2493,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
hookMonitor.names.should.eql(['access', 'before save']);
|
hookMonitor.names.should.eql(['access', 'before save']);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `before save` hookon create', function(done) {
|
it('triggers `before save` hookon create', function(done) {
|
||||||
|
@ -2465,7 +2536,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
ctxRecorder.records.should.eql(expectedContext);
|
ctxRecorder.records.should.eql(expectedContext);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `before save` hook on create', function(done) {
|
it('triggers `before save` hook on create', function(done) {
|
||||||
|
@ -2490,7 +2562,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
ctxRecorder.records.should.eql(expectedContext);
|
ctxRecorder.records.should.eql(expectedContext);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates from `before save` hook on create', function(done) {
|
it('applies updates from `before save` hook on create', function(done) {
|
||||||
|
@ -2505,7 +2578,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
instance.name.should.equal('hooked');
|
instance.name.should.equal('hooked');
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('validates model after `before save` hook on create', function(done) {
|
it('validates model after `before save` hook on create', function(done) {
|
||||||
|
@ -2517,7 +2591,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
(err || {}).should.be.instanceOf(ValidationError);
|
(err || {}).should.be.instanceOf(ValidationError);
|
||||||
(err.details.codes || {}).should.eql({name: ['presence']});
|
(err.details.codes || {}).should.eql({name: ['presence']});
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `persist` hook on create', function(done) {
|
it('triggers `persist` hook on create', function(done) {
|
||||||
|
@ -2550,7 +2625,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
}
|
}
|
||||||
ctxRecorder.records.should.eql(expectedContext);
|
ctxRecorder.records.should.eql(expectedContext);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `persist` hook on replace', function(done) {
|
it('triggers `persist` hook on replace', function(done) {
|
||||||
|
@ -2582,7 +2658,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
|
|
||||||
ctxRecorder.records.should.eql(expectedContext);
|
ctxRecorder.records.should.eql(expectedContext);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates from `persist` hook on create', function(done) {
|
it('applies updates from `persist` hook on create', function(done) {
|
||||||
|
@ -2608,7 +2685,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
found.should.have.property('extra', 'hook data');
|
found.should.have.property('extra', 'hook data');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates from `persist` hook on update', function(done) {
|
it('applies updates from `persist` hook on update', function(done) {
|
||||||
|
@ -2653,7 +2731,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
|
|
||||||
ctxRecorder.records.should.eql(aCtxForModel(TestModel, expected));
|
ctxRecorder.records.should.eql(aCtxForModel(TestModel, expected));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `loaded` hook on replace', function(done) {
|
it('triggers `loaded` hook on replace', function(done) {
|
||||||
|
@ -2677,7 +2756,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
|
|
||||||
ctxRecorder.records.should.eql(aCtxForModel(TestModel, expected));
|
ctxRecorder.records.should.eql(aCtxForModel(TestModel, expected));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('emits error when `loaded` hook fails', function(done) {
|
it('emits error when `loaded` hook fails', function(done) {
|
||||||
|
@ -2687,7 +2767,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
function(err, instance) {
|
function(err, instance) {
|
||||||
[err].should.eql([expectedError]);
|
[err].should.eql([expectedError]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `after save` hook on replace', function(done) {
|
it('triggers `after save` hook on replace', function(done) {
|
||||||
|
@ -2712,7 +2793,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
|
|
||||||
ctxRecorder.records.should.eql(aCtxForModel(TestModel, expected));
|
ctxRecorder.records.should.eql(aCtxForModel(TestModel, expected));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `after save` hook on create', function(done) {
|
it('triggers `after save` hook on create', function(done) {
|
||||||
|
@ -2736,7 +2818,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
|
|
||||||
ctxRecorder.records.should.eql(aCtxForModel(TestModel, expected));
|
ctxRecorder.records.should.eql(aCtxForModel(TestModel, expected));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2761,7 +2844,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
'after save',
|
'after save',
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `persist` hook', function(done) {
|
it('triggers `persist` hook', function(done) {
|
||||||
|
@ -2801,7 +2885,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
|
|
||||||
ctxRecorder.records.should.eql(expectedContext);
|
ctxRecorder.records.should.eql(expectedContext);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates from `persist` hook', function(done) {
|
it('applies updates from `persist` hook', function(done) {
|
||||||
|
@ -2822,7 +2907,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
found.should.have.property('extra', 'hook data');
|
found.should.have.property('extra', 'hook data');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -3020,7 +3106,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
TestModel.findById(existingInstance.id, function(err, inst) {
|
TestModel.findById(existingInstance.id, function(err, inst) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
(inst ? inst.toObject() : 'null').should.eql(
|
(inst ? inst.toObject() : 'null').should.eql(
|
||||||
existingInstance.toObject());
|
existingInstance.toObject()
|
||||||
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -3118,7 +3205,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
where: {name: 'searched'},
|
where: {name: 'searched'},
|
||||||
}}));
|
}}));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates from `access` hook', function(done) {
|
it('applies updates from `access` hook', function(done) {
|
||||||
|
@ -3140,7 +3228,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `before save` hook', function(done) {
|
it('triggers `before save` hook', function(done) {
|
||||||
|
@ -3156,7 +3245,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
data: {name: 'updated'},
|
data: {name: 'updated'},
|
||||||
}));
|
}));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates from `before save` hook', function(done) {
|
it('applies updates from `before save` hook', function(done) {
|
||||||
|
@ -3176,7 +3266,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
instance.should.have.property('extra', 'added');
|
instance.should.have.property('extra', 'added');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `persist` hook', function(done) {
|
it('triggers `persist` hook', function(done) {
|
||||||
|
@ -3194,7 +3285,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates from `persist` hook', function(done) {
|
it('applies updates from `persist` hook', function(done) {
|
||||||
|
@ -3212,7 +3304,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
instance.should.have.property('extra', 'hook data');
|
instance.should.have.property('extra', 'hook data');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not trigger `loaded`', function(done) {
|
it('does not trigger `loaded`', function(done) {
|
||||||
|
@ -3225,7 +3318,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
ctxRecorder.records.should.eql('hook not called');
|
ctxRecorder.records.should.eql('hook not called');
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers `after save` hook', function(done) {
|
it('triggers `after save` hook', function(done) {
|
||||||
|
@ -3242,7 +3336,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
info: {count: 1},
|
info: {count: 1},
|
||||||
}));
|
}));
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('accepts hookState from options', function(done) {
|
it('accepts hookState from options', function(done) {
|
||||||
|
@ -3258,7 +3353,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
foo: 'bar',
|
foo: 'bar',
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -2612,7 +2612,8 @@ describe('relations', function() {
|
||||||
const actual = pics.map(
|
const actual = pics.map(
|
||||||
function(pic) {
|
function(pic) {
|
||||||
return {imageName: pic.name, name: pic.imageable().name};
|
return {imageName: pic.name, name: pic.imageable().name};
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
actual.should.containDeep([
|
actual.should.containDeep([
|
||||||
{name: 'Article 1', imageName: 'Article Pic'},
|
{name: 'Article 1', imageName: 'Article Pic'},
|
||||||
|
@ -4357,8 +4358,7 @@ describe('relations', function() {
|
||||||
Person = db.define('Person', {name: String});
|
Person = db.define('Person', {name: String});
|
||||||
Passport = tmp.define('Passport',
|
Passport = tmp.define('Passport',
|
||||||
{name: {type: 'string', required: true}},
|
{name: {type: 'string', required: true}},
|
||||||
{idInjection: false}
|
{idInjection: false});
|
||||||
);
|
|
||||||
Address = tmp.define('Address', {street: String}, {idInjection: false});
|
Address = tmp.define('Address', {street: String}, {idInjection: false});
|
||||||
Other = db.define('Other', {name: String});
|
Other = db.define('Other', {name: String});
|
||||||
Person.embedsOne(Passport, {
|
Person.embedsOne(Passport, {
|
||||||
|
@ -4707,8 +4707,7 @@ describe('relations', function() {
|
||||||
db = getMemoryDataSource();
|
db = getMemoryDataSource();
|
||||||
Person = db.define('Person', {name: String});
|
Person = db.define('Person', {name: String});
|
||||||
Passport = db.define('Passport',
|
Passport = db.define('Passport',
|
||||||
{name: {type: 'string', required: true}}
|
{name: {type: 'string', required: true}});
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can be declared using embedsOne method', function(done) {
|
it('can be declared using embedsOne method', function(done) {
|
||||||
|
@ -4761,8 +4760,7 @@ describe('relations', function() {
|
||||||
{
|
{
|
||||||
id: {type: 'string', id: true, generated: true},
|
id: {type: 'string', id: true, generated: true},
|
||||||
name: {type: 'string', required: true},
|
name: {type: 'string', required: true},
|
||||||
}
|
});
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can be declared using embedsOne method', function(done) {
|
it('can be declared using embedsOne method', function(done) {
|
||||||
|
@ -6163,7 +6161,8 @@ describe('relations', function() {
|
||||||
err.name.should.equal('ValidationError');
|
err.name.should.equal('ValidationError');
|
||||||
err.details.codes.jobs.should.eql(['uniqueness']);
|
err.details.codes.jobs.should.eql(['uniqueness']);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
bdd.itIf(connectorCapabilities.adhocSort !== false,
|
bdd.itIf(connectorCapabilities.adhocSort !== false,
|
||||||
|
@ -6550,7 +6549,8 @@ describe('relations', function() {
|
||||||
type: 'hasMany',
|
type: 'hasMany',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
}
|
||||||
|
);
|
||||||
}).should.throw('Invalid relation name: trigger');
|
}).should.throw('Invalid relation name: trigger');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -54,6 +54,7 @@ exports.init = function init(external_exports) {
|
||||||
function check_external_exports() {
|
function check_external_exports() {
|
||||||
if (!EXT_EXP) throw new Error(
|
if (!EXT_EXP) throw new Error(
|
||||||
'Before run this, please ensure that ' +
|
'Before run this, please ensure that ' +
|
||||||
'require("spec_helper").init(exports); called');
|
'require("spec_helper").init(exports); called'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -347,7 +347,8 @@ describe('validations', function() {
|
||||||
if (options.testFlag !== 'someValue') {
|
if (options.testFlag !== 'someValue') {
|
||||||
console.error(
|
console.error(
|
||||||
'Unexpected validation options: %j Expected %j',
|
'Unexpected validation options: %j Expected %j',
|
||||||
options, {testFlag: 'someValue'});
|
options, {testFlag: 'someValue'}
|
||||||
|
);
|
||||||
err();
|
err();
|
||||||
}
|
}
|
||||||
process.nextTick(function() { done(); });
|
process.nextTick(function() { done(); });
|
||||||
|
@ -607,12 +608,14 @@ describe('validations', function() {
|
||||||
function createSite1User(next) {
|
function createSite1User(next) {
|
||||||
SiteUser.create(
|
SiteUser.create(
|
||||||
{siteId: 1, email: EMAIL},
|
{siteId: 1, email: EMAIL},
|
||||||
next);
|
next
|
||||||
|
);
|
||||||
},
|
},
|
||||||
function createSite2User(user1, next) {
|
function createSite2User(user1, next) {
|
||||||
SiteUser.create(
|
SiteUser.create(
|
||||||
{siteId: 2, email: EMAIL},
|
{siteId: 2, email: EMAIL},
|
||||||
next);
|
next
|
||||||
|
);
|
||||||
},
|
},
|
||||||
function validateDuplicateUser(user2, next) {
|
function validateDuplicateUser(user2, next) {
|
||||||
var user3 = new SiteUser({siteId: 1, email: EMAIL});
|
var user3 = new SiteUser({siteId: 1, email: EMAIL});
|
||||||
|
@ -1420,7 +1423,8 @@ describe('validations', function() {
|
||||||
obj.email = 'test@example.com';
|
obj.email = 'test@example.com';
|
||||||
var err = givenValidationError('user', obj, 'is invalid');
|
var err = givenValidationError('user', obj, 'is invalid');
|
||||||
getErrorDetails(err).should.equal(
|
getErrorDetails(err).should.equal(
|
||||||
'`user` is invalid (value: { email: \'test@example.com\' }).');
|
'`user` is invalid (value: { email: \'test@example.com\' }).'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
function givenValidationError(propertyName, propertyValue, errorMessage) {
|
function givenValidationError(propertyName, propertyValue, errorMessage) {
|
||||||
|
|
Loading…
Reference in New Issue