Sources tab: searches, company boards and the prune by region, in the app
What a pull reads can now be changed on a page instead of only the command line: try a search and see its first ten results before saving it, edit or remove one, follow a company's ATS board, switch any board or search on or off, and preview and apply a prune by region. Each row shows its open roles and the countries they are in. The page and `app companies`/`app searches` call the same functions in app/jobs/sources.py. Switching a target off closes its open roles, and the pull's settle closes them again if a batch in flight reopened them. Roles pulled before `country` existed are backfilled at startup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
047f7cd8ad
commit
6b40702a9a
16 files changed
+1068
-92
No files matched your search
+127
-1
@@ -202,7 +202,7 @@ def test_set_status_validates_and_writes_an_event(
|
||||
|
||||
def test_every_tab_renders_with_the_whole_nav(client: TestClient) -> None:
|
||||
assert [t.label for t in TABS] == ["Roles", "Applications", "Agents", "Companies",
|
||||
"Jobs", "Schedules", "Messages", "Account"]
|
||||
"Sources", "Jobs", "Schedules", "Messages", "Account"]
|
||||
for tab in TABS:
|
||||
res = client.get(tab.path)
|
||||
assert res.status_code == 200, f"{tab.path} answered {res.status_code}"
|
||||
@@ -225,6 +225,14 @@ def test_each_roledesk_tab_is_a_shell_for_roles_js(client: TestClient) -> None:
|
||||
assert client.get("/static/roles.js").status_code == 200
|
||||
|
||||
|
||||
def test_the_sources_tab_is_a_shell_for_sources_js(client: TestClient) -> None:
|
||||
page = client.get("/sources").text
|
||||
assert 'id="searches-list"' in page and 'id="boards-list"' in page
|
||||
assert page.index("app.js") < page.index("sources.js")
|
||||
assert 'value="1" selected>Region Hovedstaden' in page # from plugins.search
|
||||
assert client.get("/static/sources.js").status_code == 200
|
||||
|
||||
|
||||
def test_the_modules_bring_their_own_elements(client: TestClient) -> None:
|
||||
assert "<desk-jobs>" in client.get("/jobs").text
|
||||
assert "<desk-schedules>" in client.get("/schedules").text
|
||||
@@ -320,3 +328,121 @@ def test_roles_by_agent_are_ordered_by_score_and_hide_the_gated(
|
||||
assert everything[-1]["gated_reason"] == "place unknown"
|
||||
assert client.get("/api/roles").json()[0]["score"] is None
|
||||
assert client.get("/api/roles?agent=999").status_code == 404
|
||||
|
||||
|
||||
# ----------------------------------------------------------------- sources
|
||||
|
||||
def _fake_search(monkeypatch: pytest.MonkeyPatch, rows: int) -> None:
|
||||
import plugins.search as search
|
||||
|
||||
def run(target: str, params: dict[str, object],
|
||||
keys: dict[str, object] | None = None) -> tuple[list[dict[str, object]], bool]:
|
||||
return [{"title": f"Engineer {n}", "company": "Acme", "place": "København",
|
||||
"url": f"https://x.example/{n}"} for n in range(rows)], True
|
||||
|
||||
monkeypatch.setattr(search, "run_search", run)
|
||||
|
||||
|
||||
def test_sources_lists_searches_and_boards_with_their_countries(
|
||||
client: TestClient, store: Store) -> None:
|
||||
board = store.add_subscription("ats", "greenhouse:acme", label="Acme", company="Acme",
|
||||
board="greenhouse")
|
||||
store.upsert_role(posting("1", company="Acme", place="Copenhagen"), board)
|
||||
store.upsert_role(posting("2", company="Acme", place="Boston, MA"), board)
|
||||
store.upsert_role(posting("3", company="Acme", place="Aarhus"), board)
|
||||
store.add_subscription("search", "jobindex:cph", label="Copenhagen", board="jobindex",
|
||||
params={"q": "backend", "area": 1})
|
||||
|
||||
res = client.get("/api/sources").json()
|
||||
[row] = res["boards"]
|
||||
assert (row["label"], row["on"], row["open_roles"]) == ("Acme", True, 3)
|
||||
assert row["countries"] == [["DK", 2], ["US", 1]]
|
||||
assert [s["label"] for s in res["searches"]] == ["Copenhagen"]
|
||||
assert res["searches"][0]["params"] == {"q": "backend", "area": 1}
|
||||
|
||||
|
||||
def test_switching_a_board_off_closes_its_roles_and_on_keeps_them_closed_until_a_pull(
|
||||
client: TestClient, store: Store) -> None:
|
||||
board = store.add_subscription("ats", "greenhouse:acme", label="Acme", company="Acme",
|
||||
board="greenhouse")
|
||||
store.upsert_role(posting("1", company="Acme"), board)
|
||||
|
||||
off = client.post(f"/api/sources/{board.id}/switch", json={"on": False}).json()
|
||||
assert off["closed"] == 1 and off["source"]["on"] is False
|
||||
assert store.subscriptions(source="ats", fetchable=True) == []
|
||||
assert store.roles() == []
|
||||
|
||||
on = client.post(f"/api/sources/{board.id}/switch", json={"on": True}).json()
|
||||
assert on["closed"] == 0 and on["source"]["on"] is True
|
||||
assert client.post("/api/sources/999/switch", json={"on": True}).status_code == 404
|
||||
|
||||
|
||||
def test_a_search_is_tried_saved_updated_and_removed(
|
||||
client: TestClient, store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
_fake_search(monkeypatch, 3)
|
||||
body = {"provider": "jobindex", "name": "Copenhagen backend", "q": "backend", "area": 1}
|
||||
|
||||
tried = client.post("/api/searches/try", json=body).json()
|
||||
assert tried["found"] == 3 and tried["complete"] is True
|
||||
assert tried["sample"][0] == {"title": "Engineer 0", "company": "Acme",
|
||||
"place": "København", "url": "https://x.example/0"}
|
||||
assert store.subscriptions(source="search") == []
|
||||
|
||||
saved = client.post("/api/searches", json=body).json()
|
||||
assert saved["source"]["target"] == "jobindex:copenhagen-backend"
|
||||
assert saved["source"]["params"] == {"q": "backend", "area": 1}
|
||||
|
||||
updated = client.post("/api/searches", json={**body, "q": "python", "pages": 3}).json()
|
||||
assert updated["source"]["id"] == saved["source"]["id"]
|
||||
assert updated["source"]["params"] == {"q": "python", "area": 1, "pages": 3}
|
||||
|
||||
sub_id = saved["source"]["id"]
|
||||
assert client.delete(f"/api/searches/{sub_id}").json() == {"closed": 0}
|
||||
assert client.get("/api/sources").json()["searches"] == []
|
||||
again = client.post("/api/searches", json=body).json() # the same row, back on
|
||||
assert again["source"]["id"] == sub_id and again["source"]["on"] is True
|
||||
|
||||
|
||||
def test_a_search_that_finds_nothing_or_is_malformed_is_refused(
|
||||
client: TestClient, store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
_fake_search(monkeypatch, 0)
|
||||
res = client.post("/api/searches", json={"provider": "jobindex", "name": "X", "q": "x"})
|
||||
assert res.status_code == 422 and "found nothing" in res.json()["detail"]
|
||||
res = client.post("/api/searches", json={"provider": "indeed", "name": "X", "q": "x"})
|
||||
assert res.status_code == 422
|
||||
res = client.post("/api/searches/try", json={"provider": "jobindex", "q": " "})
|
||||
assert res.status_code == 422 and "query" in res.json()["detail"]
|
||||
assert store.subscriptions(source="search") == []
|
||||
|
||||
|
||||
def test_a_board_is_followed_only_if_it_answers(
|
||||
client: TestClient, store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
import plugins.ats as ats
|
||||
|
||||
monkeypatch.setattr(ats, "fetch_board", lambda target: [{"source_id": "1"}])
|
||||
res = client.post("/api/boards", json={"board": "ashby:acme", "name": "Acme"})
|
||||
assert res.status_code == 201
|
||||
assert res.json()["found"] == 1 and res.json()["source"]["target"] == "ashby:acme"
|
||||
assert store.company("acme") is not None
|
||||
|
||||
again = client.post("/api/boards", json={"board": "ashby:acme", "name": "Acme"})
|
||||
assert again.status_code == 422 and "already followed" in again.json()["detail"]
|
||||
bad = client.post("/api/boards", json={"board": "acme", "name": "Other"})
|
||||
assert bad.status_code == 422 and "host:slug" in bad.json()["detail"]
|
||||
|
||||
|
||||
def test_prune_previews_then_switches_off(client: TestClient, store: Store) -> None:
|
||||
us = store.add_subscription("ats", "greenhouse:us", label="US", company="US",
|
||||
board="greenhouse")
|
||||
dk = store.add_subscription("ats", "greenhouse:dk", label="DK", company="DK",
|
||||
board="greenhouse")
|
||||
store.upsert_role(posting("1", company="US", place="Boston, MA"), us)
|
||||
store.upsert_role(posting("2", company="DK", place="Copenhagen"), dk)
|
||||
|
||||
preview = client.get("/api/prune", params={"region": "DK,EU"}).json()
|
||||
assert [b["label"] for b in preview["boards"]] == ["US"]
|
||||
assert len(store.subscriptions(source="ats", fetchable=True)) == 2
|
||||
|
||||
done = client.post("/api/prune", json={"region": "DK,EU"}).json()
|
||||
assert (done["pruned"], done["roles_closed"], done["boards_left"]) == (1, 1, 1)
|
||||
assert client.get("/api/prune", params={"region": " "}).status_code == 422
|
||||
Reference in new issue
Block a user