import { describe, expect, it } from "vitest";
import { serializeQuery } from "../query";

describe("serializeQuery", () => {
  it("忽略 undefined 和 null，保留 false、0 与空字符串", () => {
    expect(
      serializeQuery({
        omitted: undefined,
        missing: null,
        enabled: false,
        page: 0,
        keyword: "",
      }),
    ).toBe("enabled=false&page=0&keyword=");
  });

  it("通过 URLSearchParams 正确编码键和值", () => {
    expect(serializeQuery({ "关键 字": "应急&预案" })).toBe(
      "%E5%85%B3%E9%94%AE+%E5%AD%97=%E5%BA%94%E6%80%A5%26%E9%A2%84%E6%A1%88",
    );
  });

  it("将数组固定序列化为单个逗号分隔值", () => {
    expect(serializeQuery({ documentType: ["MAIN", "SUB_PLAN"] })).toBe(
      "documentType=MAIN%2CSUB_PLAN",
    );
  });

  it("保留空数组的明确空值语义", () => {
    expect(serializeQuery({ ids: [] })).toBe("ids=");
  });
});
