diff --git a/src/widgets/authentik/component.jsx b/src/widgets/authentik/component.jsx index f646179cd..d90ffdf90 100644 --- a/src/widgets/authentik/component.jsx +++ b/src/widgets/authentik/component.jsx @@ -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), diff --git a/src/widgets/authentik/component.test.jsx b/src/widgets/authentik/component.test.jsx index 4b1688391..163f4c234 100644 --- a/src/widgets/authentik/component.test.jsx +++ b/src/widgets/authentik/component.test.jsx @@ -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( + , + { settings: { hideErrors: false } }, + ); + + expectBlockValue(container, "authentik.users", 5); + expectBlockValue(container, "authentik.loginsLast24H", 2); + expectBlockValue(container, "authentik.failedLoginsLast24H", 1); + }); });