import { describe, expect, it } from "vitest";
import {
  jobSignalsHybridOrOnsite,
  normalizeIsRemote,
} from "./work-arrangement.js";

describe("jobSignalsHybridOrOnsite", () => {
  it("detects hybrid in description", () => {
    expect(
      jobSignalsHybridOrOnsite({
        title: "Automation Test Engineer (SDET)",
        jobDescription:
          "Job Type: Hybrid (3 days remote)\nJob Location: Vancouver, BC",
        isRemote: true,
      }),
    ).toBe(true);
  });

  it("detects N days in office", () => {
    expect(
      jobSignalsHybridOrOnsite({
        jobDescription: "3 days per week in the office, 2 days remote",
      }),
    ).toBe(true);
  });

  it("does not flag fully remote postings", () => {
    expect(
      jobSignalsHybridOrOnsite({
        jobDescription: "100% remote. Work from anywhere in Canada.",
        isRemote: true,
      }),
    ).toBe(false);
  });
});

describe("normalizeIsRemote", () => {
  it("downgrades JobSpy false positive when hybrid is mentioned", () => {
    expect(
      normalizeIsRemote({
        title: "Automation Test Engineer (SDET)",
        jobDescription: "Job Type: Hybrid (3 days remote)",
        isRemote: true,
      }),
    ).toBe(false);
  });

  it("keeps true when upstream says remote and text is fully remote", () => {
    expect(
      normalizeIsRemote({
        jobDescription: "Fully remote role. No office visits required.",
        isRemote: true,
      }),
    ).toBe(true);
  });

  it("promotes unknown upstream when text is strongly remote-only", () => {
    expect(
      normalizeIsRemote({
        jobDescription: "100% remote — work from anywhere.",
        isRemote: undefined,
      }),
    ).toBe(true);
  });

  it("returns null when remote status is unclear", () => {
    expect(
      normalizeIsRemote({
        title: "Software Engineer",
        location: "Toronto, ON",
        isRemote: undefined,
      }),
    ).toBeNull();
  });
});
