Merge the Roles feed: rail note on the fetch gate, Show gated in every order, saved filters per agent, the company strip naming the gate's parts (wp-feed)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
553042f1fc
4 files changed
+402
-28
No files matched your search
@@ -0,0 +1,83 @@
|
||||
"""The Roles page's part of the ranking flow (docs/architecture.md, "5 Feed"):
|
||||
the note that the feed keeps to the agent's fetch gate, the saved filters in
|
||||
the rail and the routes they call, as `static/roles.js` uses them. A temp
|
||||
database and FastAPI's TestClient; no browser."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterator
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.config import Config, ServerConfig
|
||||
from app.main import create_app
|
||||
from app.storage import Store
|
||||
|
||||
STATIC = Path(__file__).resolve().parent.parent / "app" / "static"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app(tmp_path: Path) -> FastAPI:
|
||||
return create_app(Config(server=ServerConfig(host="127.0.0.1", port=0),
|
||||
database=tmp_path / "roledesk.db"))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def store(app: FastAPI) -> Store:
|
||||
return app.state.store
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(app: FastAPI) -> Iterator[TestClient]:
|
||||
with TestClient(app) as c:
|
||||
yield c
|
||||
|
||||
|
||||
def test_the_rail_says_the_feed_keeps_to_the_fetch_gate_and_offers_saved_filters(
|
||||
client: TestClient) -> None:
|
||||
page = client.get("/").text
|
||||
assert 'id="agent-gate"' in page
|
||||
for name in ("saved", "saved-list", "save-open", "save-form", "save-name", "saved-note"):
|
||||
assert f'id="{name}"' in page
|
||||
script = (STATIC / "roles.js").read_text()
|
||||
assert "Already filtered by this agent's fetch gate" in script
|
||||
# The name is asked in the page, never by a browser prompt.
|
||||
assert "prompt(" not in script
|
||||
|
||||
|
||||
def test_no_text_says_a_favourite_skips_the_places() -> None:
|
||||
script = (STATIC / "roles.js").read_text()
|
||||
for stale in ("outside your places", "Kept out of the ranking", "required gates allow"):
|
||||
assert stale not in script
|
||||
|
||||
|
||||
def test_a_saved_filter_round_trips_the_query_roles_js_writes(
|
||||
client: TestClient, store: Store) -> None:
|
||||
agent = store.save_agent("Wolf")
|
||||
query = "q=engineer&remote=remote&places=country%3ADK&gated=true&sort=time"
|
||||
|
||||
made = client.post(f"/api/agents/{agent.id}/filters",
|
||||
json={"name": "Remote engineers", "query": query})
|
||||
assert made.status_code == 201
|
||||
assert made.json()["query"] == query
|
||||
|
||||
listed = client.get(f"/api/agents/{agent.id}/filters").json()
|
||||
assert [(f["name"], f["query"]) for f in listed] == [("Remote engineers", query)]
|
||||
|
||||
# Case does not make a second name; the page says the 409 under the field.
|
||||
twice = client.post(f"/api/agents/{agent.id}/filters",
|
||||
json={"name": "remote ENGINEERS", "query": ""})
|
||||
assert twice.status_code == 409 and twice.json()["detail"]
|
||||
assert client.post(f"/api/agents/{agent.id}/filters",
|
||||
json={"name": " ", "query": ""}).status_code == 422
|
||||
assert client.get("/api/agents/999/filters").status_code == 404
|
||||
|
||||
gone = client.delete(f"/api/filters/{made.json()['id']}")
|
||||
assert gone.status_code == 204
|
||||
# A second delete, from a page that had not heard of the first, is a 404
|
||||
# the page treats as done.
|
||||
assert client.delete(f"/api/filters/{made.json()['id']}").status_code == 404
|
||||
assert client.get(f"/api/agents/{agent.id}/filters").json() == []
|
||||
Reference in new issue
Block a user