refactor(server/api/test): withUser helper; migrate 51 context-value sites (A3)
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user