mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
Release 2.24.0 (#3141)
Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Karsten Hassel <hassel@gmx.de> Co-authored-by: Malte Hallström <46646495+SkySails@users.noreply.github.com> Co-authored-by: Veeck <github@veeck.de> Co-authored-by: veeck <michael@veeck.de> Co-authored-by: dWoolridge <dwoolridge@charter.net> Co-authored-by: Johan <jojjepersson@yahoo.se> Co-authored-by: Dario Mratovich <dario_mratovich@hotmail.com> Co-authored-by: Dario Mratovich <dario.mratovich@outlook.com> Co-authored-by: Magnus <34011212+MagMar94@users.noreply.github.com> Co-authored-by: Naveen <172697+naveensrinivasan@users.noreply.github.com> Co-authored-by: buxxi <buxxi@omfilm.net> Co-authored-by: Thomas Hirschberger <47733292+Tom-Hirschberger@users.noreply.github.com> Co-authored-by: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Co-authored-by: Andrés Vanegas Jiménez <142350+angeldeejay@users.noreply.github.com> Co-authored-by: Dave Child <dave@addedbytes.com> Co-authored-by: grenagit <46225780+grenagit@users.noreply.github.com> Co-authored-by: Grena <grena@grenabox.fr> Co-authored-by: Magnus Marthinsen <magmar@online.no> Co-authored-by: Patrick <psieg@users.noreply.github.com> Co-authored-by: Piotr Rajnisz <56397164+rajniszp@users.noreply.github.com> Co-authored-by: Suthep Yonphimai <tomzt@users.noreply.github.com> Co-authored-by: CarJem Generations (Carter Wallace) <cwallacecs@gmail.com> Co-authored-by: Nicholas Fogal <nfogal.misc@gmail.com> Co-authored-by: JakeBinney <126349119+JakeBinney@users.noreply.github.com> Co-authored-by: OWL4C <124401812+OWL4C@users.noreply.github.com> Co-authored-by: Oscar Björkman <17575446+oscarb@users.noreply.github.com> Co-authored-by: Ismar Slomic <ismar@slomic.no> Co-authored-by: Jørgen Veum-Wahlberg <jorgen.wahlberg@amedia.no> Co-authored-by: Eddie Hung <6740044+eddiehung@users.noreply.github.com> Co-authored-by: Bugsounet - Cédric <github@bugsounet.fr> Co-authored-by: bugsounet <bugsounet@bugsounet.fr> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,23 +1,22 @@
|
||||
const { performWebRequest } = require("../../../../modules/default/utils");
|
||||
global.moment = require("moment-timezone");
|
||||
const { performWebRequest, formatTime } = require("../../../../modules/default/utils");
|
||||
|
||||
const nodeVersion = process.version.match(/^v(\d+)\.*/)[1];
|
||||
|
||||
describe("Utils tests", () => {
|
||||
describe("The performWebRequest-method", () => {
|
||||
describe("Default modules utils tests", () => {
|
||||
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", () => {
|
||||
@@ -29,24 +28,23 @@ describe("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}`);
|
||||
@@ -55,24 +53,22 @@ describe("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);
|
||||
@@ -82,23 +78,27 @@ describe("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");
|
||||
@@ -109,4 +109,64 @@ describe("Utils tests", () => {
|
||||
test("Always ok, need one test", () => {});
|
||||
}
|
||||
});
|
||||
|
||||
describe("formatTime", () => {
|
||||
const time = new Date();
|
||||
|
||||
beforeEach(async () => {
|
||||
time.setHours(13, 13);
|
||||
});
|
||||
|
||||
it("should convert correctly according to the config", () => {
|
||||
expect(
|
||||
formatTime(
|
||||
{
|
||||
timeFormat: 24
|
||||
},
|
||||
time
|
||||
)
|
||||
).toBe("13:13");
|
||||
expect(
|
||||
formatTime(
|
||||
{
|
||||
showPeriod: true,
|
||||
showPeriodUpper: true,
|
||||
timeFormat: 12
|
||||
},
|
||||
time
|
||||
)
|
||||
).toBe("1:13 PM");
|
||||
expect(
|
||||
formatTime(
|
||||
{
|
||||
showPeriod: true,
|
||||
showPeriodUpper: false,
|
||||
timeFormat: 12
|
||||
},
|
||||
time
|
||||
)
|
||||
).toBe("1:13 pm");
|
||||
expect(
|
||||
formatTime(
|
||||
{
|
||||
showPeriod: false,
|
||||
timeFormat: 12
|
||||
},
|
||||
time
|
||||
)
|
||||
).toBe("1:13");
|
||||
});
|
||||
|
||||
it("should convert correctly into another timezone", () => {
|
||||
expect(
|
||||
formatTime(
|
||||
{
|
||||
timeFormat: 24,
|
||||
timezone: "America/Toronto"
|
||||
},
|
||||
time
|
||||
)
|
||||
).toBe("07:13");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user