gun-ipfs plugin: some more tests (ref. #8), minor bugfix

merge-requests/3/merge
Michał 'rysiek' Woźniak 2021-09-07 16:41:13 +00:00
rodzic 1b2fbb124d
commit 24ad9a10c8
2 zmienionych plików z 47 dodań i 0 usunięć

Wyświetl plik

@ -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.')
})
});

Wyświetl plik

@ -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'!