1
0
Fork 0
fahrPool/web/lib/audit/queries.test.ts

30 lines
1.2 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import type { SupabaseClient } from "@supabase/supabase-js";
import { ladeAuditLog } from "./queries";
function fakeClient() {
const eq = vi.fn();
const builder: Record<string, unknown> = {};
builder.eq = (...a: unknown[]) => (eq(...a), builder);
builder.order = () => builder;
builder.range = async () => ({ data: [], error: null });
const client = { from: () => ({ select: () => builder }) } as unknown as SupabaseClient;
return { client, eq };
}
describe("ladeAuditLog", () => {
it("filtert den Admin nach firma_id", async () => {
const { client, eq } = fakeClient();
await ladeAuditLog(client, { role: "admin", firmaId: "f1" }, { seite: 1 }, { limit: 10, offset: 0 });
expect(eq).toHaveBeenCalledWith("firma_id", "f1");
expect(eq).not.toHaveBeenCalledWith("akteur_rolle", expect.anything());
});
it("filtert den Superadmin nach akteur_rolle", async () => {
const { client, eq } = fakeClient();
await ladeAuditLog(client, { role: "superadmin", firmaId: null }, { seite: 1 }, { limit: 10, offset: 0 });
expect(eq).toHaveBeenCalledWith("akteur_rolle", "superadmin");
expect(eq).not.toHaveBeenCalledWith("firma_id", expect.anything());
});
});