diff --git a/__tests__/plugins/gun-ipfs.test.js b/__tests__/plugins/gun-ipfs.test.js index d20a58c..d8bdf64 100644 --- a/__tests__/plugins/gun-ipfs.test.js +++ b/__tests__/plugins/gun-ipfs.test.js @@ -15,9 +15,50 @@ describe("plugin: gun-ipfs", () => { self.log = function(component, ...items) { console.debug(component + ' :: ', ...items) } + self.Ipfs = { + create: ()=>{ + return Promise.resolve({}) + } + } + self.gunUser = jest.fn(()=>{ + return {} + }) + global.Gun = jest.fn((nodes)=>{ + return { + user: self.gunUser + } + }) }) + test("it should register in LibResilientPlugins", () => { require("../../plugins/gun-ipfs.js"); expect(self.LibResilientPlugins[0].name).toEqual('gun-ipfs'); }); + + test("IPFS setup should be initiated", ()=>{ + self.importScripts = jest.fn() + require("../../plugins/gun-ipfs.js"); + expect(self.importScripts).toHaveBeenNthCalledWith(1, './lib/ipfs.js') + }) + + test("Gun setup should be initiated", ()=>{ + self.importScripts = jest.fn() + require("../../plugins/gun-ipfs.js"); + expect(self.importScripts).toHaveBeenNthCalledWith(2, "./lib/gun.js", "./lib/sea.js", "./lib/webrtc.js") + }) + + test("publishContent should error out if passed anything else than string or array of string", async ()=>{ + require("../../plugins/gun-ipfs.js"); + expect(()=>{ + self.LibResilientPlugins[0].publish({ + url: self.location.origin + '/test.json' + }) + }).toThrow('Handling a Response: not implemented yet') + expect(()=>{ + self.LibResilientPlugins[0].publish(true) + }).toThrow('Only accepts: string, Array of string, Response.') + expect(()=>{ + self.LibResilientPlugins[0].publish([true, 5]) + }).toThrow('Only accepts: string, Array of string, Response.') + }) }); diff --git a/plugins/gun-ipfs.js b/plugins/gun-ipfs.js index 89e2301..b0c4ed4 100644 --- a/plugins/gun-ipfs.js +++ b/plugins/gun-ipfs.js @@ -449,6 +449,12 @@ if (typeof window === 'undefined') { // but that would require all called functions to also accept a Response // and act accordingly; #ThisIsComplicated throw new Error("Handling a Response: not implemented yet") + } else { + resource.forEach((res)=>{ + if (typeof res !== 'string') { + throw new TypeError("Only accepts: string, Array of string, Response.") + } + }) } } else { // everything else -- that's a paddlin'!