import { beforeEach, describe, expect, it, vi } from "vitest";
import { PermissionKey, SystemRole } from "@capakraken/shared";
import {
  createToolContext,
  executeTool,
  resetAssistantImportToolTestState,
} from "./assistant-tools-import-dispo-webhooks-test-helpers.js";

describe("assistant import tools", () => {
  beforeEach(async () => {
    await resetAssistantImportToolTestState();
  });

  it("requires importData permission for CSV imports", async () => {
    const ctx = createToolContext(
      {
        auditLog: { create: vi.fn() },
      },
      {
        userRole: SystemRole.MANAGER,
        permissions: [],
      },
    );

    const result = await executeTool(
      "import_csv_data",
      JSON.stringify({
        entityType: "resources",
        rows: [{ eid: "EMP-001", displayName: "Carol Danvers" }],
        dryRun: true,
      }),
      ctx,
    );

    expect(JSON.parse(result.content)).toEqual(
      expect.objectContaining({
        error: expect.stringContaining(PermissionKey.IMPORT_DATA),
      }),
    );
  });
});
