Tests for generated columns

This commit is contained in:
Christiaan Westerbeek 2016-10-14 14:01:42 +02:00 committed by biniam
parent dd91b16e60
commit d89ab511c6
2 changed files with 50 additions and 1 deletions

View File

@ -206,6 +206,42 @@ describe('Discover model foreign keys', function() {
}); });
}); });
describe('Discover model generated columns', function() {
it('should return an array of columns for STRONGLOOP.PRODUCT and none of them is generated', function(done) {
db.discoverModelProperties('product', function(err, models) {
if (err) {
console.error(err);
done(err);
} else {
models.forEach(function(m) {
// console.dir(m);
assert(m.tableName === 'PRODUCT');
assert(!m.generated, 'STRONGLOOP.PRODUCT table should not have generated (identity) columns');
});
done(null, models);
}
});
});
it('should return an array of columns for STRONGLOOP.TESTGEN and the first is generated', function(done) {
db.discoverModelProperties('testgen', function(err, models) {
if (err) {
console.error(err);
done(err);
} else {
models.forEach(function(m) {
// console.dir(m);
assert(m.tableName === 'TESTGEN');
if (m.columnName === 'ID') {
assert(m.generated, 'STRONGLOOP.TESTGEN.ID should be a generated (identity) column');
}
});
done(null, models);
}
});
});
});
describe('Discover LDL schema from a table', function() { describe('Discover LDL schema from a table', function() {
var schema; var schema;
before(function(done) { before(function(done) {

View File

@ -86,7 +86,7 @@ DROP TABLE IF EXISTS `INVENTORY_VIEW`;
/*!50001 DROP VIEW IF EXISTS `INVENTORY_VIEW`*/; /*!50001 DROP VIEW IF EXISTS `INVENTORY_VIEW`*/;
SET @saved_cs_client = @@character_set_client; SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8; SET character_set_client = utf8;
/*!50001 CREATE VIEW `INVENTORY_VIEW` AS SELECT /*!50001 CREATE VIEW `INVENTORY_VIEW` AS SELECT
1 AS `ID`, 1 AS `ID`,
1 AS `PRODUCT_ID`, 1 AS `PRODUCT_ID`,
1 AS `PRODUCT_NAME`, 1 AS `PRODUCT_NAME`,
@ -189,6 +189,19 @@ LOCK TABLES `RESERVATION` WRITE;
/*!40000 ALTER TABLE `RESERVATION` ENABLE KEYS */; /*!40000 ALTER TABLE `RESERVATION` ENABLE KEYS */;
UNLOCK TABLES; UNLOCK TABLES;
--
-- Table structure for table `TESTGEN`
--
DROP TABLE IF EXISTS `TESTGEN`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `TESTGEN` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`NAME` varchar(64) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
-- --
-- Current Database: `STRONGLOOP` -- Current Database: `STRONGLOOP`
-- --