diff --git a/app/main.py b/app/main.py index dc3dff6..db37360 100644 --- a/app/main.py +++ b/app/main.py @@ -79,4 +79,4 @@ def search_profiles( for p in profile_store.values() if q.lower() in p["username"].lower() or q.lower() in p["bio"].lower() ] - return {"results": results[offset : offset + limit - 1], "total": len(results)} + return {"results": results[offset : offset + limit], "total": len(results)} diff --git a/tests/test_search.py b/tests/test_search.py index 4e1f460..1c48c22 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -8,7 +8,7 @@ client = TestClient(app) -def test_search_with_query(): +def test_search_with_query(clean_store): profile_store["alice"] = {"username": "alice", "bio": "dev"} profile_store["alex"] = {"username": "alex", "bio": "designer"} profile_store["bob"] = {"username": "bob", "bio": "manager"} @@ -19,8 +19,21 @@ def test_search_with_query(): assert len(data["results"]) == 2 -def test_search_empty_query(): +def test_search_empty_query(clean_store): profile_store["carol"] = {"username": "carol", "bio": "tester"} response = client.get("/search?q=") data = response.json() assert data["total"] > 0 + + +def test_search_pagination(clean_store): + profile_store["alice"] = {"username": "alice", "bio": "dev"} + profile_store["alex"] = {"username": "alex", "bio": "designer"} + profile_store["anna"] = {"username": "anna", "bio": "engineer"} + profile_store["amy"] = {"username": "amy", "bio": "tester"} + profile_store["adam"] = {"username": "adam", "bio": "manager"} + + response = client.get("/search?q=a&limit=3") + data = response.json() + assert data["total"] == 5 + assert len(data["results"]) == 3