kopia lustrzana https://gitlab.com/rysiekpl/libresilient
gun-ipfs: test content type guessing (ref. #8)
rodzic
d57cca412b
commit
ebba7e26d9
|
@ -12,9 +12,9 @@ describe("plugin: gun-ipfs", () => {
|
|||
}
|
||||
}
|
||||
}
|
||||
self.log = function(component, ...items) {
|
||||
self.log = jest.fn((component, ...items)=>{
|
||||
console.debug(component + ' :: ', ...items)
|
||||
}
|
||||
})
|
||||
global.Ipfs = {
|
||||
create: ()=>{
|
||||
return Promise.resolve({})
|
||||
|
@ -58,21 +58,6 @@ describe("plugin: gun-ipfs", () => {
|
|||
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.')
|
||||
})
|
||||
|
||||
test("fetching should error out for unpublished content", async ()=>{
|
||||
require("../../plugins/gun-ipfs.js");
|
||||
|
||||
|
@ -94,4 +79,58 @@ describe("plugin: gun-ipfs", () => {
|
|||
expect(e).toEqual(new Error('IPFS address is undefined for: /test/index.html'))
|
||||
}
|
||||
})
|
||||
|
||||
test("content types should be guessed correctly when fetching", async ()=>{
|
||||
require("../../plugins/gun-ipfs.js");
|
||||
|
||||
try {
|
||||
await self.LibResilientPlugins[0].fetch(self.location.origin + '/test/')
|
||||
} catch(e) {}
|
||||
expect(self.log).toHaveBeenCalledWith('gun-ipfs', " +-- guessed contentType : text/html")
|
||||
self.log.mockClear()
|
||||
|
||||
try {
|
||||
await self.LibResilientPlugins[0].fetch(self.location.origin + '/test.htm')
|
||||
} catch(e) {}
|
||||
expect(self.log).toHaveBeenCalledWith('gun-ipfs', " +-- guessed contentType : text/html")
|
||||
self.log.mockClear()
|
||||
|
||||
try {
|
||||
await self.LibResilientPlugins[0].fetch(self.location.origin + '/test.css')
|
||||
} catch(e) {}
|
||||
expect(self.log).toHaveBeenCalledWith('gun-ipfs', " +-- guessed contentType : text/css")
|
||||
self.log.mockClear()
|
||||
|
||||
try {
|
||||
await self.LibResilientPlugins[0].fetch(self.location.origin + '/test.js')
|
||||
} catch(e) {}
|
||||
expect(self.log).toHaveBeenCalledWith('gun-ipfs', " +-- guessed contentType : text/javascript")
|
||||
self.log.mockClear()
|
||||
|
||||
try {
|
||||
await self.LibResilientPlugins[0].fetch(self.location.origin + '/test.svg')
|
||||
} catch(e) {}
|
||||
expect(self.log).toHaveBeenCalledWith('gun-ipfs', " +-- guessed contentType : image/svg+xml")
|
||||
self.log.mockClear()
|
||||
|
||||
try {
|
||||
await self.LibResilientPlugins[0].fetch(self.location.origin + '/test.ico')
|
||||
} catch(e) {}
|
||||
expect(self.log).toHaveBeenCalledWith('gun-ipfs', " +-- guessed contentType : image/x-icon")
|
||||
})
|
||||
|
||||
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.')
|
||||
})
|
||||
});
|
||||
|
|
Ładowanie…
Reference in New Issue