Skip to content

Commit e294a80

Browse files
authored
fix: safe router navigation encoding and /users/search test coverage (#133)
1 parent 2c4a404 commit e294a80

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

backend/api/internal/tests/main_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func setupTestRouter() *gin.Engine {
8080
router.GET("/auth/me", handlers.RequireAuth(), handlers.GetMe)
8181

8282
router.GET("/users", handlers.GetUsers)
83+
router.GET("/users/search", handlers.SearchUsers)
8384
router.GET("/users/:username", handlers.GetUserByUsername)
8485
router.GET("/users/id/:user_id", handlers.GetUserById)
8586
router.POST("/users", handlers.RequireAuth(), handlers.CreateUser)

backend/api/internal/tests/user_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,26 @@ var user_tests = []TestCase{
199199
ExpectedStatus: http.StatusOK,
200200
ExpectedBody: `null`,
201201
},
202+
203+
// search users – empty q returns empty array
204+
{
205+
Method: http.MethodGet,
206+
Endpoint: "/users/search?q=",
207+
ExpectedStatus: http.StatusOK,
208+
ExpectedBody: `[]`,
209+
},
210+
// search users – prefix match returns matching users
211+
{
212+
Method: http.MethodGet,
213+
Endpoint: "/users/search?q=dev",
214+
ExpectedStatus: http.StatusOK,
215+
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"}]`,
216+
},
217+
// search users – count is capped at 20
218+
{
219+
Method: http.MethodGet,
220+
Endpoint: "/users/search?q=d&count=100",
221+
ExpectedStatus: http.StatusOK,
222+
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"}]`,
223+
},
202224
}

frontend/app/(tabs)/message.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ export default function MessageScreen() {
313313
setShowNewChatModal(false);
314314
setSearchQuery("");
315315
setSuggestions([]);
316-
router.push(`/conversation/${username}`);
316+
router.push({ pathname: "/conversation/[username]", params: { username } });
317317
};
318318

319319
const handleNewChat = () => {
@@ -342,7 +342,7 @@ export default function MessageScreen() {
342342
setShowNewChatModal(false);
343343
setSearchQuery("");
344344
setSuggestions([]);
345-
router.push(`/conversation/${username}`);
345+
router.push({ pathname: "/conversation/[username]", params: { username } });
346346
};
347347

348348
const renderSuggestion = ({

0 commit comments

Comments
 (0)