import { describe, expect, it } from "vitest";
import { textMatchesAnyKeyword, textMatchesKeyword } from "./keyword-match.js";

const TIGERA_DESCRIPTION =
  "Tigera provides Calico, a unified network security and observability platform. " +
  "Calico Open Source, is the most widely adopted container networking solution.";

describe("keyword-match", () => {
  it("matches co-op title against coop deal-breaker token", () => {
    expect(
      textMatchesKeyword(
        "Co-op Software Development Engineer in Test (SDET)",
        "coop",
      ),
    ).toBe(true);
    expect(textMatchesKeyword("Co-op SDET", "co-op")).toBe(true);
    expect(textMatchesKeyword("coop internship", "co-op")).toBe(true);
  });

  it("does not match co-op inside Calico Open Source", () => {
    expect(
      textMatchesKeyword(
        `Senior Software Development Engineer in Test\n${TIGERA_DESCRIPTION}`,
        "co-op",
      ),
    ).toBe(false);
    expect(textMatchesKeyword(TIGERA_DESCRIPTION, "coop")).toBe(false);
    expect(textMatchesKeyword("Calico Open Source", "co-op")).toBe(false);
  });

  it("matches intern in employer or title", () => {
    expect(textMatchesAnyKeyword("Acme Intern Program", ["intern"])).toBe(true);
    expect(
      textMatchesAnyKeyword("Global Relay Communications Inc.", ["intern"]),
    ).toBe(false);
    expect(textMatchesKeyword("Internal tools team", "intern")).toBe(false);
  });

  it("matches multi-word keywords with flexible separators", () => {
    expect(textMatchesKeyword("Foo Staffing Agency", "staffing agency")).toBe(
      true,
    );
    expect(textMatchesKeyword("Foo-Staffing-Agency", "staffing agency")).toBe(
      true,
    );
  });
});
