From 0de8dc7c97a98c8927e7c8f61e727a568850335d Mon Sep 17 00:00:00 2001 From: Ron Lloyd Date: Sun, 28 Aug 2016 23:07:03 -0600 Subject: [PATCH] Tests for autoupdate mysql.columnName bug fix --- test/mysql.autoupdate.test.js | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/test/mysql.autoupdate.test.js b/test/mysql.autoupdate.test.js index b9e5114..40b9029 100644 --- a/test/mysql.autoupdate.test.js +++ b/test/mysql.autoupdate.test.js @@ -13,6 +13,10 @@ before(function() { }); describe('MySQL connector', function() { + before(function () { + setupAltColNameData(); + }); + it('should auto migrate/update tables', function(done) { var schema_v1 = { @@ -163,6 +167,37 @@ describe('MySQL connector', function() { }); }); + function setupAltColNameData() { + var schema = { + "name": "ColRenameTest", + "options": { + "idInjection": false, + "mysql": { + "schema": "myapp_test", + "table": "col_rename_test" + } + }, + "properties": { + "firstName": { + "type": "String", + "required": false, + "length": 40, + "mysql": { + "columnName": "first_name", + "dataType": "varchar", + "dataLength": 40 + } + }, + "lastName": { + "type": "String", + "required": false, + "length": 40 + } + } + }; + ds.createModel(schema.name, schema.properties, schema.options); + } + it('should report errors for automigrate', function(done) { ds.automigrate('XYZ', function(err) { assert(err); @@ -176,4 +211,25 @@ describe('MySQL connector', function() { done(); }); }); + + it('"mysql.columnName" is updated with correct name on create table', function (done) { + // first autoupdate call uses create table + verifyMysqlColumnNameAutoupdate(done); + }); + + it('"mysql.columnName" is updated without changing column name on alter table', function (done) { + // second autoupdate call uses alter table + verifyMysqlColumnNameAutoupdate(done); + }); + + function verifyMysqlColumnNameAutoupdate(done) { + ds.autoupdate('ColRenameTest', function (err) { + ds.discoverModelProperties('col_rename_test', function (err, props) { + assert.equal(props[0].columnName, 'first_name'); + assert.equal(props[1].columnName, 'lastName'); + assert.equal(props.length, 2); + done(); + }); + }); + } });