From 2d5c0c3bbf4f4054e33f2683314deffd6142aa53 Mon Sep 17 00:00:00 2001 From: Danielv123 Date: Fri, 13 Apr 2018 16:37:57 +0200 Subject: [PATCH] More tests for remoteMap --- sharedPlugins/remoteMap/chunkStore.js | 2 +- sharedPlugins/remoteMap/chunkStore.spec.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/sharedPlugins/remoteMap/chunkStore.js b/sharedPlugins/remoteMap/chunkStore.js index f8a4ee66..7146f75b 100644 --- a/sharedPlugins/remoteMap/chunkStore.js +++ b/sharedPlugins/remoteMap/chunkStore.js @@ -14,8 +14,8 @@ let log = string => (allowLogging)? console.log(string):"" module.exports = class chunkStore { constructor(name, chunkSize = 32, path = "./chunkStore/"){ + if(!name || (typeof name != "string" && typeof name != "number")) throw new Error("chunkstore requires a name string as first param"); name = name.toString(); - if(!name || typeof name != "string") throw new Error("chunkstore requires a name string as first param") this.name = name; this.chunkSize = chunkSize; this.path = (path[path.length] == "/") ? path : path+"/"; diff --git a/sharedPlugins/remoteMap/chunkStore.spec.js b/sharedPlugins/remoteMap/chunkStore.spec.js index 8ea663ba..fbd325ca 100644 --- a/sharedPlugins/remoteMap/chunkStore.spec.js +++ b/sharedPlugins/remoteMap/chunkStore.spec.js @@ -46,4 +46,19 @@ describe("remoteMap/chunkStore.js", () => { },300); }); }); + describe("validates input by throwing when it is invalid", ()=>{ + it("throws if called without a string as the first parameter", ()=>{ + assert.throws(()=>{ + let throwingChunkStore = new chunkStore(undefined, undefined, "asdasda"); + }); + assert.throws(()=>{ + let throwingChunkStore = new chunkStore({}, undefined, "asdasdas"); + }); + }); + it("converts numbers to strings automatically if they are provided as the first parameter", ()=>{ + assert.ok(()=>{ + let nonThrowingChunkStore = new chunkStore(42, undefined, "./database/unitTests/chunkStore/"); + }); + }); + }); });