From 559ef1bc1101c3edf366b4cc225590af65b82f44 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Mon, 19 Mar 2018 15:25:53 +0100 Subject: [PATCH] Before we create a db instance we check for testing flag is set and then use the :MEMORY: database for a anonymous db instance. --- seasoned_api/src/database/database.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/seasoned_api/src/database/database.js b/seasoned_api/src/database/database.js index b71c357..4497ee0 100644 --- a/seasoned_api/src/database/database.js +++ b/seasoned_api/src/database/database.js @@ -1,8 +1,8 @@ const configuration = require('src/config/configuration').getInstance(); const SqliteDatabase = require('src/database/sqliteDatabase'); -const database = new SqliteDatabase(configuration.get('database', 'host')); - +const host = process.env.TESTING ? ':memory:' : configuration.get('database', 'host'); +const database = new SqliteDatabase(host); /** * This module establishes a connection to the database * specified in the confgiuration file. It tries to setup @@ -10,7 +10,6 @@ const database = new SqliteDatabase(configuration.get('database', 'host')); * If the tables already exists, it simply proceeds. */ Promise.resolve() - .then(() => database.connect()) .then(() => database.setUp()); module.exports = database;