refactor(server/api/test): withUser helper; migrate 51 context-value sites (A3)

This commit is contained in:
2026-05-08 10:39:11 -04:00
parent bf90a3a868
commit c81491164a
11 changed files with 12 additions and 12 deletions
+2 -2
View File
@@ -212,7 +212,7 @@ func TestHandleLogout_DeletesSessionAndClearsCookie(t *testing.T) {
req.AddCookie(&http.Cookie{Name: auth.SessionCookieName, Value: token})
// handleLogout runs behind RequireUser in real routing; simulate that by
// putting the user into context here.
req = req.WithContext(context.WithValue(req.Context(), userCtxKeyForTest(), user))
req = withUser(req, user)
w := httptest.NewRecorder()
h.handleLogout(w, req)
@@ -256,7 +256,7 @@ func TestHandleLogout_BearerHeaderWithTrailingWhitespaceDeletesSession(t *testin
req := httptest.NewRequest(http.MethodPost, "/api/auth/logout", nil)
// Trailing whitespace — RequireUser trims this, so logout must too.
req.Header.Set("Authorization", "Bearer "+token+" ")
req = req.WithContext(context.WithValue(req.Context(), userCtxKeyForTest(), user))
req = withUser(req, user)
w := httptest.NewRecorder()
h.handleLogout(w, req)