Add the test for loopback-datasource-juggler PR-48

https://github.com/strongloop/loopback-datasource-juggler/pull/48
This commit is contained in:
Raymond Feng 2013-12-05 16:09:15 -08:00
parent ae488942bb
commit e16e67568c
1 changed files with 26 additions and 0 deletions

View File

@ -7,6 +7,7 @@ var db;
before(function() {
var config = require('rc')('loopback', {dev: {mysql: {}}}).dev.mysql;
config.database = 'STRONGLOOP';
db = new DataSource(require('../'), config);
});
@ -192,3 +193,28 @@ describe('Discover LDL schema from a table', function () {
});
});
});
describe('Discover and build models', function () {
it('should discover and build models', function (done) {
db.discoverAndBuildModels('INVENTORY', {owner: 'STRONGLOOP', visited: {}, associations: true}, function (err, models) {
assert(models.Inventory, 'Inventory model should be discovered and built');
var schema = models.Inventory.definition;
assert(schema.settings.mysql.schema === 'STRONGLOOP');
assert(schema.settings.mysql.table === 'INVENTORY');
assert(schema.properties.productId);
assert(schema.properties.productId.type === String);
assert(schema.properties.productId.mysql.columnName === 'PRODUCT_ID');
assert(schema.properties.locationId);
assert(schema.properties.locationId.type === String);
assert(schema.properties.locationId.mysql.columnName === 'LOCATION_ID');
assert(schema.properties.available);
assert(schema.properties.available.type === Number);
assert(schema.properties.total);
assert(schema.properties.total.type === Number);
models.Inventory.findOne(function (err, inv) {
assert(!err, 'error should not be reported');
done();
});
});
});
});