gun-ipfs: stub of fetching test (ref. #8)

merge-requests/3/merge
Michał 'rysiek' Woźniak 2021-09-08 11:40:37 +00:00
rodzic a9368d4394
commit bd169f64cf
1 zmienionych plików z 51 dodań i 1 usunięć

Wyświetl plik

@ -17,7 +17,35 @@ describe("plugin: gun-ipfs", () => {
})
global.Ipfs = {
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
@ -125,6 +153,28 @@ describe("plugin: gun-ipfs", () => {
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 ()=>{
require("../../plugins/gun-ipfs.js");
expect(()=>{