Add no-param-reassign from eslint (#3089)

While waiting for the easterbunny I cleaned up some bad coding practice
:-)

Very open for comments especially regarding the places I commented
myself...

---------

Co-authored-by: veeck <michael@veeck.de>
This commit is contained in:
Veeck
2023-04-16 17:38:39 +02:00
committed by GitHub
parent 979f4ec664
commit 7e58b38ddf
18 changed files with 245 additions and 237 deletions

View File

@@ -4,21 +4,19 @@ const { performWebRequest, formatTime } = require("../../../../modules/default/u
const nodeVersion = process.version.match(/^v(\d+)\.*/)[1];
describe("Default modules utils tests", () => {
describe("The performWebRequest-method", () => {
describe("performWebRequest", () => {
if (nodeVersion > 18) {
const locationHost = "localhost:8080";
const locationProtocol = "http";
let fetchResponse;
let fetchMock;
let url;
let urlToCall;
beforeEach(() => {
fetchResponse = new Response();
global.fetch = jest.fn(() => Promise.resolve(fetchResponse));
fetchMock = global.fetch;
url = "www.test.com";
});
describe("When using cors proxy", () => {
@@ -30,24 +28,23 @@ describe("Default modules utils tests", () => {
});
test("Calls correct URL once", async () => {
const urlToCall = "http://www.test.com/path?param1=value1";
url = urlToCall;
urlToCall = "http://www.test.com/path?param1=value1";
await performWebRequest(url, "json", true);
await performWebRequest(urlToCall, "json", true);
expect(fetchMock.mock.calls.length).toBe(1);
expect(fetchMock.mock.calls[0][0]).toBe(`${locationProtocol}//${locationHost}/cors?url=${urlToCall}`);
});
test("Sends correct headers", async () => {
const urlToCall = "http://www.test.com/path?param1=value1";
url = urlToCall;
urlToCall = "http://www.test.com/path?param1=value1";
const headers = [
{ name: "header1", value: "value1" },
{ name: "header2", value: "value2" }
];
await performWebRequest(url, "json", true, headers);
await performWebRequest(urlToCall, "json", true, headers);
expect(fetchMock.mock.calls.length).toBe(1);
expect(fetchMock.mock.calls[0][0]).toBe(`${locationProtocol}//${locationHost}/cors?sendheaders=header1:value1,header2:value2&url=${urlToCall}`);
@@ -56,24 +53,22 @@ describe("Default modules utils tests", () => {
describe("When not using cors proxy", () => {
test("Calls correct URL once", async () => {
const urlToCall = "http://www.test.com/path?param1=value1";
url = urlToCall;
urlToCall = "http://www.test.com/path?param1=value1";
await performWebRequest(url);
await performWebRequest(urlToCall);
expect(fetchMock.mock.calls.length).toBe(1);
expect(fetchMock.mock.calls[0][0]).toBe(urlToCall);
});
test("Sends correct headers", async () => {
const urlToCall = "http://www.test.com/path?param1=value1";
url = urlToCall;
urlToCall = "http://www.test.com/path?param1=value1";
const headers = [
{ name: "header1", value: "value1" },
{ name: "header2", value: "value2" }
];
await performWebRequest(url, "json", false, headers);
await performWebRequest(urlToCall, "json", false, headers);
const expectedHeaders = { headers: { header1: "value1", header2: "value2" } };
expect(fetchMock.mock.calls.length).toBe(1);
@@ -83,23 +78,27 @@ describe("Default modules utils tests", () => {
describe("When receiving json format", () => {
test("Returns undefined when no data is received", async () => {
const response = await performWebRequest(url);
urlToCall = "www.test.com";
const response = await performWebRequest(urlToCall);
expect(response).toBe(undefined);
});
test("Returns object when data is received", async () => {
urlToCall = "www.test.com";
fetchResponse = new Response('{"body": "some content"}');
const response = await performWebRequest(url);
const response = await performWebRequest(urlToCall);
expect(response.body).toBe("some content");
});
test("Returns expected headers when data is received", async () => {
urlToCall = "www.test.com";
fetchResponse = new Response('{"body": "some content"}', { headers: { header1: "value1", header2: "value2" } });
const response = await performWebRequest(url, "json", false, undefined, ["header1"]);
const response = await performWebRequest(urlToCall, "json", false, undefined, ["header1"]);
expect(response.headers.length).toBe(1);
expect(response.headers[0].name).toBe("header1");