mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-28 23:11:17 -07:00
Fix: allow empty data for ntfy widget (#6653)
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
This commit is contained in:
@@ -1,5 +1,14 @@
|
||||
import { asJson } from "utils/proxy/api-helpers";
|
||||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
|
||||
const noMessages = {
|
||||
title: null,
|
||||
message: null,
|
||||
priority: 3,
|
||||
time: null,
|
||||
tags: [],
|
||||
};
|
||||
|
||||
const widget = {
|
||||
api: "{url}/{endpoint}",
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
@@ -7,6 +16,14 @@ const widget = {
|
||||
mappings: {
|
||||
messages: {
|
||||
endpoint: "{topic}/json?poll=1&since=latest",
|
||||
allowEmpty: true,
|
||||
map: (data) => {
|
||||
if (Buffer.isBuffer(data) && data.length === 0) {
|
||||
return noMessages;
|
||||
}
|
||||
|
||||
return asJson(data);
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { describe, it } from "vitest";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { expectWidgetConfigShape } from "test-utils/widget-config";
|
||||
|
||||
@@ -8,4 +8,18 @@ describe("ntfy widget config", () => {
|
||||
it("exports a valid widget config", () => {
|
||||
expectWidgetConfigShape(widget);
|
||||
});
|
||||
|
||||
it("maps an empty latest message response to the no messages state", () => {
|
||||
expect(widget.mappings.messages.map(Buffer.from(""))).toEqual({
|
||||
title: null,
|
||||
message: null,
|
||||
priority: 3,
|
||||
time: null,
|
||||
tags: [],
|
||||
});
|
||||
});
|
||||
|
||||
it("parses latest message responses", () => {
|
||||
expect(widget.mappings.messages.map(Buffer.from('{"message":"hello"}'))).toEqual({ message: "hello" });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user