From 4acf78a08e5d3752329fa78f9bb71676ec8a225a Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Wed, 2 Mar 2022 14:28:23 +0100 Subject: [PATCH] Added basic tests for `@tryghost/database-info` - these check a few of the imports and static functions --- ghost/database-info/package.json | 1 + .../database-info/test/database-info.test.js | 53 +++++++++++++++++++ ghost/database-info/test/hello.test.js | 10 ---- 3 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 ghost/database-info/test/database-info.test.js delete mode 100644 ghost/database-info/test/hello.test.js diff --git a/ghost/database-info/package.json b/ghost/database-info/package.json index b8a148f689..5b7fc8908f 100644 --- a/ghost/database-info/package.json +++ b/ghost/database-info/package.json @@ -20,6 +20,7 @@ }, "devDependencies": { "c8": "7.11.0", + "knex": "1.0.3", "mocha": "9.1.4", "should": "13.2.3", "sinon": "12.0.1" diff --git a/ghost/database-info/test/database-info.test.js b/ghost/database-info/test/database-info.test.js new file mode 100644 index 0000000000..e6b3af38e0 --- /dev/null +++ b/ghost/database-info/test/database-info.test.js @@ -0,0 +1,53 @@ +// Switch these lines once there are useful utils +// const testUtils = require('./utils'); +require('./utils'); + +const Knex = require('knex'); +const DatabaseInfo = require('../'); + +describe('DatabaseInfo', function () { + it('should export a class', function () { + DatabaseInfo.should.be.a.class; + }); + + it('can construct the class', function () { + const knex = Knex({ + client: 'sqlite3' + }); + + const databaseInfo = new DatabaseInfo(knex); + databaseInfo.should.be.an.instanceOf(DatabaseInfo); + }); + + it('recognises sqlite3 client is SQLite', function () { + const knex = Knex({ + client: 'sqlite3' + }); + + DatabaseInfo.isSQLite(knex).should.be.true(); + }); + + it('recognises better-sqlite3 client is SQLite', function () { + const knex = Knex({ + client: 'better-sqlite3' + }); + + DatabaseInfo.isSQLite(knex).should.be.true(); + }); + + it('recognises mysql client is MySQL', function () { + const knex = Knex({ + client: 'mysql' + }); + + DatabaseInfo.isMySQL(knex).should.be.true(); + }); + + it('recognises mysql2 client is MySQL', function () { + const knex = Knex({ + client: 'mysql2' + }); + + DatabaseInfo.isMySQL(knex).should.be.true(); + }); +}); diff --git a/ghost/database-info/test/hello.test.js b/ghost/database-info/test/hello.test.js deleted file mode 100644 index 85d69d1e08..0000000000 --- a/ghost/database-info/test/hello.test.js +++ /dev/null @@ -1,10 +0,0 @@ -// Switch these lines once there are useful utils -// const testUtils = require('./utils'); -require('./utils'); - -describe('Hello world', function () { - it('Runs a test', function () { - // TODO: Write me! - 'hello'.should.eql('hello'); - }); -});