* Add push notifications support * fix(notifications): address push notification review findings - Gate the capability endpoint's apple_push availability on the admin delivery toggle, matching web push: Available now means setup will actually deliver. - Reject direct admin writes to push_relay_deployment_id/api_key; the relay issues them as a pair during registration and a lone write desyncs them (and poisons the next rotation request). - Purge a device's registrations under other profiles when it re-registers, so a profile switch on a shared device stops the old profile's pushes (attempts cascade); adds a DB-backed test. - Extract the shared channelDispatcher core + retry sweep and rebuild the webhook/web push/Apple push dispatchers on it instead of keeping three copies of the worker-pool/retry loop. - Deduplicate relay URL validation (admin setting + register flow) and the push outbox attempt-building loops behind shared helpers. - Cap free-text decline reasons in notification display bodies. - Fix TestHandleApplePushDisplayDB expectations to match the shared display copy (test previously failed under SILO_TEST_DATABASE_URL). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(notifications): route push relay URL writes through registration only Direct writes to notifications.push_relay_url via the admin settings endpoint bypassed the relay registration flow, letting the stored URL drift out of sync with the deployment id / API key pair the relay minted for it. Reject the URL alongside the deployment id and API key in the settings handler; POST /admin/notifications/push/relay/register remains the only path that persists all three together. The admin UI's Relay URL field now edits local draft state and is applied by the Register/Rotate action instead of the settings save. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
121 lines
3.6 KiB
TypeScript
121 lines
3.6 KiB
TypeScript
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { MemoryRouter } from "react-router";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import AdminSettingsLayout from "./AdminSettingsLayout";
|
|
|
|
// The layout only needs the active tab's component to render; a loading form
|
|
// keeps every settings page on its skeleton state so no other hooks fire.
|
|
vi.mock("@/hooks/useSettingsForm", () => ({
|
|
useSettingsForm: () => ({ isLoading: true }),
|
|
}));
|
|
|
|
function renderLayout(search = "") {
|
|
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
|
|
return renderToStaticMarkup(
|
|
<QueryClientProvider client={client}>
|
|
<MemoryRouter initialEntries={[`/admin/settings${search}`]}>
|
|
<AdminSettingsLayout />
|
|
</MemoryRouter>
|
|
</QueryClientProvider>,
|
|
);
|
|
}
|
|
|
|
function renderInteractiveLayout(search = "") {
|
|
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
|
|
return render(
|
|
<QueryClientProvider client={client}>
|
|
<MemoryRouter initialEntries={[`/admin/settings${search}`]}>
|
|
<AdminSettingsLayout />
|
|
</MemoryRouter>
|
|
</QueryClientProvider>,
|
|
);
|
|
}
|
|
|
|
describe("AdminSettingsLayout", () => {
|
|
it("renders the grouped navigation sections", () => {
|
|
const markup = renderLayout();
|
|
|
|
for (const group of ["Server", "Media", "Connections", "Data"]) {
|
|
expect(markup).toContain(`>${group}<`);
|
|
}
|
|
});
|
|
|
|
it("renders every settings tab", () => {
|
|
const markup = renderLayout();
|
|
|
|
for (const label of [
|
|
"General",
|
|
"Theming",
|
|
"Card Overlays",
|
|
"Scanner & Matcher",
|
|
"Intro Markers",
|
|
"Subtitles",
|
|
"AI Services",
|
|
"Playback",
|
|
"Downloads",
|
|
"Watch Providers",
|
|
"Integrations",
|
|
"Email",
|
|
"Notifications",
|
|
"Compatibility Proxies",
|
|
"Rate Limiting",
|
|
"Database",
|
|
"Storage",
|
|
"Log Retention",
|
|
]) {
|
|
expect(markup).toContain(label);
|
|
}
|
|
});
|
|
|
|
it("defaults to the General tab", () => {
|
|
const markup = renderLayout();
|
|
|
|
expect(markup).toContain('aria-current="page"');
|
|
expect(markup).toBe(renderLayout("?tab=general"));
|
|
});
|
|
|
|
it("resolves the legacy jellyfin tab alias to Compatibility Proxies", () => {
|
|
const withAlias = renderLayout("?tab=jellyfin");
|
|
const direct = renderLayout("?tab=compatibility-proxies");
|
|
|
|
expect(withAlias).toBe(direct);
|
|
});
|
|
|
|
it("filters admin settings sections from the search box", async () => {
|
|
renderInteractiveLayout();
|
|
|
|
await userEvent.type(screen.getByRole("searchbox", { name: "Search settings" }), "redis");
|
|
|
|
expect(screen.getAllByRole("button", { name: /Database/ })).toHaveLength(2);
|
|
expect(screen.queryByRole("button", { name: /Playback/ })).not.toBeInTheDocument();
|
|
expect(screen.getByText("1 match")).toBeInTheDocument();
|
|
});
|
|
|
|
it("matches individual admin setting labels", async () => {
|
|
renderInteractiveLayout();
|
|
|
|
await userEvent.type(
|
|
screen.getByRole("searchbox", { name: "Search settings" }),
|
|
"pool max open",
|
|
);
|
|
|
|
expect(screen.getAllByRole("button", { name: /Database/ })).toHaveLength(2);
|
|
expect(screen.queryByRole("button", { name: /General/ })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("focuses admin settings search with Cmd+K", () => {
|
|
renderInteractiveLayout();
|
|
|
|
const searchBox = screen.getByRole("searchbox", { name: "Search settings" });
|
|
fireEvent.keyDown(document, { key: "k", metaKey: true });
|
|
|
|
expect(searchBox).toHaveFocus();
|
|
});
|
|
});
|