← back to Trademarks Copyright

tests/lifecycle.test.ts

102 lines

import { test } from "node:test";
import assert from "node:assert/strict";
import {
  domainLifecycle, abandonmentStatus, opportunityLabel, extractLatestYear,
} from "../src/lib/lifecycle";

test("domainLifecycle — expired when HTTP 4xx", () => {
  assert.equal(domainLifecycle(404, null), "expired");
  assert.equal(domainLifecycle(503, null), "expired");
});
test("domainLifecycle — live when 2xx/3xx", () => {
  assert.equal(domainLifecycle(200, null), "live");
  assert.equal(domainLifecycle(301, null), "live");
});
test("domainLifecycle — expiring_soon when whois date within 90 days", () => {
  const soon = new Date(Date.now() + 30 * 86400_000);
  assert.equal(domainLifecycle(200, soon), "expiring_soon");
});
test("domainLifecycle — expired when whois date passed", () => {
  const past = new Date(Date.now() - 5 * 86400_000);
  assert.equal(domainLifecycle(200, past), "expired");
});
test("domainLifecycle — unknown on 0 status + no date", () => {
  assert.equal(domainLifecycle(0, null), "unknown");
  assert.equal(domainLifecycle(null, null), "unknown");
});

test("abandonmentStatus — buckets by years stale", () => {
  assert.equal(abandonmentStatus(0), "active");
  assert.equal(abandonmentStatus(0.5), "active");
  assert.equal(abandonmentStatus(1), "stale");
  assert.equal(abandonmentStatus(2.9), "stale");
  assert.equal(abandonmentStatus(3), "abandoned");
  assert.equal(abandonmentStatus(10), "abandoned");
  assert.equal(abandonmentStatus(null), "unknown");
});

test("opportunityLabel — do_not_target when registered + active", () => {
  const l = opportunityLabel({
    isRegistered: true, yearsInBusiness: 10,
    lifecycle: "live", abandonment: "active", isParked: false,
  });
  assert.equal(l, "do_not_target");
});
test("opportunityLabel — domain_snipe on expired lifecycle regardless of abandonment", () => {
  const l = opportunityLabel({
    isRegistered: false, yearsInBusiness: 10,
    lifecycle: "expired", abandonment: "unknown", isParked: false,
  });
  assert.equal(l, "domain_snipe");
});
test("opportunityLabel — abandonment_watch when unregistered + 3+ yrs stale + live", () => {
  const l = opportunityLabel({
    isRegistered: false, yearsInBusiness: 10,
    lifecycle: "live", abandonment: "abandoned", isParked: false,
  });
  assert.equal(l, "abandonment_watch");
});
test("opportunityLabel — licensing_outreach when unregistered + active + live", () => {
  const l = opportunityLabel({
    isRegistered: false, yearsInBusiness: 7,
    lifecycle: "live", abandonment: "active", isParked: false,
  });
  assert.equal(l, "licensing_outreach");
});
test("opportunityLabel — unclear when parked", () => {
  const l = opportunityLabel({
    isRegistered: false, yearsInBusiness: 1,
    lifecycle: "live", abandonment: "active", isParked: true,
  });
  assert.equal(l, "unclear");
});
test("opportunityLabel — unclear when USPTO unchecked (isRegistered=null)", () => {
  const l = opportunityLabel({
    isRegistered: null, yearsInBusiness: 7,
    lifecycle: "live", abandonment: "active", isParked: false,
  });
  assert.equal(l, "unclear");
});

test("extractLatestYear — pulls © year from text", () => {
  const { year, signal } = extractLatestYear("Some text © 2024 BrandCo. All rights reserved.");
  assert.equal(year, 2024);
  assert.ok(signal && signal.includes("2024"));
});
test("extractLatestYear — pulls 'Since 1995'", () => {
  const { year } = extractLatestYear("Family-owned Since 1995");
  assert.equal(year, 1995);
});
test("extractLatestYear — prefers highest recent year in a range", () => {
  const { year } = extractLatestYear("© 2018–2023 BrandCo");
  assert.equal(year, 2023);
});
test("extractLatestYear — returns null when nothing found", () => {
  const { year } = extractLatestYear("No date information anywhere.");
  assert.equal(year, null);
});
test("extractLatestYear — case-insensitive on Copyright word", () => {
  const { year } = extractLatestYear("Copyright 2022 Some Company");
  assert.equal(year, 2022);
});