Skip to content

Commit

Permalink
Tests: Resolve tests following data directory changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tgxn committed Jul 13, 2021
1 parent 95cf457 commit 614c098
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
11 changes: 6 additions & 5 deletions lib/organize.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const OrganizerLayer = require("./layer");

class Organize {
constructor() {
this.dataLocations = {};
this.configArray = [];
this.storageObject = null;
}
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
});

Expand Down
4 changes: 2 additions & 2 deletions test/memory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({});
});
});
Expand Down
17 changes: 10 additions & 7 deletions test/organize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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 () => {
Expand Down
9 changes: 7 additions & 2 deletions test/testSetup.js
Original file line number Diff line number Diff line change
@@ -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(),
Expand All @@ -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", () => ({
Expand Down

0 comments on commit 614c098

Please sign in to comment.