From 8b823a571d257bdb8807908ebe63c82148f908b4 Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Sat, 25 May 2024 18:17:50 +0100 Subject: [PATCH] Coverage 100% --- test/file/json/invalid.json | 1 + test/lib/datastore.js | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 test/file/json/invalid.json diff --git a/test/file/json/invalid.json b/test/file/json/invalid.json new file mode 100644 index 00000000..004e1e20 --- /dev/null +++ b/test/file/json/invalid.json @@ -0,0 +1 @@ +{,} diff --git a/test/lib/datastore.js b/test/lib/datastore.js index eae2a3a1..3e0f0802 100644 --- a/test/lib/datastore.js +++ b/test/lib/datastore.js @@ -169,6 +169,10 @@ describe("lib/datastore", function() { const loadedData = await datastoreProvider.load(); assert.equal(loadedData.size, 0); }); + it("throws for invalid file contents", async function() { + await fs.copy(path.join(testFiles, "json", "invalid.json"), dataPath); + await assert.rejects(() => datastoreProvider.load(dataPath)); + }); }); }); @@ -245,6 +249,10 @@ describe("lib/datastore", function() { const loadedData = await datastoreProvider.load(); assert.equal(loadedData.size, 0); }); + it("throws for invalid file contents", async function() { + await fs.copy(path.join(testFiles, "json", "invalid.json"), dataPath); + await assert.rejects(() => datastoreProvider.load(dataPath)); + }); }); }); @@ -386,15 +394,15 @@ describe("lib/datastore", function() { describe("getMutable", function() { it("returns the correct value", function() { - assert.equal(datastore.get("foo"), "fooValue"); - assert.equal(datastore.get("bar"), "barValue"); - assert.equal(datastore.get("baz"), "bazValue"); + assert.equal(datastore.getMutable("foo"), "fooValue"); + assert.equal(datastore.getMutable("bar"), "barValue"); + assert.equal(datastore.getMutable("baz"), "bazValue"); }); it("returns undefined correctly", function() { - assert.equal(datastore.get("missing1"), undefined); - assert.equal(datastore.get("missing2"), undefined); - assert.equal(datastore.get(1), undefined); - assert.equal(datastore.get(2), undefined); + assert.equal(datastore.getMutable("missing1"), undefined); + assert.equal(datastore.getMutable("missing2"), undefined); + assert.equal(datastore.getMutable(1), undefined); + assert.equal(datastore.getMutable(2), undefined); }); }); @@ -406,7 +414,7 @@ describe("lib/datastore", function() { describe("valuesMutable", function() { it("returns all values", function() { - assert.deepEqual([...datastore.values()], [...datastoreProvider.value.values()]); + assert.deepEqual([...datastore.valuesMutable()], [...datastoreProvider.value.values()]); }); }); });