import { plainToInstance } from "class-transformer";
import { validate } from "class-validator";
import { describe, expect, it } from "vitest";
import { GetMessagesQueryDto } from "./get-messages-query.dto";

describe("GetMessagesQueryDto", () => {
  it("should use defaults when empty", async () => {
    const dto = plainToInstance(GetMessagesQueryDto, {});
    const errors = await validate(dto);

    expect(errors).toHaveLength(0);
    expect(dto.limit).toBe(50);
    expect(dto.skip).toBe(0);
  });

  it("should reject limit greater than 200", async () => {
    const dto = plainToInstance(GetMessagesQueryDto, {
      limit: 201,
      skip: 0,
    });
    const errors = await validate(dto);

    expect(errors.length).toBeGreaterThan(0);
    expect(errors.some((error) => error.property === "limit")).toBe(true);
  });

  it("should reject negative skip", async () => {
    const dto = plainToInstance(GetMessagesQueryDto, {
      limit: 50,
      skip: -1,
    });
    const errors = await validate(dto);

    expect(errors.length).toBeGreaterThan(0);
    expect(errors.some((error) => error.property === "skip")).toBe(true);
  });
});
