Update eslint infrastructure

This commit is contained in:
Loay 2016-08-10 14:41:03 -04:00
parent 4368b6e1e1
commit 9c9b61e7dc
21 changed files with 561 additions and 605 deletions

13
.eslintrc Normal file
View File

@ -0,0 +1,13 @@
{
"extends": "loopback",
"rules": {
"max-len": ["error", 120, 4, {
"ignoreComments": true,
"ignoreUrls": true,
"ignorePattern": "^\\s*var\\s.=\\s*(require\\s*\\()|(/)"
}],
"camelcase": 0,
"one-var": "off",
"no-unused-expressions": "off"
}
}

View File

@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
var DataSource = require('loopback-datasource-juggler').DataSource;
var config = require('rc')('loopback', {dev: {mysql: {}}}).dev.mysql;
@ -34,12 +35,7 @@ ds.discoverForeignKeys('inventory', show);
ds.discoverExportedForeignKeys('location', show);
ds.discoverAndBuildModels('weapon', {owner: 'strongloop', visited: {}, associations: true}, function(err, models) {
for (var m in models) {
models[m].all(show);
}
});

View File

@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
var SG = require('strong-globalize');
SG.SetRootDir(__dirname);

View File

@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
var g = require('strong-globalize')();
module.exports = mixinDiscovery;
@ -88,7 +89,6 @@ function mixinDiscovery(MySQL, mysql) {
function queryViews(options) {
var sqlViews = null;
if (options.views) {
var schema = options.owner || options.schema;
if (options.all && !schema) {
@ -183,7 +183,7 @@ function mixinDiscovery(MySQL, mysql) {
schema: options.owner || options.schema,
table: table,
options: options,
cb: cb
cb: cb,
};
}
@ -452,7 +452,7 @@ function mixinDiscovery(MySQL, mysql) {
default:
return 'String';
}
}
};
MySQL.prototype.getDefaultSchema = function() {
if (this.dataSource && this.dataSource.settings &&

View File

@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
var g = require('strong-globalize')();
var EnumFactory = function() {
@ -11,7 +12,7 @@ var EnumFactory = function() {
if (typeof arg === 'number' && arg % 1 == 0) {
return Enum._values[arg];
} else if (Enum[arg]) {
return Enum[arg]
return Enum[arg];
} else if (Enum._values.indexOf(arg) !== -1) {
return arg;
} else if (arg === null) {
@ -30,7 +31,7 @@ var EnumFactory = function() {
configurable: false,
enumerable: true,
value: arg,
writable: false
writable: false,
});
dxList.push(arg);
}
@ -38,18 +39,18 @@ var EnumFactory = function() {
configurable: false,
enumerable: false,
value: dxList,
writable: false
writable: false,
});
Object.defineProperty(Enum, '_string', {
configurable: false,
enumerable: false,
value: stringified(Enum),
writable: false
writable: false,
});
Object.freeze(Enum);
return Enum;
} else {
throw g.f("No arguments - could not create {{Enum}}.");
throw g.f('No arguments - could not create {{Enum}}.');
}
};
@ -64,10 +65,3 @@ function stringified(anEnum) {
}
exports.EnumFactory = EnumFactory;

View File

@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
var g = require('strong-globalize')();
var async = require('async');
module.exports = mixinMigration;
@ -49,7 +50,6 @@ function mixinMigration(MySQL, mysql) {
});
});
}, cb);
};
/*!
@ -130,7 +130,7 @@ function mixinMigration(MySQL, mysql) {
if (!ai[name]) {
ai[name] = {
info: i,
columns: []
columns: [],
};
}
ai[name].columns[i.Seq_in_index - 1] = i.Column_name;
@ -216,7 +216,7 @@ function mixinMigration(MySQL, mysql) {
' (' + pName + ') ' + type);
} else {
if (typeof i === 'object' && i.unique && i.unique === true) {
kind = "UNIQUE";
kind = 'UNIQUE';
}
sql.push('ADD ' + kind + ' INDEX ' + pName + ' ' + type +
' (' + pName + ') ');
@ -350,7 +350,7 @@ function mixinMigration(MySQL, mysql) {
return (kind + ' INDEX ' + columnName + ' (' + columnName + ') ' + type);
} else {
if (typeof i === 'object' && i.unique && i.unique === true) {
kind = "UNIQUE";
kind = 'UNIQUE';
}
return (kind + ' INDEX ' + columnName + ' ' + type + ' (' + columnName + ') ');
}
@ -496,10 +496,10 @@ function mixinMigration(MySQL, mysql) {
function stringOptions(p, columnType) {
if (p.charset) {
columnType += " CHARACTER SET " + p.charset;
columnType += ' CHARACTER SET ' + p.charset;
}
if (p.collation) {
columnType += " COLLATE " + p.collation;
columnType += ' COLLATE ' + p.collation;
}
return columnType;
}

View File

@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
var g = require('strong-globalize')();
/*!
@ -100,7 +101,7 @@ MySQL.prototype.connect = function(callback) {
callback && callback(err, conn);
});
}
}
};
function generateOptions(settings) {
var s = settings || {};
@ -133,7 +134,7 @@ function generateOptions (settings) {
socketPath: s.socketPath,
charset: s.collation.toUpperCase(), // Correct by docs despite seeming odd.
supportBigNumbers: s.supportBigNumbers,
connectionLimit: s.connectionLimit
connectionLimit: s.connectionLimit,
};
// Don't configure the DB if the pool can be used for multiple DBs
@ -363,7 +364,7 @@ MySQL.prototype.toColumnValue = function(prop, val) {
if (prop.type.name === 'GeoPoint') {
return new ParameterizedSQL({
sql: 'Point(?,?)',
params: [val.lat, val.lng]
params: [val.lat, val.lng],
});
}
if (prop.type === Object) {
@ -416,7 +417,7 @@ MySQL.prototype.fromColumnValue = function(prop, val) {
case 'Point':
val = {
lat: val.x,
lng: val.y
lng: val.y,
};
break;
case 'List':
@ -465,7 +466,7 @@ MySQL.prototype._buildLimit = function(model, limit, offset) {
return '';
}
return 'LIMIT ' + (offset ? (offset + ',' + limit) : limit);
}
};
MySQL.prototype.applyPagination = function(model, stmt, filter) {
var limitClause = this._buildLimit(model, filter.limit,

View File

@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
var debug = require('debug')('loopback:connector:mysql:transaction');
module.exports = mixinTransaction;
@ -11,7 +12,6 @@ module.exports = mixinTransaction;
* @param {Object} mysql mysql driver
*/
function mixinTransaction(MySQL, mysql) {
/**
* Begin a new transaction
* @param isolationLevel

View File

@ -5,7 +5,9 @@
"main": "index.js",
"scripts": {
"pretest": "node pretest.js",
"test": "mocha"
"lint": "eslint .",
"test": "mocha --timeout 10000 test/*.js",
"posttest": "npm run lint"
},
"dependencies": {
"async": "^0.9.0",
@ -16,6 +18,8 @@
},
"devDependencies": {
"bluebird": "~2.9.10",
"eslint": "^2.13.1",
"eslint-config-loopback": "^4.0.0",
"loopback-datasource-juggler": "^2.28.0",
"mocha": "^2.1.0",
"rc": "^1.0.0",

View File

@ -1,3 +1,4 @@
'use strict';
// TODO: used for testing support for parallel testing on ci.strongloop.com which
// provides MYSQL_* env vars instead of TEST_MYSQL_* env vars.
process.env.TEST_MYSQL_USER = process.env.TEST_MYSQL_USER || process.env.MYSQL_USER;

View File

@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
require('./init.js');
var assert = require('assert');
var should = require('should');
@ -13,7 +14,6 @@ var url = require('url');
var db, DummyModel, odb, config;
describe('connections', function() {
before(function() {
require('./init.js');
@ -44,13 +44,11 @@ describe('connections', function () {
});
it('should use utf8 charset', function(done) {
var test_set = /utf8/;
var test_collo = /utf8_general_ci/;
var test_set_str = 'utf8';
var test_set_collo = 'utf8_general_ci';
charsetTest(test_set, test_collo, test_set_str, test_set_collo, done);
});
it('should disconnect first db', function(done) {
@ -61,13 +59,11 @@ describe('connections', function () {
});
it('should use latin1 charset', function(done) {
var test_set = /latin1/;
var test_collo = /latin1_general_ci/;
var test_set_str = 'latin1';
var test_set_collo = 'latin1_general_ci';
charsetTest(test_set, test_collo, test_set_str, test_set_collo, done);
});
it('should drop db and disconnect all', function(done) {
@ -113,11 +109,9 @@ describe('connections', function () {
});
function charsetTest(test_set, test_collo, test_set_str, test_set_collo, done) {
query('DROP DATABASE IF EXISTS ' + odb.settings.database, function(err) {
assert.ok(!err);
odb.disconnect(function() {
db = getDataSource({collation: test_set_collo, createDatabase: true});
DummyModel = db.define('DummyModel', {string: String});
db.automigrate(function() {
@ -152,7 +146,6 @@ function charsetTest(test_set, test_collo, test_set_str, test_set_collo, done) {
});
});
});
}
function matchResult(result, variable_name, match) {
@ -173,7 +166,7 @@ function generateURL(config) {
auth: config.username || '',
hostname: config.host,
pathname: config.database,
slashes: true
slashes: true,
};
if (config.password) {
urlObj.auth += ':' + config.password;
@ -181,8 +174,3 @@ function generateURL(config) {
var formatedUrl = url.format(urlObj);
return formatedUrl;
}

View File

@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
require('./init.js');
var assert = require('assert');
@ -10,7 +11,6 @@ var db, EnumModel, ANIMAL_ENUM;
var mysqlVersion;
describe('MySQL specific datatypes', function() {
before(setup);
it('should run migration', function(done) {
@ -80,13 +80,11 @@ describe('MySQL specific datatypes', function () {
it('should disconnect when done', function(done) {
db.disconnect();
done()
done();
});
});
function setup(done) {
require('./init.js');
db = getSchema();
@ -98,7 +96,7 @@ function setup(done) {
condition: {type: db.EnumFactory('hungry', 'sleepy', 'thirsty')},
mood: {type: db.EnumFactory('angry', 'happy', 'sad')},
note: Object,
extras: 'JSON'
extras: 'JSON',
});
query('SELECT VERSION()', function(err, res) {
@ -129,7 +127,7 @@ var blankDatabase = function (db, cb) {
});
};
getFields = function (model, cb) {
var getFields = function(model, cb) {
query('SHOW FIELDS FROM ' + model, function(err, res) {
if (err) {
cb(err);
@ -141,9 +139,9 @@ getFields = function (model, cb) {
cb(err, fields);
}
});
}
};
getIndexes = function (model, cb) {
var getIndexes = function(model, cb) {
query('SHOW INDEXES FROM ' + model, function(err, res) {
if (err) {
console.log(err);
@ -153,16 +151,10 @@ getIndexes = function (model, cb) {
// Note: this will only show the first key of compound keys
res.forEach(function(index) {
if (parseInt(index.Seq_in_index, 10) == 1) {
indexes[index.Key_name] = index
indexes[index.Key_name] = index;
}
});
cb(err, indexes);
}
});
};

View File

@ -3,13 +3,12 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
describe('mysql imported features', function() {
before(function() {
require('./init.js');
});
require('loopback-datasource-juggler/test/common.batch.js');
require('loopback-datasource-juggler/test/include.test.js');
});

View File

@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
// TODO: used for testing support for parallel testing on ci.strongloop.com which
// provides MYSQL_* env vars instead of TEST_MYSQL_* env vars.
process.env.TEST_MYSQL_USER = process.env.TEST_MYSQL_USER || process.env.MYSQL_USER;
@ -15,16 +16,15 @@ module.exports = require('should');
var DataSource = require('loopback-datasource-juggler').DataSource;
var config = require('rc')('loopback', {test: {mysql: {}}}).test.mysql;
console.log(config)
console.log(config);
global.getConfig = function(options) {
var dbConf = {
host: process.env.TEST_MYSQL_HOST || config.host || 'localhost',
port: process.env.TEST_MYSQL_PORT || config.port || 3306,
database: 'myapp_test',
username: process.env.TEST_MYSQL_USER || config.username,
password: process.env.TEST_MYSQL_PASSWORD || config.password,
createDatabase: true
createDatabase: true,
};
if (options) {

View File

@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
var should = require('./init.js');
var assert = require('assert');
var Schema = require('loopback-datasource-juggler').Schema;
@ -11,7 +12,6 @@ var db, UserData, StringData, NumberData, DateData;
var mysqlVersion;
describe('migrations', function() {
before(setup);
it('should run migration', function(done) {
@ -71,7 +71,7 @@ describe('migrations', function () {
Null: 'YES',
Key: '',
Default: null,
Extra: '' }
Extra: ''},
});
done();
});
@ -129,7 +129,7 @@ describe('migrations', function () {
Packed: null,
Null: '',
Index_type: 'BTREE',
Comment: '' }
Comment: ''},
});
done();
});
@ -138,7 +138,7 @@ describe('migrations', function () {
it('StringData should have correct columns', function(done) {
getFields('StringData', function(err, fields) {
fields.should.be.eql({
idString: { Field: "idString",
idString: {Field: 'idString',
Type: 'varchar(255)',
Null: 'NO',
Key: 'PRI',
@ -173,7 +173,7 @@ describe('migrations', function () {
Null: 'YES',
Key: '',
Default: null,
Extra: '' }
Extra: ''},
});
done();
});
@ -211,7 +211,7 @@ describe('migrations', function () {
Null: 'YES',
Key: '',
Default: null,
Extra: '' }
Extra: ''},
});
done();
});
@ -237,7 +237,7 @@ describe('migrations', function () {
Null: 'YES',
Key: '',
Default: null,
Extra: '' }
Extra: ''},
});
done();
});
@ -248,7 +248,7 @@ describe('migrations', function () {
query('SELECT * FROM UserData', function(err, res) {
cb(!err && res[0].email == 'test@example.com');
});
}
};
UserData.create({email: 'test@example.com'}, function(err, user) {
assert.ok(!err, 'Could not create user: ' + err);
@ -295,7 +295,7 @@ describe('migrations', function () {
// UserData.defineProperty('email', false); Can't undefine currently.
UserData.dataSource.isActual(function(err, ok) {
assert.ok(!ok, 'dataSource is actual (shouldn\t be)');
done()
done();
});
});
});
@ -324,7 +324,7 @@ describe('migrations', function () {
it('should allow both kinds of date columns', function(done) {
DateData.create({
dateTime: new Date('Aug 9 1996 07:47:33 GMT'),
timestamp: new Date('Sep 22 2007 17:12:22 GMT')
timestamp: new Date('Sep 22 2007 17:12:22 GMT'),
}, function(err, obj) {
assert.ok(!err);
assert.ok(obj);
@ -354,11 +354,9 @@ describe('migrations', function () {
db.disconnect();
done();
});
});
function setup(done) {
require('./init.js');
db = getSchema();
@ -372,9 +370,9 @@ function setup(done) {
createdByAdmin: Boolean,
}, {indexes: {
index0: {
columns: 'email, createdByAdmin'
}
}
columns: 'email, createdByAdmin',
},
},
});
StringData = db.define('StringData', {
@ -384,7 +382,7 @@ function setup(done) {
mediumString: {type: String, null: false, dataType: 'varchar', limit: 255},
tinyText: {type: String, dataType: 'tinyText'},
giantJSON: {type: Schema.JSON, dataType: 'longText'},
text: {type: Schema.Text, dataType: 'varchar', limit: 1024}
text: {type: Schema.Text, dataType: 'varchar', limit: 1024},
});
NumberData = db.define('NumberData', {
@ -393,12 +391,12 @@ function setup(done) {
tinyInt: {type: Number, dataType: 'tinyInt', display: 2},
mediumInt: {type: Number, dataType: 'mediumInt', unsigned: true,
required: true},
floater: {type: Number, dataType: 'double', precision: 14, scale: 6}
floater: {type: Number, dataType: 'double', precision: 14, scale: 6},
});
DateData = db.define('DateData', {
dateTime: {type: Date, dataType: 'datetime'},
timestamp: {type: Date, dataType: 'timestamp'}
timestamp: {type: Date, dataType: 'timestamp'},
});
query('SELECT VERSION()', function(err, res) {
@ -429,7 +427,7 @@ var blankDatabase = function (db, cb) {
});
};
getFields = function (model, cb) {
var getFields = function(model, cb) {
query('SHOW FIELDS FROM ' + model, function(err, res) {
if (err) {
cb(err);
@ -441,9 +439,9 @@ getFields = function (model, cb) {
cb(err, fields);
}
});
}
};
getIndexes = function (model, cb) {
var getIndexes = function(model, cb) {
query('SHOW INDEXES FROM ' + model, function(err, res) {
if (err) {
console.log(err);
@ -453,16 +451,10 @@ getIndexes = function (model, cb) {
// Note: this will only show the first key of compound keys
res.forEach(function(index) {
if (parseInt(index.Seq_in_index, 10) == 1) {
indexes[index.Key_name] = index
indexes[index.Key_name] = index;
}
});
cb(err, indexes);
}
});
};

View File

@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
var assert = require('assert');
require('./init');
var ds;
@ -13,84 +14,82 @@ before(function () {
describe('MySQL connector', function() {
it('should auto migrate/update tables', function(done) {
var schema_v1 =
{
"name": "CustomerTest",
"options": {
"idInjection": false,
"mysql": {
"schema": "myapp_test",
"table": "customer_test"
}
'name': 'CustomerTest',
'options': {
'idInjection': false,
'mysql': {
'schema': 'myapp_test',
'table': 'customer_test',
},
"properties": {
"id": {
"type": "String",
"length": 20,
"id": 1
},
"name": {
"type": "String",
"required": false,
"length": 40
'properties': {
'id': {
'type': 'String',
'length': 20,
'id': 1,
},
"email": {
"type": "String",
"required": true,
"length": 40
'name': {
'type': 'String',
'required': false,
'length': 40,
},
"age": {
"type": "Number",
"required": false
}
}
}
'email': {
'type': 'String',
'required': true,
'length': 40,
},
'age': {
'type': 'Number',
'required': false,
},
},
};
var schema_v2 =
{
"name": "CustomerTest",
"options": {
"idInjection": false,
"mysql": {
"schema": "myapp_test",
"table": "customer_test"
}
'name': 'CustomerTest',
'options': {
'idInjection': false,
'mysql': {
'schema': 'myapp_test',
'table': 'customer_test',
},
"properties": {
"id": {
"type": "String",
"length": 20,
"id": 1
},
"email": {
"type": "String",
"required": false,
"length": 60,
"mysql": {
"columnName": "email",
"dataType": "varchar",
"dataLength": 60,
"nullable": "YES"
}
'properties': {
'id': {
'type': 'String',
'length': 20,
'id': 1,
},
"firstName": {
"type": "String",
"required": false,
"length": 40
'email': {
'type': 'String',
'required': false,
'length': 60,
'mysql': {
'columnName': 'email',
'dataType': 'varchar',
'dataLength': 60,
'nullable': 'YES',
},
"lastName": {
"type": "String",
"required": false,
"length": 40
}
}
}
},
'firstName': {
'type': 'String',
'required': false,
'length': 40,
},
'lastName': {
'type': 'String',
'required': false,
'length': 40,
},
},
};
ds.createModel(schema_v1.name, schema_v1.properties, schema_v1.options);
ds.automigrate(function() {
ds.discoverModelProperties('customer_test', function(err, props) {
assert.equal(props.length, 4);
var names = props.map(function(p) {
@ -137,6 +136,4 @@ describe('MySQL connector', function () {
done();
});
});
});

View File

@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
process.env.NODE_ENV = 'test';
require('should');
@ -31,10 +32,9 @@ describe('discoverModels', function () {
describe('Discover models including views', function() {
it('should return an array of tables and views', function(done) {
db.discoverModelDefinitions({
views: true,
limit: 3
limit: 3,
}, function(err, models) {
if (err) {
console.error(err);
@ -56,9 +56,8 @@ describe('discoverModels', function () {
describe('Discover current user\'s tables', function() {
it('should return an array of tables for the current user', function(done) {
db.discoverModelDefinitions({
limit: 3
limit: 3,
}, function(err, models) {
if (err) {
console.error(err);
@ -77,10 +76,9 @@ describe('discoverModels', function () {
describe('Discover models excluding views', function() {
// TODO: this test assumes the current user owns the tables
it.skip('should return an array of only tables', function(done) {
db.discoverModelDefinitions({
views: false,
limit: 3
limit: 3,
}, function(err, models) {
if (err) {
console.error(err);
@ -104,10 +102,9 @@ describe('discoverModels', function () {
describe('Discover models including other users', function() {
it('should return an array of all tables and views', function(done) {
db.discoverModelDefinitions({
all: true,
limit: 3
limit: 3,
}, function(err, models) {
if (err) {
console.error(err);
@ -144,7 +141,6 @@ describe('Discover model properties', function () {
});
});
});
});
describe('Discover model primary keys', function() {
@ -244,7 +240,8 @@ describe('Discover LDL schema from a table', function () {
describe('Discover and build models', function() {
var models;
before(function(done) {
db.discoverAndBuildModels('INVENTORY', {owner: 'STRONGLOOP', visited: {}, associations: true}, function (err, models_) {
db.discoverAndBuildModels('INVENTORY', {owner: 'STRONGLOOP', visited: {}, associations: true},
function(err, models_) {
models = models_;
done(err);
});

View File

@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
var should = require('./init.js');
var Post, PostWithStringId, PostWithUniqueTitle, db;
@ -21,7 +22,6 @@ ObjectID.prototype.toJSON = function() {
};
describe('mysql', function() {
before(function(done) {
db = getDataSource();
@ -31,18 +31,18 @@ describe('mysql', function () {
comments: [String],
history: Object,
stars: Number,
userId: ObjectID
userId: ObjectID,
});
PostWithStringId = db.define('PostWithStringId', {
id: {type: String, id: true},
title: {type: String, length: 255, index: true},
content: { type: String }
content: {type: String},
});
PostWithUniqueTitle = db.define('PostWithUniqueTitle', {
title: {type: String, length: 255, index: {unique: true}},
content: { type: String }
content: {type: String},
});
db.automigrate(['PostWithDefaultId', 'PostWithStringId', 'PostWithUniqueTitle'], function(err) {
@ -64,7 +64,6 @@ describe('mysql', function () {
it('should allow array or object', function(done) {
Post.create({title: 'a', content: 'AAA', comments: ['1', '2'],
history: {a: 1, b: 'b'}}, function(err, post) {
should.not.exist(err);
Post.findById(post.id, function(err, p) {
@ -84,7 +83,6 @@ describe('mysql', function () {
var uid = new ObjectID('123');
Post.create({title: 'a', content: 'AAA', userId: uid},
function(err, post) {
should.not.exist(err);
Post.findById(post.id, function(err, p) {
@ -115,7 +113,6 @@ describe('mysql', function () {
done();
});
});
});
});
@ -136,7 +133,6 @@ describe('mysql', function () {
done();
});
});
});
});
@ -158,7 +154,6 @@ describe('mysql', function () {
done();
});
});
});
context('replaceOrCreate', function() {
@ -250,7 +245,6 @@ describe('mysql', function () {
done();
});
});
});
});
@ -271,7 +265,6 @@ describe('mysql', function () {
done();
});
});
});
});
@ -294,11 +287,10 @@ describe('mysql', function () {
done();
});
});
});
it('all return should honor filter.fields', function(done) {
var post = new Post({title: 'b', content: 'BBB'})
var post = new Post({title: 'b', content: 'BBB'});
post.save(function(err, post) {
Post.all({fields: ['title'], where: {title: 'b'}}, function(err, posts) {
should.not.exist(err);
@ -310,7 +302,6 @@ describe('mysql', function () {
done();
});
});
});
@ -384,7 +375,7 @@ describe('mysql', function () {
Post.create({title: 'My Post', content: 'Hello'}, function(err, post) {
Post.find({where: {and: [
{title: 'My Post'},
{content: 'Hello'}
{content: 'Hello'},
]}}, function(err, posts) {
should.not.exist(err);
posts.should.have.property('length', 1);
@ -397,7 +388,7 @@ describe('mysql', function () {
Post.create({title: 'My Post', content: 'Hello'}, function(err, post) {
Post.find({where: {and: [
{title: 'My Post'},
{content: 'Hello1'}
{content: 'Hello1'},
]}}, function(err, posts) {
should.not.exist(err);
posts.should.have.property('length', 0);
@ -410,7 +401,7 @@ describe('mysql', function () {
Post.create({title: 'My Post', content: 'Hello'}, function(err, post) {
Post.find({where: {or: [
{title: 'My Post'},
{content: 'Hello1'}
{content: 'Hello1'},
]}}, function(err, posts) {
should.not.exist(err);
posts.should.have.property('length', 1);
@ -423,7 +414,7 @@ describe('mysql', function () {
Post.create({title: 'My Post', content: 'Hello'}, function(err, post) {
Post.find({where: {or: [
{title: 'My Post1'},
{content: 'Hello1'}
{content: 'Hello1'},
]}}, function(err, posts) {
should.not.exist(err);
posts.should.have.property('length', 0);
@ -437,13 +428,13 @@ describe('mysql', function () {
Post.create({title: 'My Post', content: 'Hello'}, function(err, post) {
Post.count({and: [
{title: 'My Post'},
{content: 'Hello'}
{content: 'Hello'},
]}, function(err, count) {
should.not.exist(err);
count.should.be.equal(1);
Post.count({and: [
{title: 'My Post1'},
{content: 'Hello'}
{content: 'Hello'},
]}, function(err, count) {
should.not.exist(err);
count.should.be.equal(0);
@ -459,7 +450,7 @@ describe('mysql', function () {
Post.create({title: 'My Post2', content: 'Hello'}, function(err, post) {
Post.destroyAll({and: [
{title: 'My Post1'},
{content: 'Hello'}
{content: 'Hello'},
]}, function(err) {
should.not.exist(err);
Post.count(function(err, count) {
@ -517,7 +508,6 @@ describe('mysql', function () {
});
});
it('should not allow SQL injection for inq operator with number column', function(done) {
Post.create({title: 'My Post1', content: 'Hello', stars: 5},
function(err, post) {
@ -581,7 +571,7 @@ describe('mysql', function () {
beforeEach(function createTestFixtures(done) {
Post.create([
{title: 'a', content: 'AAA'},
{title: 'b', content: 'BBB'}
{title: 'b', content: 'BBB'},
], done);
});
after(function deleteTestFixtures(done) {

View File

@ -3,9 +3,10 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
var should = require('./init');
var suite = require('loopback-datasource-juggler/test/persistence-hooks.suite.js');
suite(global.getDataSource(), should, {
replaceOrCreateReportsNewInstance: true
replaceOrCreateReportsNewInstance: true,
});

View File

@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
if (typeof Promise === 'undefined') {
global.Promise = require('bluebird');
}
@ -13,17 +14,16 @@ require('should');
var db, Post, Review;
describe('transactions with promise', function() {
before(function(done) {
db = getDataSource({collation: 'utf8_general_ci', createDatabase: true});
db.once('connected', function() {
Post = db.define('PostTX', {
title: {type: String, length: 255, index: true},
content: {type: String}
content: {type: String},
}, {mysql: {engine: 'INNODB'}});
Review = db.define('ReviewTX', {
author: String,
content: {type: String}
content: {type: String},
}, {mysql: {engine: 'INNODB'}});
Post.hasMany(Review, {as: 'reviews', foreignKey: 'postId'});
db.automigrate(['PostTX', 'ReviewTX'], done);
@ -38,7 +38,7 @@ describe('transactions with promise', function() {
// Transaction.begin(db.connector, Transaction.READ_COMMITTED,
var promise = Post.beginTransaction({
isolationLevel: Transaction.READ_COMMITTED,
timeout: timeout
timeout: timeout,
});
promise.then(function(tx) {
(typeof tx.id).should.be.eql('string');
@ -65,7 +65,7 @@ describe('transactions with promise', function() {
function(p) {
p.reviews.create({
author: 'John',
content: 'Review for ' + p.title
content: 'Review for ' + p.title,
}, {transaction: currentTx}).then(
function(c) {
done(null, c);
@ -102,7 +102,6 @@ describe('transactions with promise', function() {
}
describe('commit', function() {
var post = {title: 't1', content: 'c1'};
before(createPostInTx(post));
@ -129,7 +128,6 @@ describe('transactions with promise', function() {
});
describe('rollback', function() {
var post = {title: 't2', content: 'c2'};
before(createPostInTx(post));
@ -156,7 +154,6 @@ describe('transactions with promise', function() {
});
describe('timeout', function() {
var post = {title: 't3', content: 'c3'};
before(createPostInTx(post, 500));
@ -176,7 +173,5 @@ describe('transactions with promise', function() {
done();
});
});
});
});

View File

@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
var Transaction = require('loopback-datasource-juggler').Transaction;
require('./init.js');
require('should');
@ -10,17 +11,16 @@ require('should');
var db, Post, Review;
describe('transactions', function() {
before(function(done) {
db = getDataSource({collation: 'utf8_general_ci', createDatabase: true});
db.once('connected', function() {
Post = db.define('PostTX', {
title: {type: String, length: 255, index: true},
content: {type: String}
content: {type: String},
}, {mysql: {engine: 'INNODB'}});
Review = db.define('ReviewTX', {
author: String,
content: {type: String}
content: {type: String},
}, {mysql: {engine: 'INNODB'}});
Post.hasMany(Review, {as: 'reviews', foreignKey: 'postId'});
db.automigrate(['PostTX', 'ReviewTX'], done);
@ -35,7 +35,7 @@ describe('transactions', function() {
// Transaction.begin(db.connector, Transaction.READ_COMMITTED,
Post.beginTransaction({
isolationLevel: Transaction.READ_COMMITTED,
timeout: timeout
timeout: timeout,
},
function(err, tx) {
if (err) return done(err);
@ -65,7 +65,7 @@ describe('transactions', function() {
} else {
p.reviews.create({
author: 'John',
content: 'Review for ' + p.title
content: 'Review for ' + p.title,
}, {transaction: tx},
function(err, c) {
done(err);
@ -105,7 +105,6 @@ describe('transactions', function() {
}
describe('commit', function() {
var post = {title: 't1', content: 'c1'};
before(createPostInTx(post));
@ -132,7 +131,6 @@ describe('transactions', function() {
});
describe('rollback', function() {
var post = {title: 't2', content: 'c2'};
before(createPostInTx(post));
@ -159,7 +157,6 @@ describe('transactions', function() {
});
describe('timeout', function() {
var post = {title: 't3', content: 'c3'};
before(createPostInTx(post, 500));
@ -179,7 +176,5 @@ describe('transactions', function() {
done();
});
});
});
});