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

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

  it("enforces admin access for dispo batch inspection via the backing router", async () => {
    const ctx = createToolContext(
      {
        importBatch: {
          findUnique: vi.fn(),
        },
      },
      { userRole: SystemRole.USER },
    );

    const result = await executeTool(
      "get_dispo_import_batch",
      JSON.stringify({ id: "batch_1" }),
      ctx,
    );

    expect(JSON.parse(result.content)).toEqual(
      expect.objectContaining({
        error: "You do not have permission to perform this action.",
      }),
    );
  });

  it("returns a stable assistant error for a missing dispo import batch", async () => {
    const ctx = createToolContext(
      {
        importBatch: {
          findUnique: vi.fn().mockResolvedValue(null),
        },
      },
      { userRole: SystemRole.ADMIN },
    );

    const result = await executeTool(
      "get_dispo_import_batch",
      JSON.stringify({ id: "batch_missing" }),
      ctx,
    );

    expect(JSON.parse(result.content)).toEqual({
      error: "Import batch not found with the given criteria.",
    });
  });
});
