kopia lustrzana https://gitlab.com/rysiekpl/libresilient
gun-ipfs: stub of fetching test (ref. #8)
rodzic
a9368d4394
commit
bd169f64cf
|
@ -17,7 +17,35 @@ describe("plugin: gun-ipfs", () => {
|
||||||
})
|
})
|
||||||
global.Ipfs = {
|
global.Ipfs = {
|
||||||
create: ()=>{
|
create: ()=>{
|
||||||
return Promise.resolve({})
|
return Promise.resolve({
|
||||||
|
get: ()=>{
|
||||||
|
return {
|
||||||
|
next: ()=>{
|
||||||
|
sourceUsed = true
|
||||||
|
return Promise.resolve({
|
||||||
|
value: {
|
||||||
|
path: 'some-ipfs-looking-address',
|
||||||
|
content: {
|
||||||
|
next: ()=>{
|
||||||
|
sourceUsed = !sourceUsed
|
||||||
|
return Promise.resolve({
|
||||||
|
done: sourceUsed,
|
||||||
|
value: Uint8Array.from(
|
||||||
|
Array
|
||||||
|
.from('{test: "success"}')
|
||||||
|
.map(
|
||||||
|
letter => letter.charCodeAt(0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.Ipfs = global.Ipfs
|
self.Ipfs = global.Ipfs
|
||||||
|
@ -125,6 +153,28 @@ describe("plugin: gun-ipfs", () => {
|
||||||
expect(self.log).toHaveBeenCalledWith('gun-ipfs', " +-- guessed contentType : image/x-icon")
|
expect(self.log).toHaveBeenCalledWith('gun-ipfs', " +-- guessed contentType : image/x-icon")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("fetching should work (stub!)", async ()=>{
|
||||||
|
self.gunUser = jest.fn(()=>{
|
||||||
|
return {
|
||||||
|
get: () => {
|
||||||
|
return {
|
||||||
|
get: ()=>{
|
||||||
|
return {
|
||||||
|
once: (arg)=>{ arg('some-ipfs-looking-address') }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
require("../../plugins/gun-ipfs.js");
|
||||||
|
|
||||||
|
await self.Ipfs.create()
|
||||||
|
let response = await self.LibResilientPlugins[0].fetch(self.location.origin + '/test.json')
|
||||||
|
expect(response.body.type).toEqual('application/json')
|
||||||
|
expect(String.fromCharCode.apply(null, response.body.parts[0])).toEqual('{test: "success"}')
|
||||||
|
})
|
||||||
|
|
||||||
test("publishContent should error out if passed anything else than string or array of string", async ()=>{
|
test("publishContent should error out if passed anything else than string or array of string", async ()=>{
|
||||||
require("../../plugins/gun-ipfs.js");
|
require("../../plugins/gun-ipfs.js");
|
||||||
expect(()=>{
|
expect(()=>{
|
||||||
|
|
Ładowanie…
Reference in New Issue