diff --git a/test/plugins/sqlite.js b/test/plugins/sqlite.js index 2826d784..0971d00f 100644 --- a/test/plugins/sqlite.js +++ b/test/plugins/sqlite.js @@ -16,13 +16,13 @@ describe("SQLite Message Storage", function () { const expectedPath = path.join(Helper.getHomePath(), "logs", "testUser.sqlite3"); let store; - // Delete database file from previous test run before(function (done) { store = new MessageStorage({ name: "testUser", idMsg: 1, }); + // Delete database file from previous test run if (fs.existsSync(expectedPath)) { fs.unlink(expectedPath, done); } else { @@ -30,6 +30,13 @@ describe("SQLite Message Storage", function () { } }); + after(function (done) { + // After tests run, remove the logs folder + // so we return to the clean state + fs.unlinkSync(expectedPath); + fs.rmdir(path.join(Helper.getHomePath(), "logs"), done); + }); + it("should resolve an empty array when disabled", function (done) { store.getMessages(null, null).then((messages) => { expect(messages).to.be.empty; diff --git a/test/plugins/storage.js b/test/plugins/storage.js index 145e7c70..9d3bbc8f 100644 --- a/test/plugins/storage.js +++ b/test/plugins/storage.js @@ -6,6 +6,7 @@ const crypto = require("crypto"); const expect = require("chai").expect; const util = require("../util"); const Helper = require("../../src/helper"); +const storage = require("../../src/plugins/storage"); const link = require("../../src/plugins/irc-events/link.js"); describe("Image storage", function () { @@ -51,6 +52,13 @@ describe("Image storage", function () { this.connection.close(done); }); + after(function (done) { + // After storage tests run, remove the remaining empty + // storage folder so we return to the clean state + const dir = Helper.getStoragePath(); + fs.rmdir(dir, done); + }); + beforeEach(function () { this.irc = util.createClient(); this.network = util.createNetwork(); @@ -125,4 +133,13 @@ describe("Image storage", function () { done(); }); }); + + it("should clear storage folder", function () { + const dir = Helper.getStoragePath(); + + expect(fs.readdirSync(dir)).to.not.be.empty; + storage.emptyDir(); + expect(fs.readdirSync(dir)).to.be.empty; + expect(fs.existsSync(dir)).to.be.true; + }); });