Add, edit, check and delete a company by hand through the API, and show the by-hand fields in the list

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Sonnet 5.5 committed 2026-09-29 17:02:19 +02:00
1 parent b3cb93d5aa
commit 28afc334c3
2 files changed
+259 -24

No files matched your search

+153 -8
View File
@@ -421,24 +421,27 @@ def test_companies_lists_board_and_open_role_count(
store.add_company("Acme", key="acme", ats="greenhouse", country="DK")
store.upsert_role(posting("1", company="Acme"), sub)
store.add_company("Other", key="other", domain="other.example") # no board found
store.add_company("Novo", key="novo", ats="successfactors", # followed, not readable
store.add_company("Novo", key="novo", ats="taleo", # followed, not readable
careers_url="https://novo.example/careers")
res = client.get("/api/companies")
assert res.status_code == 200
[row] = [c for c in res.json() if c["key"] == "acme"]
assert row == {"key": "acme", "name": "Acme", "board": "greenhouse",
"subscription_id": sub.id, "on": True, "affinity": 0, "open_roles": 1,
"ats": "greenhouse", "ats_slug": "", "careers_url": "",
"country": "DK", "failing_since": "", "failing_reason": "",
"from_search": False}
assert row == {"key": "acme", "name": "Acme", "domain": "", "notes": "",
"board": "greenhouse", "subscription_id": sub.id, "on": True,
"affinity": 0, "open_roles": 1, "ats": "greenhouse", "ats_slug": "",
"careers_url": "", "country": "DK", "failing_since": "",
"failing_reason": "", "from_search": False, "hand_reason": "",
"checked_at": "", "by_hand": False}
[other] = [c for c in res.json() if c["key"] == "other"]
assert (other["board"], other["subscription_id"], other["on"], other["ats"]) == (
"", None, None, "")
[novo] = [c for c in res.json() if c["key"] == "novo"]
assert (novo["board"], novo["subscription_id"], novo["ats"], novo["careers_url"]) == (
"", None, "successfactors", "https://novo.example/careers")
"", None, "taleo", "https://novo.example/careers")
assert not any(c["from_search"] for c in res.json())
# Companies with no board shown, unread or not, are the list checked by hand.
assert {c["key"] for c in res.json() if c["by_hand"]} == {"other", "novo"}
def test_judging_a_company_known_only_from_a_search_creates_its_row(
@@ -1214,10 +1217,152 @@ def test_a_companys_board_is_set_replaced_and_detached(
assert client.post("/api/companies/nope/board",
json={"board": "lever:acme"}).status_code == 404
assert client.delete("/api/companies/nope/board").status_code == 404
bad = client.post("/api/companies/acme/board", json={"board": "workday:acme"})
bad = client.post("/api/companies/acme/board", json={"board": "taleo:acme"})
assert bad.status_code == 422 and "host:slug" in bad.json()["detail"]
def test_a_company_is_added_by_hand_with_a_reason_and_a_link(
client: TestClient, store: Store) -> None:
res = client.post("/api/companies", json={
"name": "Revolut Ltd", "careers_url": " https://revolut.example/careers ",
"notes": "wants a login"})
assert res.status_code == 201, res.text
assert res.json() == {
"key": "revolut", "name": "Revolut Ltd", "domain": "", "notes": "wants a login",
"board": "", "subscription_id": None, "on": None, "affinity": 0, "open_roles": 0,
"ats": "", "ats_slug": "", "careers_url": "https://revolut.example/careers",
"country": "", "failing_since": "", "failing_reason": "", "from_search": False,
"hand_reason": "added", "checked_at": "", "by_hand": True}
assert store.company("revolut").hand_reason == "added" # type: ignore[union-attr]
other = client.post("/api/companies", json={"name": "Meta", "hand_reason": "blocked"})
assert other.status_code == 201 and other.json()["hand_reason"] == "blocked"
# The key comes from the name, so a legal suffix or case is the same company.
assert client.post("/api/companies", json={"name": "REVOLUT"}).status_code == 409
assert store.company("revolut").notes == "wants a login" # type: ignore[union-attr]
def test_adding_a_company_by_hand_refuses_a_bad_link_reason_or_name(
client: TestClient, store: Store) -> None:
for link in ("javascript:alert(1)", "ftp://x.example/jobs", "revolut.example/careers",
"https://"):
res = client.post("/api/companies", json={"name": "Revolut", "careers_url": link})
assert res.status_code == 422, link
assert client.post("/api/companies", json={"name": "Revolut", "careers_url": ""}
).status_code == 201
assert client.post("/api/companies", json={"name": "Meta", "hand_reason": "lazy"}
).status_code == 422
assert client.post("/api/companies", json={"name": " "}).status_code == 422
assert client.post("/api/companies", json={}).status_code == 422
assert [c.key for c in store.companies()] == ["revolut"]
def test_a_company_from_a_search_only_is_no_longer_one_once_it_has_a_reason(
client: TestClient, store: Store) -> None:
store.save_agent("A")
search = store.add_subscription("search", "jobindex:cph", label="cph", board="jobindex")
item = posting("1", company="Novo")
item.source = "search"
store.upsert_role(item, search)
client.post("/api/companies/novo/affinity", json={"affinity": 1})
[row] = client.get("/api/companies").json()
assert (row["from_search"], row["by_hand"]) == (True, False)
res = client.patch("/api/companies/novo", json={"hand_reason": "unread"})
assert res.status_code == 200
assert (res.json()["from_search"], res.json()["by_hand"]) == (False, True)
def test_a_company_is_edited_and_only_the_fields_sent_change(
client: TestClient, store: Store) -> None:
store.add_company("Acme", key="acme", careers_url="https://acme.example/jobs",
notes="old", hand_reason="unread")
res = client.patch("/api/companies/acme", json={"notes": "new", "name": "Acme Labs"})
assert res.status_code == 200, res.text
body = res.json()
assert (body["key"], body["name"], body["notes"], body["careers_url"],
body["hand_reason"]) == ("acme", "Acme Labs", "new", "https://acme.example/jobs",
"unread")
# A link and a reason can be cleared, since "" is a value.
res = client.patch("/api/companies/acme", json={"careers_url": "", "hand_reason": ""})
assert (res.json()["careers_url"], res.json()["hand_reason"]) == ("", "")
assert client.patch("/api/companies/acme", json={}).status_code == 200
assert client.patch("/api/companies/acme", json={"careers_url": "javascript:x"}
).status_code == 422
assert client.patch("/api/companies/acme", json={"hand_reason": "lazy"}).status_code == 422
assert client.patch("/api/companies/acme", json={"name": " "}).status_code == 422
assert client.patch("/api/companies/acme", json={"notes": None}).status_code == 422
assert client.patch("/api/companies/nope", json={"notes": "x"}).status_code == 404
assert store.company("acme").name == "Acme Labs" # type: ignore[union-attr]
def test_a_company_with_a_board_keeps_its_name_and_takes_the_other_edits(
client: TestClient, store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
import plugins.ats as ats
monkeypatch.setattr(ats, "fetch_board", lambda target: ([], True))
store.add_company("Acme", key="acme")
assert client.post("/api/companies/acme/board", json={"board": "greenhouse:acme"}
).status_code == 200
res = client.patch("/api/companies/acme", json={"name": "Acme Labs"})
assert res.status_code == 409 and "detach" in res.json()["detail"]
assert client.patch("/api/companies/acme", json={"name": "Acme"}).status_code == 200
assert client.patch("/api/companies/acme", json={"notes": "hi"}).status_code == 200
# Detached, the subscription is still there and the name stays fixed.
client.delete("/api/companies/acme/board")
assert client.patch("/api/companies/acme", json={"name": "Acme Labs"}).status_code == 409
assert store.company("acme").name == "Acme" # type: ignore[union-attr]
def test_checking_a_company_stamps_now(client: TestClient, store: Store) -> None:
clock = Clock()
store.clock = clock
store.add_company("Acme", key="acme", hand_reason="unread")
res = client.post("/api/companies/acme/checked")
assert res.status_code == 200
assert res.json()["checked_at"] == "2026-09-23T09:00:00+00:00"
clock.tick(48)
assert client.post("/api/companies/acme/checked").json()["checked_at"] == (
"2026-09-25T09:00:00+00:00")
assert client.post("/api/companies/nope/checked").status_code == 404
def test_a_company_is_deleted_unless_it_is_read(
client: TestClient, store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
import plugins.ats as ats
monkeypatch.setattr(ats, "fetch_board", lambda target: ([], True))
agent = store.save_agent("A")
store.add_company("Meta", key="meta", hand_reason="blocked")
store.set_affinity(agent.id, "meta", 1)
res = client.delete("/api/companies/meta")
assert res.status_code == 204 and res.content == b""
assert store.company("meta") is None
assert store.company("meta", agent.id) is None
assert client.delete("/api/companies/meta").status_code == 404
assert "meta" not in {c["key"] for c in client.get("/api/companies").json()}
# A board shown: refused until it is detached; a detached board is no board.
store.add_company("Acme", key="acme")
sub_id = client.post("/api/companies/acme/board", json={"board": "greenhouse:acme"}
).json()["source"]["id"]
res = client.delete("/api/companies/acme")
assert res.status_code == 409 and "greenhouse:acme" in res.json()["detail"]
store.upsert_role(posting("1", company="Acme"), store.subscription(sub_id))
client.delete("/api/companies/acme/board")
assert client.delete("/api/companies/acme").status_code == 204
# Open roles hold a company even where no board is on: they would be
# orphaned from the list.
store.add_company("Beta", key="beta")
store.upsert_role(posting("2", company="Beta"))
res = client.delete("/api/companies/beta")
assert res.status_code == 409 and "open roles" in res.json()["detail"]
assert store.company("beta") is not None
def test_the_pull_a_source_switch_queues_is_refused_quietly_while_one_runs(
app: FastAPI, store: Store) -> None:
"""The four actions that queue a `pull` (switching a source on, following