import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import { collectModuleSyncResult } from "./sync-check";

describe("collectModuleSyncResult (integration)", () => {
  let tmpDir: string;

  beforeEach(() => {
    tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "sync-check-int-"));
  });

  afterEach(() => {
    fs.rmSync(tmpDir, { recursive: true, force: true });
  });

  it("combines source sync and test case sync errors", async () => {
    const srcDir = path.join(tmpDir, "modules", "foo", "command");
    fs.mkdirSync(srcDir, { recursive: true });
    fs.writeFileSync(path.join(srcDir, "createOrder.ts"), "export {}");

    const result = await collectModuleSyncResult("modules", tmpDir);
    expect(result.errors.some((e) => e.type === "missing-doc")).toBe(true);
  });

  it("reports no files checked for an empty modules directory", async () => {
    fs.mkdirSync(path.join(tmpDir, "modules"), { recursive: true });
    const result = await collectModuleSyncResult("modules", tmpDir);
    expect(result.filesChecked).toBe(0);
  });
});
