merge-requests/14/merge
Michał 'rysiek' Woźniak 2022-06-22 20:34:30 +00:00
rodzic dddb1c57bf
commit 6bef03ef0b
1 zmienionych plików z 50 dodań i 13 usunięć

Wyświetl plik

@ -95,17 +95,17 @@ describe("plugin: alt-fetch", () => {
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 () => {
test("it should fetch the content, trying <concurrency> random endpoints out of all configured (if more than concurrency setting)", async () => {
init = {
name: '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'
'https://alt.resilient.is/',
'https://error.resilient.is/',
'https://timeout.resilient.is/',
'https://alt2.resilient.is/',
'https://alt3.resilient.is/',
'https://alt4.resilient.is/'
]}
require("../../../plugins/alt-fetch/index.js");
@ -134,17 +134,54 @@ describe("plugin: alt-fetch", () => {
expect(response.url).toEqual('https://resilient.is/test.json')
})
test("it should fetch the content, trying all endpoints (if fewer than concurrency setting)", async () => {
init = {
name: 'alt-fetch',
endpoints: [
'https://alt.resilient.is/',
'https://error.resilient.is/'
]}
require("../../../plugins/alt-fetch/index.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 LibResilientPluginConstructors.get('alt-fetch')(LR, init).fetch('https://resilient.is/test.json');
expect(fetch).toHaveBeenCalledTimes(2);
expect(fetch).toHaveBeenNthCalledWith(1, 'https://alt.resilient.is/test.json', {"cache": "reload"});
expect(fetch).toHaveBeenNthCalledWith(2, 'https://error.resilient.is/test.json', {"cache": "reload"});
expect(await response.json()).toEqual({test: "success"})
expect(response.url).toEqual('https://resilient.is/test.json')
})
test("it should pass the Request() init data to fetch() for all used endpoints", async () => {
init = {
name: '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'
'https://alt.resilient.is/',
'https://error.resilient.is/',
'https://timeout.resilient.is/',
'https://alt2.resilient.is/',
'https://alt3.resilient.is/',
'https://alt4.resilient.is/'
]}
require("../../../plugins/alt-fetch/index.js");