import { describe, expect, it } from "vitest";
import { ZodError } from "zod";
import { get{{pascalCase entity}}UseCase } from "@/application/use-cases/get-{{kebabCase entity}}.use-case";
import { Mock{{pascalCase entity}}Repository } from "@/infrastructure/repositories/{{kebabCase entity}}.repository.mock";
import { {{pascalCase entity}}NotFoundError } from "@/entities/errors/{{kebabCase entity}}";

describe("get{{pascalCase entity}}UseCase", () => {
  it("returns the seeded {{camelCase entity}} by id", async () => {
    const repo = new Mock{{pascalCase entity}}Repository();
    const useCase = get{{pascalCase entity}}UseCase(repo);
    const result = await useCase({ id: "seed-1" });
    expect(result.id).toBe("seed-1");
    expect(result.name).toBeTypeOf("string");
  });

  it("throws {{pascalCase entity}}NotFoundError when repository returns null", async () => {
    const repo = new Mock{{pascalCase entity}}Repository(new Map());
    const useCase = get{{pascalCase entity}}UseCase(repo);
    await expect(useCase({ id: "missing" })).rejects.toBeInstanceOf(
      {{pascalCase entity}}NotFoundError,
    );
  });

  it("throws ZodError when repository returns malformed data", async () => {
    const malformedRepo = {
      get{{pascalCase entity}}: async () => ({ id: "", name: "x" }) as never,
    };
    const useCase = get{{pascalCase entity}}UseCase(malformedRepo);
    await expect(useCase({ id: "anything" })).rejects.toBeInstanceOf(ZodError);
  });
});
