import { describe, it, expect } from "vitest";
import { deleteMediaUseCase } from "@/application/use-cases/delete-media.use-case";
import { MockMediaRepository } from "@/infrastructure/repositories/media.repository.mock";
import { MediaNotFoundError } from "@/entities/errors/media";
import { mediaFactory } from "@/__factories__/media.factory";

describe("deleteMediaUseCase", () => {
  it("deletes media when found", async () => {
    const repo = new MockMediaRepository();
    const seed = mediaFactory.build({ id: "m-1" });
    await repo._store(seed);

    const useCase = deleteMediaUseCase(repo);
    await useCase({ id: "m-1" });

    const result = await repo.getMedia("m-1");
    expect(result).toBeUndefined();
  });

  it("throws MediaNotFoundError when id does not exist", async () => {
    const repo = new MockMediaRepository();
    const useCase = deleteMediaUseCase(repo);

    await expect(useCase({ id: "missing" })).rejects.toThrow(MediaNotFoundError);
  });
});
