kopia lustrzana https://gitlab.com/rysiekpl/libresilient
alt-fetch plugin tests: coverage 100%, all pass (ref. #8)
rodzic
257558904c
commit
ef71323cf9
|
@ -58,7 +58,7 @@ describe("plugin: alt-fetch", () => {
|
||||||
expect(self.LibResilientPlugins[0].name).toEqual('alt-fetch');
|
expect(self.LibResilientPlugins[0].name).toEqual('alt-fetch');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("it should fail upon bad config", () => {
|
test("it should fail with bad config", () => {
|
||||||
self.LibResilientConfig = {
|
self.LibResilientConfig = {
|
||||||
plugins: {
|
plugins: {
|
||||||
'alt-fetch':{
|
'alt-fetch':{
|
||||||
|
@ -70,7 +70,7 @@ describe("plugin: alt-fetch", () => {
|
||||||
expect(()=>{require("../../plugins/alt-fetch.js")}).toThrow(Error);
|
expect(()=>{require("../../plugins/alt-fetch.js")}).toThrow(Error);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("it should fetch the content", async () => {
|
test("it should fetch the content, trying all configured endpoints (if fewer or equal to concurrency setting)", async () => {
|
||||||
require("../../plugins/alt-fetch.js");
|
require("../../plugins/alt-fetch.js");
|
||||||
|
|
||||||
global.fetch.mockImplementation((url, init) => {
|
global.fetch.mockImplementation((url, init) => {
|
||||||
|
@ -92,7 +92,50 @@ describe("plugin: alt-fetch", () => {
|
||||||
|
|
||||||
const response = await self.LibResilientPlugins[0].fetch('https://resilient.is/test.json');
|
const response = await self.LibResilientPlugins[0].fetch('https://resilient.is/test.json');
|
||||||
|
|
||||||
expect(fetch).toHaveBeenCalled();
|
expect(fetch).toHaveBeenCalledTimes(3);
|
||||||
|
expect(await response.json()).toEqual({test: "success"})
|
||||||
|
expect(response.url).toEqual('https://resilient.is/test.json')
|
||||||
|
})
|
||||||
|
|
||||||
|
test("it should fetch the content using, trying <concurrency> random endpoints out of all configured (if more than concurrency setting)", async () => {
|
||||||
|
|
||||||
|
self.LibResilientConfig = {
|
||||||
|
plugins: {
|
||||||
|
'alt-fetch':{
|
||||||
|
endpoints: [
|
||||||
|
'https://alt.resilient.is/test.json',
|
||||||
|
'https://error.resilientis/test.json',
|
||||||
|
'https://timeout.resilientis/test.json',
|
||||||
|
'https://alt2.resilient.is/test.json',
|
||||||
|
'https://alt3.resilient.is/test.json',
|
||||||
|
'https://alt4.resilient.is/test.json'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
require("../../plugins/alt-fetch.js");
|
||||||
|
|
||||||
|
global.fetch.mockImplementation((url, init) => {
|
||||||
|
const response = new Response(
|
||||||
|
new Blob(
|
||||||
|
[JSON.stringify({ test: "success" })],
|
||||||
|
{type: "application/json"}
|
||||||
|
),
|
||||||
|
{
|
||||||
|
status: 200,
|
||||||
|
statusText: "OK",
|
||||||
|
headers: {
|
||||||
|
'ETag': 'TestingETagHeader'
|
||||||
|
},
|
||||||
|
url: url
|
||||||
|
});
|
||||||
|
return Promise.resolve(response);
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await self.LibResilientPlugins[0].fetch('https://resilient.is/test.json');
|
||||||
|
|
||||||
|
expect(fetch).toHaveBeenCalledTimes(3);
|
||||||
expect(await response.json()).toEqual({test: "success"})
|
expect(await response.json()).toEqual({test: "success"})
|
||||||
expect(response.url).toEqual('https://resilient.is/test.json')
|
expect(response.url).toEqual('https://resilient.is/test.json')
|
||||||
})
|
})
|
||||||
|
@ -102,7 +145,7 @@ describe("plugin: alt-fetch", () => {
|
||||||
|
|
||||||
const response = await self.LibResilientPlugins[0].fetch('https://resilient.is/test.json');
|
const response = await self.LibResilientPlugins[0].fetch('https://resilient.is/test.json');
|
||||||
|
|
||||||
expect(fetch).toHaveBeenCalled();
|
expect(fetch).toHaveBeenCalledTimes(3);
|
||||||
expect(await response.json()).toEqual({test: "success"})
|
expect(await response.json()).toEqual({test: "success"})
|
||||||
expect(response.url).toEqual('https://resilient.is/test.json')
|
expect(response.url).toEqual('https://resilient.is/test.json')
|
||||||
expect(response.headers.has('X-LibResilient-Method')).toEqual(true)
|
expect(response.headers.has('X-LibResilient-Method')).toEqual(true)
|
||||||
|
@ -133,7 +176,7 @@ describe("plugin: alt-fetch", () => {
|
||||||
|
|
||||||
const response = await self.LibResilientPlugins[0].fetch('https://resilient.is/test.json');
|
const response = await self.LibResilientPlugins[0].fetch('https://resilient.is/test.json');
|
||||||
|
|
||||||
expect(fetch).toHaveBeenCalled();
|
expect(fetch).toHaveBeenCalledTimes(3);
|
||||||
expect(await response.json()).toEqual({test: "success"})
|
expect(await response.json()).toEqual({test: "success"})
|
||||||
expect(response.url).toEqual('https://resilient.is/test.json')
|
expect(response.url).toEqual('https://resilient.is/test.json')
|
||||||
expect(response.headers.has('X-LibResilient-Method')).toEqual(true)
|
expect(response.headers.has('X-LibResilient-Method')).toEqual(true)
|
||||||
|
|
Ładowanie…
Reference in New Issue