"""The HiBob host module against saved answers: Liquidia's board trimmed to five roles and Dixa's whole one, 2026-09-29. No network.""" from __future__ import annotations import json import sys from pathlib import Path from typing import Any import httpx import pytest ROOT = Path(__file__).resolve().parents[1] if str(ROOT) not in sys.path: sys.path.insert(0, str(ROOT)) from app.jobs.discover import boards_in # noqa: E402 from plugins import ats, readers # noqa: E402 from plugins.readers import hibob # noqa: E402 FIXTURES = ROOT / "tests" / "fixtures" / "ats" BOARD = (FIXTURES / "hibob.json").read_bytes() DIXA = (FIXTURES / "hibob-dixa.json").read_bytes() API = "https://liquidia.careers.hibob.com/api/job-ad" def test_rows_carry_the_ads_texts_place_and_date() -> None: rows = hibob.parse(BOARD, "liquidia") assert len(rows) == 5 first = rows[0] assert first["source_id"] == "c328a12c-1c6a-4d34-bfa7-ac322bc32c5d" assert first["title"] == "Senior Vice President, Head of Clinical Operations" assert first["url"] == \ "https://liquidia.careers.hibob.com/jobs/c328a12c-1c6a-4d34-bfa7-ac322bc32c5d" assert first["department"] == "1023-Clin Ops - R&D" assert first["location"] == "USA, United States" assert first["remote"] == "hybrid" and rows[1]["remote"] == "remote" assert first["posted"] is not None and first["posted"].isoformat() == \ "2026-09-15T19:22:14.562309+00:00" # nine fractional digits in the answer text = first["description"] # The description, the responsibilities, the requirements and the benefits, in that order, # as text with its entities read. assert text.startswith("Liquidia is deeply passionate") assert text.index("Leadership & Strategy") < text.index("Bachelor\u2019s degree required") assert "<" not in text and "&" not in text and "\xa0" not in text assert first["salary_text"] == "" and first["currency"] == "" def test_a_board_of_general_applications_reads_as_it_is() -> None: rows = hibob.parse(DIXA, "dixa") assert [(r["title"], r["location"], r["remote"]) for r in rows] == [ ("Expression of interest", "Copenhagen, Denmark", "hybrid"), ("Expression of interest", "London, United Kingdom", "onsite")] assert rows[1]["description"].startswith("We're always excited") def _one(**fields: Any) -> bytes: return json.dumps({"jobAdDetails": [{"id": "a", "title": "Baker", **fields}]}).encode() @pytest.mark.parametrize(("pay", "columns", "text"), [ ({"payTransparencyMinSalary": 50000, "payTransparencyMaxSalary": 70000, "payTransparencySalaryCurrency": "EUR", "payTransparencySalaryPayPeriod": "Yearly"}, (50000, 70000, "EUR"), "EUR 50,000 to 70,000 per year"), ({"payTransparencyMinSalary": 4000, "payTransparencyMaxSalary": None, "payTransparencySalaryCurrency": "DKK", "payTransparencySalaryPayPeriod": "MONTH"}, (48000, None, "DKK"), "DKK from 4,000 per month"), # An hourly rate stays out of the yearly columns and in the text. ({"payTransparencyMinSalary": 30, "payTransparencyMaxSalary": 40, "payTransparencySalaryCurrency": "USD", "payTransparencySalaryPayPeriod": "hourly"}, (None, None, ""), "USD 30 to 40 per hour"), ({}, (None, None, ""), ""), ]) def test_pay_is_read_by_its_period(pay: dict[str, Any], columns: tuple[Any, ...], text: str) -> None: row = hibob.parse(_one(**pay), "acme")[0] assert (row["salary_min"], row["salary_max"], row["currency"]) == columns assert row["salary_text"] == text def test_the_place_leaves_the_country_off_where_the_site_names_it() -> None: for fields, want in (({"site": "Denmark", "country": "Denmark"}, "Denmark"), ({"site": "Copenhagen", "country": "Denmark"}, "Copenhagen, Denmark"), ({"site": "", "country": "Denmark"}, "Denmark"), ({}, "")): assert hibob.parse(_one(**fields), "acme")[0]["location"] == want def test_an_ad_without_a_title_or_id_is_skipped_and_an_empty_board_is_empty() -> None: body = json.dumps({"jobAdDetails": [{"id": "a", "title": " "}, {"title": "x"}, {"id": "c", "title": "Cook"}]}).encode() assert [r["source_id"] for r in hibob.parse(body, "acme")] == ["c"] assert hibob.parse(b'{"filterGroups": {}, "jobAdDetails": []}', "acme") == [] # ------------------------------------------------------------ the fetch def test_the_page_sends_the_company_header_and_states_no_total() -> None: seen: list[tuple[str, dict[str, str] | None]] = [] def get(url: str, *, method: str = "GET", payload: Any = None, headers: dict[str, str] | None = None) -> bytes: seen.append((url, headers)) return BOARD data, results, total, cursor = hibob.page(get, "Liquidia", None) assert seen == [(API, {"companyIdentifier": "liquidia", "Accept": "application/json"})] assert len(results) == 5 and all(r["id"] for r in results) assert total is None and cursor is None assert len(hibob.rows(data, "liquidia")) == 5 def test_a_body_without_the_ads_is_not_a_board() -> None: with pytest.raises(ValueError, match="not a HiBob board"): hibob.page(lambda url, **kw: b'{"error": "unauthorized"}', "acme", None) @pytest.fixture def web(monkeypatch: pytest.MonkeyPatch) -> dict[str, Any]: answers: dict[str, Any] = {} seen: list[tuple[str, dict[str, str] | None]] = [] def fake_get(client, url, host, slug, *, method="GET", payload=None, headers=None, www_twin=False): seen.append((url, headers)) if not ats._allowed_host(host, slug)(httpx.URL(url).host): raise ats._Refused(url) answer = answers[url] if isinstance(answer, BaseException): raise answer return answer monkeypatch.setattr(ats, "_get", fake_get) return {"answers": answers, "seen": seen} def test_the_board_is_one_request_and_complete(web: dict[str, Any]) -> None: web["answers"][API] = BOARD with httpx.Client() as client: rows, complete = ats._fetch_rows(client, "hibob:liquidia") assert len(rows) == 5 and complete assert [url for url, _ in web["seen"]] == [API] assert web["seen"][0][1]["companyIdentifier"] == "liquidia" def test_an_empty_board_is_complete_and_a_401_is_a_failure(web: dict[str, Any]) -> None: web["answers"]["https://acme.careers.hibob.com/api/job-ad"] = b'{"jobAdDetails": []}' request = httpx.Request("GET", API) web["answers"][API] = httpx.HTTPStatusError( "401", request=request, response=httpx.Response(401, request=request)) with httpx.Client() as client: assert ats._fetch_rows(client, "hibob:acme") == ([], True) with pytest.raises(httpx.HTTPStatusError): ats._fetch_rows(client, "hibob:liquidia") def test_the_robots_txt_that_is_the_apps_own_page_allows(web: dict[str, Any]) -> None: """The host answers /robots.txt with its single-page app's HTML, a 200 with no rules.""" web["answers"]["https://dixa.careers.hibob.com/robots.txt"] = \ b'