diff --git a/aurweb/routers/rpc.py b/aurweb/routers/rpc.py index 25574ff8..23978f1d 100644 --- a/aurweb/routers/rpc.py +++ b/aurweb/routers/rpc.py @@ -281,3 +281,15 @@ async def rpc_openapi_search_post( arg, [], ) + + +@router.get("/rpc/v{version}/suggest/{arg}") +async def rpc_openapi_suggest(request: Request, version: int, arg: str): + return await rpc_request( + request, + version, + "suggest", + defaults.RPC_SEARCH_BY, + arg, + [], + ) diff --git a/test/test_rpc.py b/test/test_rpc.py index e5b37542..84ddd8d7 100644 --- a/test/test_rpc.py +++ b/test/test_rpc.py @@ -1040,3 +1040,19 @@ def test_rpc_openapi_search_post_bad_request(client: TestClient): data = resp.json() expected = "the 'arg' parameter must be of string type" assert data.get("error") == expected + + +def test_rpc_openapi_suggest(client: TestClient, packages: list[Package]): + suggestions = { + "big": ["big-chungus"], + "chungy": ["chungy-chungus"], + } + + for term, expected in suggestions.items(): + with client as request: + endp = f"/rpc/v5/suggest/{term}" + resp = request.get(endp) + assert resp.status_code == HTTPStatus.OK + + data = resp.json() + assert data == expected