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

@@ -1,18 +1,45 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { getAdminActiveUserKpiCounts, getAdminTenantKpiCounts } from "@hivegrid/db/kpi.server";
import { StatChange } from "~/application/dtos/stats/StatChange";
import { getAdminDashboardStats } from "./adminDashboardService";
import { getDbClient } from "@hivegrid/db/client.server";
import { listAuditEvents } from "@hivegrid/db/audit-events-query.server";
import { getAdminDashboardOverview, getAdminDashboardStats } from "./adminDashboardService";
import { getMrr } from "./.server/subscriptionService";
import { adminGetAllTenantsIdsAndNames } from "../db/tenants.db.server";
import { getRlsExecutionContext, runWithRlsContext } from "@hivegrid/db/rls-context.server";
import { getPlatformOutboxCounts } from "@hivegrid/db/admin-dashboard.server";
vi.mock("@hivegrid/db/kpi.server", () => ({
getAdminActiveUserKpiCounts: vi.fn(),
getAdminTenantKpiCounts: vi.fn(),
}));
vi.mock("@hivegrid/db/client.server", () => ({
getDbClient: vi.fn(),
}));
vi.mock("@hivegrid/db/audit-events-query.server", () => ({
listAuditEvents: vi.fn(),
}));
vi.mock("@hivegrid/db/admin-dashboard.server", () => ({
getPlatformOutboxCounts: vi.fn(),
}));
vi.mock("./.server/subscriptionService", () => ({
getMrr: vi.fn(),
}));
vi.mock("../db/tenants.db.server", () => ({
adminGetAllTenantsIdsAndNames: vi.fn(),
}));
const adminTenants = ["tenant_1", "tenant_2", "tenant_3", "tenant_4", "tenant_5"].map((id) => ({
id,
name: id,
slug: id,
}));
const translations: Record<string, string> = {
"admin.kpi.accounts.name": "Translated accounts",
"admin.kpi.accounts.hint": "Translated total accounts",
@@ -30,6 +57,7 @@ function t(key: string) {
describe("getAdminDashboardStats", () => {
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(adminGetAllTenantsIdsAndNames).mockResolvedValue(adminTenants);
vi.mocked(getMrr).mockResolvedValue({ total: 1234.5, count: 7 });
});
@@ -45,7 +73,10 @@ describe("getAdminDashboardStats", () => {
expect(getAdminActiveUserKpiCounts).toHaveBeenCalledTimes(1);
expect(getAdminActiveUserKpiCounts).toHaveBeenCalledWith({ gte });
expect(getMrr).toHaveBeenCalledTimes(1);
expect(getMrr).toHaveBeenCalledWith("eur");
expect(getMrr).toHaveBeenCalledWith(
"eur",
adminTenants.map((tenant) => tenant.id)
);
expect(stats).toEqual([
{
name: "Translated accounts",
@@ -107,3 +138,107 @@ describe("getAdminDashboardStats", () => {
});
});
});
describe("getAdminDashboardOverview", () => {
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(adminGetAllTenantsIdsAndNames).mockResolvedValue(adminTenants);
vi.stubEnv("BULLMQ_REDIS_URL", "redis://localhost:6379/0");
vi.stubEnv("MEILI_URL", "http://localhost:7700");
vi.stubEnv("MEILI_API_KEY", "devkey");
vi.stubEnv("LAGO_API_URL", "http://lago.local");
vi.stubEnv("LAGO_API_KEY", "lago-key");
vi.stubEnv("MOLLIE_API_KEY", "mollie-key");
vi.stubEnv("MOLLIE_PROFILE_ID", "profile-id");
vi.stubEnv("SENTRY_ENVIRONMENT", "staging");
vi.stubEnv("SENTRY_RELEASE", "abc123");
vi.stubEnv("SENTRY_DSN", "https://example.invalid/1");
vi.mocked(listAuditEvents).mockResolvedValue({
rows: [
{
id: "audit-1",
createdAt: new Date("2026-07-01T10:00:00.000Z"),
summaryText: "Tenant aktualisiert",
action: "tenant.update",
actorEmail: "ops@example.test",
targetType: "Tenant",
sourceModule: "admin",
actorType: "user",
outcome: "success",
},
],
total: 1,
take: 5,
skip: 0,
} as never);
vi.mocked(getPlatformOutboxCounts).mockResolvedValue({ pendingOrProcessing: 5, failed: 6 });
});
it("builds billing, system, deploy, and audit overview signals", async () => {
vi.mocked(getDbClient).mockReturnValue(createDashboardClient({
failedWebhookCount: 4,
}) as never);
const overview = await runWithRlsContext({ userId: "operator_1" }, () => getAdminDashboardOverview());
expect(overview.billing).toMatchObject({
openIssueCount: 6,
pastDueCount: 2,
frozenCount: 1,
missingProviderCount: 3,
});
expect(overview.billing.signals).toEqual(
expect.arrayContaining([
expect.objectContaining({ id: "billing-issues", value: "6", tone: "warning", href: "/system/billing" }),
expect.objectContaining({ id: "billing-past-due", value: "2", tone: "danger", href: "/system/billing" }),
])
);
expect(overview.system.signals).toEqual(
expect.arrayContaining([
expect.objectContaining({ id: "redis", value: "OK", tone: "success" }),
expect.objectContaining({ id: "webhooks", value: "4", tone: "warning", href: "/system/webhooks" }),
expect.objectContaining({ id: "outbox", value: "5/6", tone: "danger", href: "/events" }),
])
);
expect(overview.deploy).toMatchObject({ environment: "staging", release: "abc123" });
expect(overview.recentEvents).toEqual([
expect.objectContaining({
id: "audit-1",
label: "Tenant aktualisiert",
detail: "ops@example.test · Tenant",
timestamp: "2026-07-01T10:00:00.000Z",
href: "/audit",
}),
]);
expect(listAuditEvents).toHaveBeenCalledWith({ take: 5, skip: 0 });
expect(getPlatformOutboxCounts).toHaveBeenCalledWith(undefined, {
allowMarkedLocalDatabaseFallback: false,
});
});
});
function createDashboardClient({
failedWebhookCount,
}: {
failedWebhookCount: number;
}) {
const subscriptions = new Map([
["tenant_1", { status: "past_due", pastDueSince: null, frozenAt: null, planCode: "pro", lagoCustomerId: null, mollieCustomerId: "m_1" }],
["tenant_2", { status: "trial", pastDueSince: new Date(), frozenAt: null, planCode: null, lagoCustomerId: "l_2", mollieCustomerId: "m_2" }],
["tenant_3", { status: "frozen", pastDueSince: null, frozenAt: new Date(), planCode: "pro", lagoCustomerId: "l_3", mollieCustomerId: null }],
["tenant_4", { status: "active", pastDueSince: null, frozenAt: null, planCode: "pro", lagoCustomerId: null, mollieCustomerId: "m_4" }],
["tenant_5", { status: "trial", pastDueSince: null, frozenAt: null, planCode: null, lagoCustomerId: "l_5", mollieCustomerId: "m_5" }],
]);
const tenantSubscriptionFindUnique = vi.fn(async ({ where }: { where: { tenantId: string } }) => {
expect(getRlsExecutionContext()).toMatchObject({ userId: "operator_1", tenantId: where.tenantId });
return subscriptions.get(where.tenantId) ?? null;
});
return {
tenantSubscription: {
findUnique: tenantSubscriptionFindUnique,
},
eventWebhookAttempt: {
count: vi.fn().mockResolvedValue(failedWebhookCount),
},
};
}