import { expect, test } from "vitest";

import { keys } from "./query-keys";

test("the key factory produces the expected arrays", () => {
  expect(keys.me()).toEqual(["me"]);
  expect(keys.config()).toEqual(["config"]);
  expect(keys.objects()).toEqual(["objects"]);
  const p = { limit: 50, offset: 0 };
  expect(keys.objectsPage(p)).toEqual(["objects", p]);
  expect(keys.object("x")).toEqual(["object", "x"]);
  expect(keys.fieldDefinitions()).toEqual(["field-definitions"]);
  expect(keys.vocabularies()).toEqual(["vocabularies"]);
  expect(keys.terms("v1")).toEqual(["terms", "v1"]);
  expect(keys.authorities("person")).toEqual(["authorities", "person"]);
  expect(keys.search()).toEqual(["search"]);
  expect(keys.searchResults("q", null)).toEqual(["search", "q", null]);
});

test("objects() is a prefix of objectsPage() so invalidation matches", () => {
  const prefix = keys.objects();
  const full = keys.objectsPage({ limit: 50, offset: 0 });
  expect(full.slice(0, prefix.length)).toEqual(prefix);
});
