generated from kgod/ai-review-template
feat: initialize resume agent with OfferPai sync
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from test_resume_patch_api import create_resume_with_anchor, first_entry
|
||||
|
||||
BASE = "/ai-api/resume-agent"
|
||||
|
||||
|
||||
def test_optimize_confirm_undo_flow(client: TestClient) -> None:
|
||||
session_id, body = create_resume_with_anchor(client)
|
||||
original = first_entry(body)["description"]
|
||||
entry_id = first_entry(body)["id"]
|
||||
|
||||
response = client.post(
|
||||
f"{BASE}/sessions/{session_id}/resume/optimize", json={"entry_id": entry_id}
|
||||
)
|
||||
assert response.status_code == 200
|
||||
entry = first_entry(response.json())
|
||||
proposal = entry["pending_proposal"]
|
||||
assert proposal["source"] == "rule_polish"
|
||||
assert proposal["optimized_description"] == "完成课程设计。"
|
||||
assert entry["description"] == original
|
||||
|
||||
response = client.post(
|
||||
f"{BASE}/sessions/{session_id}/resume/optimize/confirm",
|
||||
json={"entry_id": entry_id},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
entry = first_entry(response.json())
|
||||
assert "pending_proposal" not in entry
|
||||
assert entry["description"] == "完成课程设计。"
|
||||
assert entry["provenance"] == "rule_polish"
|
||||
assert entry["previous_version"]["description"] == original
|
||||
|
||||
response = client.post(
|
||||
f"{BASE}/sessions/{session_id}/resume/optimize/undo",
|
||||
json={"entry_id": entry_id},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
entry = first_entry(response.json())
|
||||
assert entry["description"] == original
|
||||
assert "previous_version" not in entry
|
||||
|
||||
|
||||
def test_optimize_reject(client: TestClient) -> None:
|
||||
session_id, body = create_resume_with_anchor(client)
|
||||
original = first_entry(body)["description"]
|
||||
entry_id = first_entry(body)["id"]
|
||||
client.post(f"{BASE}/sessions/{session_id}/resume/optimize", json={"entry_id": entry_id})
|
||||
response = client.post(
|
||||
f"{BASE}/sessions/{session_id}/resume/optimize/reject",
|
||||
json={"entry_id": entry_id},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
entry = first_entry(response.json())
|
||||
assert "pending_proposal" not in entry
|
||||
assert entry["description"] == original
|
||||
|
||||
|
||||
def test_optimize_unknown_entry_404(client: TestClient) -> None:
|
||||
session_id, _ = create_resume_with_anchor(client)
|
||||
response = client.post(
|
||||
f"{BASE}/sessions/{session_id}/resume/optimize", json={"entry_id": "entry_nope"}
|
||||
)
|
||||
assert response.status_code == 404
|
||||
assert response.json()["error"]["code"] == "entry_not_found"
|
||||
|
||||
|
||||
def test_confirm_without_proposal_422(client: TestClient) -> None:
|
||||
session_id, body = create_resume_with_anchor(client)
|
||||
entry_id = first_entry(body)["id"]
|
||||
response = client.post(
|
||||
f"{BASE}/sessions/{session_id}/resume/optimize/confirm",
|
||||
json={"entry_id": entry_id},
|
||||
)
|
||||
assert response.status_code == 422
|
||||
assert response.json()["error"]["code"] == "optimize_not_pending"
|
||||
Reference in New Issue
Block a user