import { describe, expect, it } from "vitest";
import { areHistoryQueriesEqual } from "../queryUtils";
import type { HistoryQuery } from "../../types/history";

describe("areHistoryQueriesEqual", () => {
  it("returns true for identical history queries", () => {
    const a: HistoryQuery = {
      range: "7d",
      origin: "blocklist",
      jail: "ssh",
      ip: "192.0.2.1",
      source: "archive",
      page: 2,
      page_size: 50,
    };

    const b = { ...a };

    expect(areHistoryQueriesEqual(a, b)).toBe(true);
  });

  it("returns false when a single query field differs", () => {
    const base: HistoryQuery = {
      range: "7d",
      origin: "all",
      jail: "ssh",
      ip: "192.0.2.1",
      source: "archive",
      page: 2,
      page_size: 50,
    };

    expect(
      areHistoryQueriesEqual(base, { ...base, page: 3 }),
    ).toBe(false);
    expect(
      areHistoryQueriesEqual(base, { ...base, ip: "198.51.100.1" }),
    ).toBe(false);
  });
});
