test: separate assertions from test flow control

This commit is contained in:
Ryan Graham 2016-08-05 10:49:09 -07:00
parent 9ad29ddbaa
commit 5a7cac6852
No known key found for this signature in database
GPG Key ID: F15A82CDEFD85858
1 changed files with 56 additions and 44 deletions

View File

@ -211,8 +211,14 @@ describe('Discover model foreign keys', function () {
});
describe('Discover LDL schema from a table', function () {
it('should return an LDL schema for INVENTORY', function (done) {
db.discoverSchema('INVENTORY', {owner: 'STRONGLOOP'}, function (err, schema) {
var schema;
before(function (done) {
db.discoverSchema('INVENTORY', {owner: 'STRONGLOOP'}, function (err, schema_) {
schema = schema_;
done(err);
});
});
it('should return an LDL schema for INVENTORY', function () {
var productId = 'productId' in schema.properties ? 'productId' : 'productid';
var locationId = 'locationId' in schema.properties ? 'locationId' : 'locationid';
console.error('schema:', schema);
@ -232,14 +238,18 @@ describe('Discover LDL schema from a table', function () {
assert.strictEqual(schema.properties.available.type, 'Number');
assert(schema.properties.total);
assert.strictEqual(schema.properties.total.type, 'Number');
done(null, schema);
});
});
});
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) {
var models;
before(function (done) {
db.discoverAndBuildModels('INVENTORY', {owner: 'STRONGLOOP', visited: {}, associations: true}, function (err, models_) {
models = models_;
done(err);
});
});
it('should discover and build models', function () {
assert(models.Inventory, 'Inventory model should be discovered and built');
var schema = models.Inventory.definition;
var productId = 'productId' in schema.properties ? 'productId' : 'productid';
@ -256,10 +266,12 @@ describe('Discover and build models', function () {
assert.strictEqual(schema.properties.available.type, Number);
assert(schema.properties.total);
assert.strictEqual(schema.properties.total.type, Number);
});
it('should be able to find an instance', function (done) {
assert(models.Inventory, 'Inventory model must exist');
models.Inventory.findOne(function (err, inv) {
assert(!err, 'error should not be reported');
done();
});
});
});
});