import { describe, it, expect } from "vitest";
import { mediaSchema } from "@/entities/models/media";

describe("mediaSchema", () => {
  it("parses a valid media object", () => {
    const result = mediaSchema.parse({
      id: "1",
      alt: "A photo",
      url: "https://cdn.example.com/photo.png",
      filename: "photo.png",
      mimeType: "image/png",
      filesize: 1024,
    });
    expect(result.id).toBe("1");
    expect(result.alt).toBe("A photo");
  });

  it("parses a media object with optional width and height", () => {
    const result = mediaSchema.parse({
      id: "2",
      alt: "A photo",
      url: "https://cdn.example.com/photo.png",
      filename: "photo.png",
      mimeType: "image/png",
      filesize: 2048,
      width: 1920,
      height: 1080,
    });
    expect(result.width).toBe(1920);
    expect(result.height).toBe(1080);
  });

  it("parses without width and height (optional)", () => {
    const result = mediaSchema.parse({
      id: "3",
      alt: "Doc",
      url: "https://cdn.example.com/doc.pdf",
      filename: "doc.pdf",
      mimeType: "application/pdf",
      filesize: 512,
    });
    expect(result.width).toBeUndefined();
    expect(result.height).toBeUndefined();
  });

  it("throws for missing required fields", () => {
    expect(() =>
      mediaSchema.parse({ id: "1", alt: "x", url: "x" }),
    ).toThrow();
  });
});
