Skip to content

Commit

Permalink
Improve error messages in autoupdate test
Browse files Browse the repository at this point in the history
  • Loading branch information
bajtos committed May 3, 2019
1 parent 795e064 commit f0d671f
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions test/postgresql.autoupdate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,19 +629,27 @@ describe('autoupdate', function() {
// Table create order is important. Referenced tables must exist before creating a reference.
// do initial update/creation of referenced tables
ds.autoupdate(function(err) {
assert(!err, err);
if (err) {
err.message += ' (while running initial autoupdate)';
return done(err);
}

// do initial update/creation of table with fk
ds.createModel(orderTest_schema_v1.name, orderTest_schema_v1.properties, orderTest_schema_v1.options);
ds.autoupdate(function(err) {
assert(!err, err);
if (err) {
err.message += ' (while updating OrderTest schema v1)';
return done(err);
}
ds.discoverModelProperties('order_test', function(err, props) {
if (err) return done(err);
// validate that we have the correct number of properties
assert.equal(props.length, 3);

// get the foreign keys for order_test
ds.connector.discoverForeignKeys('order_test', {}, function(err, foreignKeys) {
assert(!err, err);
if (err) return done(err);

// validate that the foreign key exists and points to the right column
assert(foreignKeys);
assert.equal(foreignKeys.length, 1);
Expand All @@ -653,14 +661,18 @@ describe('autoupdate', function() {
// update and add another fk
ds.createModel(orderTest_schema_v2.name, orderTest_schema_v2.properties, orderTest_schema_v2.options);
ds.autoupdate(function(err) {
assert(!err, err);
if (err) {
err.message += ' (while updating OrderTest schema v2)';
return done(err);
}
ds.discoverModelProperties('order_test', function(err, props) {
if (err) return done(err);
// validate that we have the correct number of properties
assert.equal(props.length, 4);

// get the foreign keys for order_test
ds.connector.discoverForeignKeys('order_test', {}, function(err, foreignKeysUpdated) {
assert(!err, err);
if (err) return done(err);
// validate that the foreign keys exist and point to the new column
assert(foreignKeysUpdated);
assert.equal(foreignKeysUpdated.length, 1);
Expand All @@ -673,18 +685,27 @@ describe('autoupdate', function() {
ds.createModel(orderTest_schema_v3.name, orderTest_schema_v3.properties,
orderTest_schema_v3.options);
ds.autoupdate(function(err) {
if (err) {
err.message += ' (while updating OrderTest schema v3)';
return done(err);
}
// get the foreign keys for order_test
ds.connector.discoverForeignKeys('order_test', {}, function(err, foreignKeysMulti) {
assert(!err, err);
if (err) return done(err);
assert(foreignKeysMulti);
assert.equal(foreignKeysMulti.length, 2);

// remove fk
ds.createModel(orderTest_schema_v4.name, orderTest_schema_v4.properties,
orderTest_schema_v4.options);
ds.autoupdate(function(err) {
assert(!err, err);
if (err) {
err.message += ' (while updating OrderTest schema v4)';
return done(err);
}
ds.discoverModelProperties('order_test', function(err, props) {
if (err) return done(err);

// validate that we have the correct number of properties
assert.equal(props.length, 4);

Expand Down

0 comments on commit f0d671f

Please sign in to comment.