diff --git a/backend/api/internal/tests/main_test.go b/backend/api/internal/tests/main_test.go index 38baf53..fdf06e0 100644 --- a/backend/api/internal/tests/main_test.go +++ b/backend/api/internal/tests/main_test.go @@ -80,6 +80,7 @@ func setupTestRouter() *gin.Engine { router.GET("/auth/me", handlers.RequireAuth(), handlers.GetMe) router.GET("/users", handlers.GetUsers) + router.GET("/users/search", handlers.SearchUsers) router.GET("/users/:username", handlers.GetUserByUsername) router.GET("/users/id/:user_id", handlers.GetUserById) router.POST("/users", handlers.RequireAuth(), handlers.CreateUser) diff --git a/backend/api/internal/tests/user_test.go b/backend/api/internal/tests/user_test.go index 27a187e..79f5214 100644 --- a/backend/api/internal/tests/user_test.go +++ b/backend/api/internal/tests/user_test.go @@ -199,4 +199,26 @@ var user_tests = []TestCase{ ExpectedStatus: http.StatusOK, ExpectedBody: `null`, }, + + // search users – empty q returns empty array + { + Method: http.MethodGet, + Endpoint: "/users/search?q=", + ExpectedStatus: http.StatusOK, + ExpectedBody: `[]`, + }, + // search users – prefix match returns matching users + { + Method: http.MethodGet, + Endpoint: "/users/search?q=dev", + ExpectedStatus: http.StatusOK, + ExpectedBody: `[{"bio":"Full-stack developer passionate about open-source projects.","creation_date":"2023-12-13T00:00:00Z","id":1,"links":["https://github.com/dev_user1","https://devuser1.com"],"picture":"https://example.com/dev_user1.jpg","settings":{"accentColor":"","backgroundRefreshEnabled":false,"compactMode":false,"refreshIntervalMs":120000,"zenMode":false},"username":"dev_user1"}]`, + }, + // search users – count is capped at 20 + { + Method: http.MethodGet, + Endpoint: "/users/search?q=d&count=100", + ExpectedStatus: http.StatusOK, + ExpectedBody: `[{"bio":"Data scientist with a passion for machine learning.","creation_date":"2023-06-13T00:00:00Z","id":3,"links":["https://github.com/data_scientist3","https://datascientist3.com"],"picture":"https://example.com/data_scientist3.jpg","settings":{"accentColor":"","backgroundRefreshEnabled":false,"compactMode":false,"refreshIntervalMs":120000,"zenMode":false},"username":"data_scientist3"},{"bio":"Full-stack developer passionate about open-source projects.","creation_date":"2023-12-13T00:00:00Z","id":1,"links":["https://github.com/dev_user1","https://devuser1.com"],"picture":"https://example.com/dev_user1.jpg","settings":{"accentColor":"","backgroundRefreshEnabled":false,"compactMode":false,"refreshIntervalMs":120000,"zenMode":false},"username":"dev_user1"}]`, + }, } diff --git a/frontend/app/(tabs)/message.tsx b/frontend/app/(tabs)/message.tsx index e9a2ae9..dcb4294 100644 --- a/frontend/app/(tabs)/message.tsx +++ b/frontend/app/(tabs)/message.tsx @@ -313,7 +313,7 @@ export default function MessageScreen() { setShowNewChatModal(false); setSearchQuery(""); setSuggestions([]); - router.push(`/conversation/${username}`); + router.push({ pathname: "/conversation/[username]", params: { username } }); }; const handleNewChat = () => { @@ -342,7 +342,7 @@ export default function MessageScreen() { setShowNewChatModal(false); setSearchQuery(""); setSuggestions([]); - router.push(`/conversation/${username}`); + router.push({ pathname: "/conversation/[username]", params: { username } }); }; const renderSuggestion = ({