mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-25 13:31:20 -07:00
Fix: ensure authentik widget v1 fallback (#6991)
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:
@@ -35,7 +35,8 @@ export default function Component({ service }) {
|
||||
let loginsLast24H;
|
||||
let failedLoginsLast24H;
|
||||
switch (widget.version) {
|
||||
case 1:
|
||||
// v1 is default
|
||||
default:
|
||||
const yesterday = new Date(Date.now()).setHours(-24);
|
||||
loginsLast24H = loginsData.reduce(
|
||||
(total, current) => (current.x_cord >= yesterday ? total + current.y_cord : total),
|
||||
|
||||
@@ -99,4 +99,28 @@ describe("widgets/authentik/component", () => {
|
||||
expectBlockValue(container, "authentik.loginsLast24H", 2);
|
||||
expectBlockValue(container, "authentik.failedLoginsLast24H", 1);
|
||||
});
|
||||
|
||||
it("falls back to v1 when no version is configured", () => {
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(new Date("2026-01-02T00:00:00Z"));
|
||||
|
||||
const oneHourAgo = Date.now() - 60 * 60 * 1000;
|
||||
|
||||
useWidgetAPI.mockImplementation((widget, endpoint) => {
|
||||
if (endpoint === "users") return { data: { pagination: { count: 5 } }, error: undefined };
|
||||
if (endpoint === "login") return { data: [{ x_cord: oneHourAgo, y_cord: 2 }], error: undefined };
|
||||
if (endpoint === "login_failed") return { data: [{ x_cord: oneHourAgo, y_cord: 1 }], error: undefined };
|
||||
return { data: undefined, error: undefined };
|
||||
});
|
||||
|
||||
// service-helpers sets version to null when the key is absent
|
||||
const { container } = renderWithProviders(
|
||||
<Component service={{ widget: { type: "authentik", version: null } }} />,
|
||||
{ settings: { hideErrors: false } },
|
||||
);
|
||||
|
||||
expectBlockValue(container, "authentik.users", 5);
|
||||
expectBlockValue(container, "authentik.loginsLast24H", 2);
|
||||
expectBlockValue(container, "authentik.failedLoginsLast24H", 1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user