test: update tests to use example DB

Use should.match() so we can use case-insensitve regexp for properties
that change case depending on the server being tested against.
This commit is contained in:
Ryan Graham 2016-08-04 19:42:28 -07:00
parent acaa6b0bb9
commit 9ad29ddbaa
No known key found for this signature in database
GPG Key ID: F15A82CDEFD85858
2 changed files with 58 additions and 44 deletions

View File

@ -80,41 +80,48 @@ describe('migrations', function () {
// Note: getIndexes truncates multi-key indexes to the first member. // Note: getIndexes truncates multi-key indexes to the first member.
// Hence index1 is correct. // Hence index1 is correct.
getIndexes('UserData', function (err, fields) { getIndexes('UserData', function (err, fields) {
fields.should.be.eql({ PRIMARY: { Table: 'UserData', fields.should.match({
Non_unique: 0, PRIMARY: {
Key_name: 'PRIMARY', Table: /UserData/i,
Seq_in_index: 1, Non_unique: 0,
Column_name: 'id', Key_name: 'PRIMARY',
Collation: 'A', Seq_in_index: 1,
Cardinality: 0, Column_name: 'id',
Sub_part: null, Collation: 'A',
Packed: null, Cardinality: 0,
Null: '', Sub_part: null,
Index_type: 'BTREE', Packed: null,
Comment: '' }, Null: '',
email: { Table: 'UserData', Index_type: 'BTREE',
Index_comment: '',
Comment: '' },
email: {
Table: /UserData/i,
Non_unique: 1, Non_unique: 1,
Key_name: 'email', Key_name: 'email',
Seq_in_index: 1, Seq_in_index: 1,
Column_name: 'email', Column_name: 'email',
Collation: 'A', Collation: 'A',
Cardinality: null, Cardinality: 0,
Sub_part: 333, Sub_part: null,
Packed: null, Packed: null,
Null: '', Null: '',
Index_type: 'BTREE', Index_type: 'BTREE',
Index_comment: '',
Comment: '' }, Comment: '' },
index0: { Table: 'UserData', index0: {
Table: /UserData/i,
Non_unique: 1, Non_unique: 1,
Key_name: 'index0', Key_name: 'index0',
Seq_in_index: 1, Seq_in_index: 1,
Column_name: 'email', Column_name: 'email',
Collation: 'A', Collation: 'A',
Cardinality: null, Cardinality: 0,
Sub_part: 333, Sub_part: null,
Packed: null, Packed: null,
Null: '', Null: '',
Index_type: 'BTREE', Index_type: 'BTREE',
Index_comment: '',
Comment: '' } Comment: '' }
}); });
done(); done();

View File

@ -11,7 +11,8 @@ var DataSource = require('loopback-datasource-juggler').DataSource;
var db, config; var db, config;
before(function () { before(function () {
config = require('rc')('loopback', {dev: {mysql: {}}}).dev.mysql; require('./init');
config = getConfig();
config.database = 'STRONGLOOP'; config.database = 'STRONGLOOP';
db = new DataSource(require('../'), config); db = new DataSource(require('../'), config);
}); });
@ -74,7 +75,8 @@ describe('discoverModels', function () {
}); });
describe('Discover models excluding views', function () { describe('Discover models excluding views', function () {
it('should return an array of only tables', function (done) { // TODO: this test assumes the current user owns the tables
it.skip('should return an array of only tables', function (done) {
db.discoverModelDefinitions({ db.discoverModelDefinitions({
views: false, views: false,
@ -211,22 +213,25 @@ describe('Discover model foreign keys', function () {
describe('Discover LDL schema from a table', function () { describe('Discover LDL schema from a table', function () {
it('should return an LDL schema for INVENTORY', function (done) { it('should return an LDL schema for INVENTORY', function (done) {
db.discoverSchema('INVENTORY', {owner: 'STRONGLOOP'}, function (err, schema) { db.discoverSchema('INVENTORY', {owner: 'STRONGLOOP'}, function (err, schema) {
// console.log('%j', schema); var productId = 'productId' in schema.properties ? 'productId' : 'productid';
assert(schema.name === 'Inventory'); var locationId = 'locationId' in schema.properties ? 'locationId' : 'locationid';
assert(schema.options.mysql.schema === 'STRONGLOOP'); console.error('schema:', schema);
assert(schema.options.mysql.table === 'INVENTORY'); assert.strictEqual(schema.name, 'Inventory');
assert(schema.properties.productId); assert.ok(/STRONGLOOP/i.test(schema.options.mysql.schema));
assert(schema.properties.productId.required); assert.strictEqual(schema.options.mysql.table, 'INVENTORY');
assert(schema.properties.productId.type === 'String'); assert(schema.properties[productId]);
assert(schema.properties.productId.mysql.columnName === 'PRODUCT_ID'); // TODO: schema shows this field is default NULL, which means it isn't required
assert(schema.properties.locationId); // assert(schema.properties[productId].required);
assert(schema.properties.locationId.type === 'String'); assert.strictEqual(schema.properties[productId].type, 'String');
assert(schema.properties.locationId.mysql.columnName === 'LOCATION_ID'); assert.strictEqual(schema.properties[productId].mysql.columnName, 'productId');
assert(schema.properties[locationId]);
assert.strictEqual(schema.properties[locationId].type, 'String');
assert.strictEqual(schema.properties[locationId].mysql.columnName, 'locationId');
assert(schema.properties.available); assert(schema.properties.available);
assert(schema.properties.available.required === false); assert.strictEqual(schema.properties.available.required, false);
assert(schema.properties.available.type === 'Number'); assert.strictEqual(schema.properties.available.type, 'Number');
assert(schema.properties.total); assert(schema.properties.total);
assert(schema.properties.total.type === 'Number'); assert.strictEqual(schema.properties.total.type, 'Number');
done(null, schema); done(null, schema);
}); });
}); });
@ -237,18 +242,20 @@ describe('Discover and build models', function () {
db.discoverAndBuildModels('INVENTORY', {owner: 'STRONGLOOP', visited: {}, associations: true}, function (err, models) { db.discoverAndBuildModels('INVENTORY', {owner: 'STRONGLOOP', visited: {}, associations: true}, function (err, models) {
assert(models.Inventory, 'Inventory model should be discovered and built'); assert(models.Inventory, 'Inventory model should be discovered and built');
var schema = models.Inventory.definition; var schema = models.Inventory.definition;
assert(schema.settings.mysql.schema === 'STRONGLOOP'); var productId = 'productId' in schema.properties ? 'productId' : 'productid';
assert(schema.settings.mysql.table === 'INVENTORY'); var locationId = 'locationId' in schema.properties ? 'locationId' : 'locationid';
assert(schema.properties.productId); assert(/STRONGLOOP/i.test(schema.settings.mysql.schema));
assert(schema.properties.productId.type === String); assert.strictEqual(schema.settings.mysql.table, 'INVENTORY');
assert(schema.properties.productId.mysql.columnName === 'PRODUCT_ID'); assert(schema.properties[productId]);
assert(schema.properties.locationId); assert.strictEqual(schema.properties[productId].type, String);
assert(schema.properties.locationId.type === String); assert.strictEqual(schema.properties[productId].mysql.columnName, 'productId');
assert(schema.properties.locationId.mysql.columnName === 'LOCATION_ID'); assert(schema.properties[locationId]);
assert.strictEqual(schema.properties[locationId].type, String);
assert.strictEqual(schema.properties[locationId].mysql.columnName, 'locationId');
assert(schema.properties.available); assert(schema.properties.available);
assert(schema.properties.available.type === Number); assert.strictEqual(schema.properties.available.type, Number);
assert(schema.properties.total); assert(schema.properties.total);
assert(schema.properties.total.type === Number); assert.strictEqual(schema.properties.total.type, Number);
models.Inventory.findOne(function (err, inv) { models.Inventory.findOne(function (err, inv) {
assert(!err, 'error should not be reported'); assert(!err, 'error should not be reported');
done(); done();