mirror of
https://gh-proxy.org/https://github.com/klinsmaya/multica.git
synced 2026-11-08 17:36:45 +08:00
* feat(issues): consolidate thread navigation in the sidebar outline * fix(auth): reject sessions whose user no longer exists
34 lines
945 B
Go
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)
|
|
})
|
|
}
|
|
}
|