Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -0,0 +1,86 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const getHostRoutingContextFromRequest = vi.fn();
|
||||
const loadAdminData = vi.fn();
|
||||
|
||||
vi.mock("~/utils/app/HostRouting.server", () => ({
|
||||
getHostRoutingContextFromRequest: (request: Request) => getHostRoutingContextFromRequest(request),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/data/.server/adminData", () => ({
|
||||
loadAdminData: (...args: unknown[]) => loadAdminData(...args),
|
||||
}));
|
||||
|
||||
vi.mock("~/locale/i18next.server", () => ({
|
||||
getTranslations: vi.fn(async () => ({ t: (key: string) => key })),
|
||||
}));
|
||||
|
||||
import { loader } from "./settings";
|
||||
|
||||
describe("canonical admin settings route", () => {
|
||||
beforeEach(() => {
|
||||
getHostRoutingContextFromRequest.mockReset();
|
||||
loadAdminData.mockReset();
|
||||
loadAdminData.mockResolvedValue({
|
||||
isSuperAdmin: false,
|
||||
permissions: ["admin_identity.sessions.read"],
|
||||
});
|
||||
});
|
||||
|
||||
it("redirects an authenticated admin to identity and security", async () => {
|
||||
getHostRoutingContextFromRequest.mockReturnValue("admin");
|
||||
|
||||
const response = await loader({
|
||||
request: new Request("http://admin.localhost:3000/settings"),
|
||||
params: {},
|
||||
context: {},
|
||||
} as never);
|
||||
|
||||
expect(loadAdminData).toHaveBeenCalledOnce();
|
||||
expect(response.status).toBe(302);
|
||||
expect(response.headers.get("location")).toBe("/settings/security");
|
||||
});
|
||||
|
||||
it("redirects a partial admin to the first settings route they may read", async () => {
|
||||
getHostRoutingContextFromRequest.mockReturnValue("admin");
|
||||
loadAdminData.mockResolvedValue({
|
||||
isSuperAdmin: false,
|
||||
permissions: ["admin.settings.general.view"],
|
||||
});
|
||||
|
||||
const response = await loader({
|
||||
request: new Request("http://admin.localhost:3000/settings"),
|
||||
params: {},
|
||||
context: {},
|
||||
} as never);
|
||||
|
||||
expect(response.status).toBe(302);
|
||||
expect(response.headers.get("location")).toBe("/settings/general");
|
||||
});
|
||||
|
||||
it("keeps settings hidden when the admin has no settings permission", async () => {
|
||||
getHostRoutingContextFromRequest.mockReturnValue("admin");
|
||||
loadAdminData.mockResolvedValue({ isSuperAdmin: false, permissions: [] });
|
||||
|
||||
await expect(
|
||||
loader({
|
||||
request: new Request("http://admin.localhost:3000/settings"),
|
||||
params: {},
|
||||
context: {},
|
||||
} as never)
|
||||
).rejects.toMatchObject({ status: 404 });
|
||||
});
|
||||
|
||||
it("keeps the canonical route unavailable outside the admin host", async () => {
|
||||
getHostRoutingContextFromRequest.mockReturnValue("app");
|
||||
|
||||
await expect(
|
||||
loader({
|
||||
request: new Request("http://app.localhost:3000/settings"),
|
||||
params: {},
|
||||
context: {},
|
||||
} as never)
|
||||
).rejects.toMatchObject({ status: 404 });
|
||||
expect(loadAdminData).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user