Files
multica/server/internal/handler/auth_session_test.go
Jiayuan Zhang bd6fb86173 feat(issues): consolidate thread navigation in the sidebar outline (#8120)
* feat(issues): consolidate thread navigation in the sidebar outline

* fix(auth): reject sessions whose user no longer exists
2026-09-07 18:12:23 +08:00

34 lines
945 B
Go

package handler
import (
"errors"
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/jackc/pgx/v5"
"github.com/multica-ai/multica/server/internal/testutil"
db "github.com/multica-ai/multica/server/pkg/db/generated"
)
func TestGetMeSessionFailures(t *testing.T) {
for _, tt := range []struct {
name string
err error
wantStatus int
}{
{"missing user", pgx.ErrNoRows, http.StatusUnauthorized},
{"wrapped missing user", fmt.Errorf("lookup: %w", pgx.ErrNoRows), http.StatusUnauthorized},
{"database unavailable", errors.New("connection refused"), http.StatusInternalServerError},
} {
t.Run(tt.name, func(t *testing.T) {
h := newTestHandler(Config{})
h.Queries = db.New(&mockDB{getUserErr: tt.err})
req := httptest.NewRequest(http.MethodGet, "/api/me", nil)
req.Header.Set("X-User-ID", "00000000-0000-4000-8000-000000000001")
testutil.Call(t, h.GetMe, req).Want(tt.wantStatus)
})
}
}