Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -0,0 +1,50 @@
// @vitest-environment node
import { beforeEach, describe, expect, it, vi } from "vitest";
const mocks = vi.hoisted(() => ({
tenantHasModule: vi.fn(),
webConfig: { kwp: { hiveGridTenantId: "tenant-1" } },
}));
vi.mock("~/utils/connector/tenantConnector.server", () => ({ tenantHasModule: mocks.tenantHasModule }));
vi.mock("@hivegrid/config", () => ({ loadRequiredWebConfig: () => mocks.webConfig }));
import { hasKwpIntegrationModule, KWP_INTEGRATION_MODULE_KEY, requireKwpIntegrationModule } from "./kwpAccess.server";
const CONTEXT = {
tenantId: "tenant-1",
userId: "user-1",
permissions: ["integrations.read", "integrations.connect"],
hasModule: true,
} as const;
beforeEach(() => {
vi.clearAllMocks();
mocks.webConfig.kwp.hiveGridTenantId = "tenant-1";
mocks.tenantHasModule.mockResolvedValue(true);
});
describe("KWP integration access", () => {
it("uses the dedicated subscription-gated kwp_integration feature", async () => {
expect(KWP_INTEGRATION_MODULE_KEY).toBe("kwp_integration");
await expect(hasKwpIntegrationModule(CONTEXT)).resolves.toBe(true);
expect(mocks.tenantHasModule).toHaveBeenCalledWith({
tenantId: "tenant-1",
userId: "user-1",
moduleKey: "kwp_integration",
});
});
it("returns a not-found domain error when the tenant lacks the add-on", async () => {
mocks.tenantHasModule.mockResolvedValueOnce(false);
await expect(requireKwpIntegrationModule(CONTEXT)).rejects.toMatchObject({ status: 404 });
});
it("fails closed before entitlement lookup when the process credentials belong to another tenant", async () => {
mocks.webConfig.kwp.hiveGridTenantId = "tenant-other";
await expect(hasKwpIntegrationModule(CONTEXT)).resolves.toBe(false);
await expect(requireKwpIntegrationModule(CONTEXT)).rejects.toMatchObject({ status: 404 });
expect(mocks.tenantHasModule).not.toHaveBeenCalled();
});
});
@@ -0,0 +1,28 @@
import { featureKeys } from "@hivegrid/entitlements";
import { CatalogError, foundationErrors } from "@hivegrid/foundation";
import { loadRequiredWebConfig } from "@hivegrid/config";
import { tenantHasModule } from "~/utils/connector/tenantConnector.server";
import type { IntegrationsRouteContext } from "~/utils/integrations/integrationsAccess.server";
export const KWP_INTEGRATION_MODULE_KEY = featureKeys.kwpIntegration;
export async function hasKwpIntegrationModule(context: IntegrationsRouteContext): Promise<boolean> {
const configuredTenantId = loadRequiredWebConfig().kwp?.hiveGridTenantId?.trim();
if (!configuredTenantId || configuredTenantId !== context.tenantId) return false;
return tenantHasModule({
tenantId: context.tenantId,
userId: context.userId,
moduleKey: KWP_INTEGRATION_MODULE_KEY,
});
}
/** Fail closed with the platform's 404 permission semantics. */
export async function requireKwpIntegrationModule(
context: IntegrationsRouteContext,
): Promise<IntegrationsRouteContext> {
if (!(await hasKwpIntegrationModule(context))) {
throw new CatalogError(foundationErrors.notFound, { module: KWP_INTEGRATION_MODULE_KEY });
}
return context;
}