Cover matcher and API scenarios

This commit is contained in:
Fiden
2026-08-07 13:15:43 +00:00
parent a67826daa4
commit 11e1a4c4a2
7 changed files with 265 additions and 4 deletions
+49
View File
@@ -0,0 +1,49 @@
from __future__ import annotations
from fastapi.testclient import TestClient
from app.main import app
client = TestClient(app)
def test_service_exposes_only_match_endpoint() -> None:
application_paths = [route.path for route in app.routes]
assert application_paths == ["/match"]
def test_match_contract_and_message_order() -> None:
messages = [
"бур sds 10х210",
"где находится ваш магазин",
"нужен кабель",
]
response = client.post("/match", json={"messages": messages})
assert response.status_code == 200
body = response.json()
assert set(body) == {"results"}
assert [result["message"] for result in body["results"]] == messages
assert [result["status"] for result in body["results"]] == [
"matched",
"not_found",
"ambiguous",
]
for result in body["results"]:
assert set(result) == {"message", "status", "candidates"}
assert len(result["candidates"]) <= 3
for candidate in result["candidates"]:
assert set(candidate) == {"sku", "confidence"}
assert 0.0 <= candidate["confidence"] <= 1.0
def test_empty_message_list_is_valid() -> None:
response = client.post("/match", json={"messages": []})
assert response.status_code == 200
assert response.json() == {"results": []}
def test_unknown_request_fields_are_rejected() -> None:
response = client.post("/match", json={"messages": [], "debug": True})
assert response.status_code == 422