kopia lustrzana https://gitlab.com/rysiekpl/libresilient
gun-ipfs plugin: some more tests (ref. #8), minor bugfix
rodzic
1b2fbb124d
commit
24ad9a10c8
|
@ -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.')
|
||||
})
|
||||
});
|
||||
|
|
|
@ -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'!
|
||||
|
|
Ładowanie…
Reference in New Issue