SPB Git forge
38commits 1branches 0releases
338.7 MBsize
maindefault branch
3 h agolast push
HTML 53.9% TypeScript 44.5% JavaScript 0.6% SQL 0.5%
6.7 KB · 87 lines typescript
Raw Blame History
1import { describe, expect, it } from "vitest";2import { classifyPage, eventTypeFor, isDataCenterRelevant } from "./classify.js";3import { projectMwFigures } from "./mw-figures.js";45describe("classifyPage — URL rules win", () => {6  it("a facility page mentioning an acquisition stays facility_page", () => {7    const c = classifyPage("https://op.com/data-centers/ashburn-va1/", "VA1 Ashburn", "VA1 was acquired in 2019 as part of the acquisition of Acme. 36 MW critical load, N+1, 2N power.");8    expect(c.pageType).toBe("facility_page");9    expect(c.eventType).toBe("facility_updated");10    expect(c.mw).toEqual([36]);11  });12  it("facility index, newsroom index, press release, cloud region, financial, planning by URL", () => {13    expect(classifyPage("https://op.com/data-centers/", null, "").pageType).toBe("facility_index");14    expect(classifyPage("https://op.com/newsroom/", null, "").pageType).toBe("news_index");15    expect(classifyPage("https://op.com/news/2026/big-campus", null, "").pageType).toBe("press_release");16    expect(classifyPage("https://cloud.com/global-infrastructure/regions/", null, "").pageType).toBe("cloud_region");17    expect(classifyPage("https://op.com/investors/annual-report", null, "").pageType).toBe("financial_disclosure");18    expect(classifyPage("https://county.gov/planning/applications/2026-001", null, "").pageType).toBe("planning_document");19    expect(classifyPage("https://op.de/rechenzentren/frankfurt-1/", null, "").pageType).toBe("facility_page");20  });21  it("PDFs are planning documents only with planning vocabulary in URL or title, otherwise unknown", () => {22    expect(classifyPage("https://county.gov/files/rezoning-application-2026.pdf", null, "").pageType).toBe("planning_document");23    expect(classifyPage("https://county.gov/files/ZMAP-2026-0001.pdf", "Planning Commission agenda", "")).toMatchObject({ pageType: "planning_document", rule: "url:pdf+planning" });24    expect(classifyPage("https://op.com/files/brochure.pdf", "Campus brochure", "We announce a new 100 MW data center")).toMatchObject({ pageType: "unknown", rule: "url:pdf" });25    expect(classifyPage("https://op.com/news/release.pdf", null, "").pageType).toBe("unknown"); // the news parser decides26  });27});2829describe("classifyPage — text rules", () => {30  it("first matching text rule wins", () => {31    expect(classifyPage("https://x.com/p/1", "Acme completes acquisition of Beta", "").pageType).toBe("acquisition");32    expect(classifyPage("https://x.com/p/2", "Acme expands Dallas campus", "adds 40 MW").pageType).toBe("expansion");33    expect(classifyPage("https://x.com/p/3", "Acme breaks ground in Ohio", "").pageType).toBe("construction_update");34    expect(classifyPage("https://x.com/p/4", "Acme signs power purchase agreement", "").pageType).toBe("power_infrastructure");35    expect(classifyPage("https://x.com/p/5", "Acme launches new region in Madrid", "availability zones").pageType).toBe("cloud_region");36    expect(classifyPage("https://x.com/p/6", "Acme announces $2 billion campus", "").pageType).toBe("project_announcement");37    expect(classifyPage("https://x.com/p/7", "Quarterly newsletter", "nothing here").pageType).toBe("unknown");38  });39  it("understands German, French, Spanish, Portuguese and Dutch announcements", () => {40    expect(classifyPage("https://x.de/p/1", "Acme baut neues Rechenzentrum in Frankfurt", "").pageType).toBe("project_announcement");41    expect(classifyPage("https://x.fr/p/1", "Acme annonce un nouveau centre de données à Marseille", "communiqué de presse").pageType).toBe("project_announcement");42    expect(classifyPage("https://x.es/p/1", "Acme construirá un nuevo centro de datos en Madrid", "").pageType).toBe("project_announcement");43    expect(classifyPage("https://x.pt/p/1", "Acme anuncia novo centro de dados em Sines", "").pageType).toBe("project_announcement");44    expect(classifyPage("https://x.nl/p/1", "Acme bouwt nieuw datacentrum in Groningen", "").pageType).toBe("project_announcement");45  });46  it("filters portfolio totals out of the MW list", () => {47    const c = classifyPage("https://x.com/p/8", "Acme announces 60 MW data center in Lisbon", "The new facility brings the company's total capacity to 1.4 GW across Europe. The 60MW site opens in 2028.");48    expect(c.mw).toEqual([60]);49  });50});5152describe("eventTypeFor", () => {53  it("maps page types to event types with text refinements", () => {54    expect(eventTypeFor("construction_update", "Acme breaks ground")).toBe("construction_started");55    expect(eventTypeFor("construction_update", "construction progress update")).toBe("project_status_changed");56    expect(eventTypeFor("planning_document", "the board approved the application")).toBe("planning_approved");57    expect(eventTypeFor("planning_document", "application filed")).toBe("planning_filed");58    expect(eventTypeFor("cloud_region", "Acme announces upcoming region")).toBe("cloud_region_announced");59    expect(eventTypeFor("cloud_region", "region is now available")).toBe("cloud_region_launched");60    expect(eventTypeFor("project_announcement", "to invest $5 billion in the state")).toBe("investment_announced");61    expect(eventTypeFor("project_announcement", "to invest $5 billion in a 300 MW campus")).toBe("project_announced");62    expect(eventTypeFor("project_announcement", "Acme investiert 1 Mrd. in ein neues Rechenzentrum")).toBe("project_announced");63    expect(eventTypeFor("press_release", "")).toBe("news");64    expect(eventTypeFor("unknown", "")).toBeUndefined();65  });66});6768describe("isDataCenterRelevant", () => {69  it("accepts data-center vocabulary in every indexed language", () => {70    for (const t of ["new data center in Ohio", "colocation provider", "50 MW campus", "Rechenzentrum in Frankfurt", "centre de données à Paris", "centro de datos en Madrid", "centro de dados em Lisboa", "datacentrum in Amsterdam", "nytt datasenter i Oslo", "nytt datacenter i Stockholm", "serverhall i Luleå"]) expect(isDataCenterRelevant(t), t).toBe(true);71  });72  it("rejects unrelated text", () => {73    expect(isDataCenterRelevant("Quarterly dividend declared by the board")).toBe(false);74    expect(isDataCenterRelevant("Acme names Jane Doe as CFO")).toBe(false);75  });76});7778describe("projectMwFigures", () => {79  it("keeps site figures, drops portfolio/company-wide figures, dedupes, sorts descending, bounds 0–20 000", () => {80    expect(projectMwFigures("a 100 MW campus with a first 20MW phase and 20 MW later; portfolio of 2 GW across Asia; 30,000 MW pipeline")).toEqual([100, 20]);81    expect(projectMwFigures("brings the total capacity to 500 MW")).toEqual([]);82    expect(projectMwFigures("now operates 800 MW globally")).toEqual([]);83    expect(projectMwFigures("1.5 GW of contracted capacity")).toEqual([]);84    expect(projectMwFigures("no figures here")).toEqual([]);85  });86});87