From 7fdf1771fee8b080867558c36c87ee48bcbc1a0e Mon Sep 17 00:00:00 2001 From: Muhammad Aaqil Date: Sun, 1 Sep 2024 12:40:31 +0500 Subject: [PATCH 1/2] test: all tests are passing because of empty model discovery Signed-off-by: Muhammad Aaqil --- test/mysql.discover.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/mysql.discover.test.js b/test/mysql.discover.test.js index 9da8060e..2df73143 100644 --- a/test/mysql.discover.test.js +++ b/test/mysql.discover.test.js @@ -242,6 +242,11 @@ describe('Discover model generated columns', function() { 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) return done(err); + console.log('[[[[[[[[[[[models]]]]]]]]]]]'); + console.log(models); + console.log(models.length); + console.log('[[[[[[[[[[[models]]]]]]]]]]]'); + models.forEach(function(model) { assert(model.tableName.toLowerCase() === 'testgen'); if (model.columnName === 'ID') { From 4872c3899dfa6b00e7b8a96f90c3034ae5430e84 Mon Sep 17 00:00:00 2001 From: Muhammad Aaqil Date: Sun, 1 Sep 2024 16:44:23 +0500 Subject: [PATCH 2/2] test: cover when an empty array of models is returned Signed-off-by: Muhammad Aaqil --- package.json | 2 +- test/mysql.discover.test.js | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index b0ab2d9d..286d9375 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "pretest": "node pretest.js", "lint": "eslint .", - "test": "mocha test/*.test.js", + "test": "mocha test/mysql.discover.test.js", "posttest": "npm run lint", "postinstall": "patch-package" }, diff --git a/test/mysql.discover.test.js b/test/mysql.discover.test.js index 2df73143..cf16036c 100644 --- a/test/mysql.discover.test.js +++ b/test/mysql.discover.test.js @@ -109,6 +109,7 @@ describe('Discover models including other users', function() { done(err); } else { let others = false; + assert(models.length > 0, 'some models returned'); models.find(function(m) { assert(m.owner); if (m.owner !== 'STRONGLOOP') { @@ -143,6 +144,7 @@ describe('Discover model properties', function() { console.error(err); done(err); } else { + assert(models.length > 0, 'some models returned'); models.forEach(function(m) { productProperties.push(m.columnName); }); productProperties.forEach((prop, index) => { assert(productPropertiesInOrdinalOrder[index] === prop); @@ -159,6 +161,7 @@ describe('Discover model properties', function() { console.error(err); done(err); } else { + assert(models.length > 0, 'some models returned'); models.forEach(function(m) { assert(m.tableName.toLowerCase() === 'product'); }); @@ -176,6 +179,7 @@ describe('Discover model primary keys', function() { console.error(err); done(err); } else { + assert(models.length > 0, 'some models returned'); models.forEach(function(m) { assert(m.tableName.toLowerCase() === 'product'); }); @@ -190,6 +194,7 @@ describe('Discover model primary keys', function() { console.error(err); done(err); } else { + assert(models.length > 0, 'some models returned'); models.forEach(function(m) { assert(m.tableName.toLowerCase() === 'product'); }); @@ -206,6 +211,7 @@ describe('Discover model foreign keys', function() { console.error(err); done(err); } else { + assert(models.length > 0, 'some models returned'); models.forEach(function(m) { assert(m.fkTableName === 'INVENTORY'); }); @@ -219,6 +225,7 @@ describe('Discover model foreign keys', function() { console.error(err); done(err); } else { + assert(models.length > 0, 'some models returned'); models.forEach(function(m) { assert(m.fkTableName === 'INVENTORY'); }); @@ -232,6 +239,7 @@ 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) return done(err); + assert(models.length > 0, 'some models returned'); models.forEach(function(model) { assert(model.tableName.toLowerCase() === 'product'); assert(!model.generated, 'STRONGLOOP.PRODUCT table should not have generated (identity) columns'); @@ -242,11 +250,7 @@ describe('Discover model generated columns', function() { 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) return done(err); - console.log('[[[[[[[[[[[models]]]]]]]]]]]'); - console.log(models); - console.log(models.length); - console.log('[[[[[[[[[[[models]]]]]]]]]]]'); - + assert(models.length > 0, 'some models returned'); models.forEach(function(model) { assert(model.tableName.toLowerCase() === 'testgen'); if (model.columnName === 'ID') {