From 614c0984d6b365387ad0024f3453a62f5fdf5a01 Mon Sep 17 00:00:00 2001 From: tgxn Date: Tue, 13 Jul 2021 13:05:58 +0200 Subject: [PATCH] Tests: Resolve tests following data directory changes --- lib/organize.js | 11 ++++++----- test/config.test.js | 4 ++-- test/memory.test.js | 4 ++-- test/organize.test.js | 17 ++++++++++------- test/testSetup.js | 9 +++++++-- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/lib/organize.js b/lib/organize.js index 550d61e..2abf0b3 100644 --- a/lib/organize.js +++ b/lib/organize.js @@ -13,6 +13,7 @@ const OrganizerLayer = require("./layer"); class Organize { constructor() { + this.dataLocations = {}; this.configArray = []; this.storageObject = null; } @@ -48,26 +49,26 @@ class Organize { } } - const dataLocations = { + this.dataLocations = { config: path.join(dataPath, "config.json"), storage: path.join(dataPath, "storage.json"), logsDir: path.join(dataPath, "logs/") }; - logger.info("data file paths", dataPath, dataLocations); + logger.info("data file paths", dataPath, this.dataLocations); if (enableFileLogs) { - addFileTransport(dataLocations.logsDir); + addFileTransport(this.dataLocations.logsDir); } try { - this.config = new Config(dataLocations.config); + this.config = new Config(this.dataLocations.config); this.configArray = await this.config.loadAndValidateConfig(); } catch (errors) { logger.error("Config Errors Found", errors); } try { - this.memory = new Memory(dataLocations.storage); + this.memory = new Memory(this.dataLocations.storage); await this.memory.loadStore(); } catch (errors) { logger.error("Error loading storage"); diff --git a/test/config.test.js b/test/config.test.js index ba21b3f..9ac012c 100644 --- a/test/config.test.js +++ b/test/config.test.js @@ -18,8 +18,8 @@ jest.mock("fs", () => ({ let config; test("parses home dir", () => { - config = new Config("~/configFile"); - expect(config.configPath).toBe(`${homedir}${path.sep}configFile`); + config = new Config("/tmp/configFile"); + expect(config.configPath).toBe(`/tmp/configFile`); expect(config.configArray).toStrictEqual([]); }); diff --git a/test/memory.test.js b/test/memory.test.js index b45c7ea..abdc90e 100644 --- a/test/memory.test.js +++ b/test/memory.test.js @@ -21,10 +21,10 @@ jest.mock("../lib/storage", () => { let memory; test("parses home dir storeFile", () => { - memory = new Memory("~/storeFile"); + memory = new Memory("/tmp/storeFile"); return memory.loadStore().then(() => { - expect(memory.storageFileLocation).toBe(`${homedir}${path.sep}storeFile`); + expect(memory.storageFileLocation).toBe(`/tmp/storeFile`); expect(memory.linkFiles).toStrictEqual({}); }); }); diff --git a/test/organize.test.js b/test/organize.test.js index 22ca8fd..ddd2226 100644 --- a/test/organize.test.js +++ b/test/organize.test.js @@ -2,11 +2,6 @@ const Organize = require("../lib/organize"); const configArray = require("../config.example.json"); -const configLocations = { - config: "./config.json", - storage: "./data/storage.json" -}; - let mockFileData = configArray; jest.mock("fs", () => ({ promises: { @@ -25,8 +20,16 @@ jest.mock("fs", () => ({ let organize; test("new Organize & loadConfig", async () => { - organize = new Organize(configLocations); - await organize.loadConfig(); + organize = new Organize(); + await organize.loadConfig({ + dataPathString: "/tmp", + enableFileLogs: false, + quietConsole: false + }); + + expect(organize.dataLocations.config).toBe("/tmp/config.json"); + expect(organize.dataLocations.storage).toBe(`/tmp/storage.json`); + expect(organize.dataLocations.logsDir).toBe(`/tmp/logs/`); }); test("organizeAll", async () => { diff --git a/test/testSetup.js b/test/testSetup.js index ede0064..32bbae2 100644 --- a/test/testSetup.js +++ b/test/testSetup.js @@ -1,6 +1,10 @@ jest.mock("winston", () => ({ format: { - simple: jest.fn() + simple: jest.fn(), + timestamp: jest.fn(), + cli: jest.fn(), + colorize: jest.fn(), + combine: jest.fn() }, transports: { Console: jest.fn(), @@ -9,7 +13,8 @@ jest.mock("winston", () => ({ info: jest.fn(), error: jest.fn(), debug: jest.fn(), - log: jest.fn() + log: jest.fn(), + add: jest.fn() })); jest.mock("winston-daily-rotate-file", () => ({