Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/routes/app.$tenant/integrations.calendar-routing.test.ts
T

121 lines
5.2 KiB
TypeScript

// AK-P16a reachability (DoD B.6): the "google-calendar" catalog entry must lead
// to the calendar module's per-user connection surface, never to the generic
// DataConnection detail (which would always show zero connections and whose
// connect wizard would bypass the Google OAuth flow). Mirrors the Aircall
// routing contract in integrations.aircall-routing.test.ts.
import { beforeEach, describe, expect, it, vi } from "vitest";
const mocks = vi.hoisted(() => ({
context: {
tenantId: "tenant_1",
userId: "user_1",
permissions: ["integrations.read", "integrations.connect", "integrations.disconnect"],
hasModule: true,
},
loadIntegrationsContext: vi.fn(),
listConnections: vi.fn(),
createConnection: vi.fn(),
reconnectConnection: vi.fn(),
disconnectConnection: vi.fn(),
runSyncForConnection: vi.fn(),
hasKwpIntegrationModule: vi.fn(),
requireKwpIntegrationModule: vi.fn(),
}));
vi.mock("~/components/screens/integrations/IntegrationsCatalogPage", () => ({
IntegrationsCatalogPage: () => null,
}));
vi.mock("~/components/screens/integrations/ConnectionDetailPage", () => ({
ConnectionDetailPage: () => null,
}));
vi.mock("~/components/ui/errors/ServerError", () => ({ default: () => null }));
vi.mock("~/locale/i18next.server", () => ({
getTranslations: () => Promise.resolve({ t: (key: string) => key }),
}));
vi.mock("~/utils/integrations/integrationsAccess.server", () => ({
badRequestResponse: () => new Response("Bad Request", { status: 400 }),
integrationsActionErrorResponse: () => new Response("Bad Request", { status: 400 }),
integrationsHasPermission: () => true,
loadIntegrationsContext: mocks.loadIntegrationsContext,
notFoundResponse: () => new Response("Not Found", { status: 404 }),
requireIntegrationsPermission: () => undefined,
}));
vi.mock("~/utils/integrations/appsEngineService.server", () => ({
createConnection: mocks.createConnection,
disconnectConnection: mocks.disconnectConnection,
listConnections: mocks.listConnections,
reconnectConnection: mocks.reconnectConnection,
runSyncForConnection: mocks.runSyncForConnection,
}));
vi.mock("~/modules/kwp/routes/kwpAccess.server", () => ({
hasKwpIntegrationModule: mocks.hasKwpIntegrationModule,
requireKwpIntegrationModule: mocks.requireKwpIntegrationModule,
}));
import { loader as catalogLoader } from "./integrations._index";
import { action as appAction, loader as appLoader } from "./integrations.$app._index";
beforeEach(() => {
vi.clearAllMocks();
mocks.loadIntegrationsContext.mockResolvedValue(mocks.context);
mocks.listConnections.mockResolvedValue([]);
mocks.hasKwpIntegrationModule.mockResolvedValue(true);
mocks.requireKwpIntegrationModule.mockImplementation(async (context: unknown) => context);
});
describe("Google-Calendar integration routing", () => {
it("links the calendar catalog card to the calendar connections settings", async () => {
const response = await catalogLoader({
request: new Request("https://app.example.test/acme/settings/integrations"),
params: { tenant: "acme" },
context: undefined,
unstable_pattern: "/:tenant/settings/integrations",
});
const body = (await response.json()) as {
vm: { status: string; data?: { rows: Array<{ key: string; detailHref: string }> } };
};
expect(body.vm.data?.rows.find((row) => row.key === "google-calendar")?.detailHref).toBe(
"/acme/settings/integrations/calendar",
);
});
it("redirects the generic google-calendar detail loader to the calendar connections", async () => {
const thrown = await appLoader({
request: new Request("https://app.example.test/acme/settings/integrations/google-calendar"),
params: { tenant: "acme", app: "google-calendar" },
context: undefined,
unstable_pattern: "/:tenant/settings/integrations/:app",
}).catch((error: unknown) => error);
expect(thrown).toBeInstanceOf(Response);
expect((thrown as Response).status).toBe(302);
expect((thrown as Response).headers.get("location")).toBe("/acme/settings/integrations/calendar");
expect(mocks.listConnections).not.toHaveBeenCalled();
});
it.each(["connect", "reconnect", "disconnect", "manual-sync"])(
"blocks the generic google-calendar %s mutation before any generic lifecycle service runs",
async (intent) => {
const request = new Request("https://app.example.test/acme/settings/integrations/google-calendar", {
method: "POST",
body: new URLSearchParams({ intent, connectionId: "connection_1", label: "Google Kalender" }),
});
const thrown = await appAction({
request,
params: { tenant: "acme", app: "google-calendar" },
context: undefined,
unstable_pattern: "/:tenant/settings/integrations/:app",
}).catch((error: unknown) => error);
expect(thrown).toBeInstanceOf(Response);
expect((thrown as Response).status).toBe(303);
expect((thrown as Response).headers.get("location")).toBe("/acme/settings/integrations/calendar");
expect(mocks.createConnection).not.toHaveBeenCalled();
expect(mocks.reconnectConnection).not.toHaveBeenCalled();
expect(mocks.disconnectConnection).not.toHaveBeenCalled();
expect(mocks.runSyncForConnection).not.toHaveBeenCalled();
},
);
});