From bd169f64cf381ddf8db3597166ee37e8f0024fad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=27rysiek=27=20Wo=C5=BAniak?= Date: Wed, 8 Sep 2021 11:40:37 +0000 Subject: [PATCH] gun-ipfs: stub of fetching test (ref. #8) --- __tests__/plugins/gun-ipfs.test.js | 52 +++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/__tests__/plugins/gun-ipfs.test.js b/__tests__/plugins/gun-ipfs.test.js index dae1163..d146e81 100644 --- a/__tests__/plugins/gun-ipfs.test.js +++ b/__tests__/plugins/gun-ipfs.test.js @@ -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(()=>{