ultisuite-backend/internal/api/middleware/testauth.go
R3D347HR4Y 747e0d4bb4 Add CI workflow and unit tests for mail API
- Created a CI workflow in `.github/workflows/ci.yml` to run Go tests and verify database migrations.
- Added unit tests for the mail API in `internal/api/mail/handlers_test.go`, covering message listing, retrieval, sending, and label updating.
- Introduced a service interface for the mail handler in `internal/api/mail/service_iface.go`.
- Updated mail handler initialization to accept a service API in `internal/api/mail/handlers.go`.
- Implemented test authentication middleware for testing purposes in `internal/api/middleware/testauth.go`.
- Added various test cases for IMAP and SMTP functionalities, ensuring robust error handling and validation.
- Enhanced project documentation with checklist updates for testing and CI integration.
2026-05-22 17:02:37 +02:00

20 lines
556 B
Go

package middleware
import (
"context"
"net/http"
"github.com/ultisuite/ulti-backend/internal/auth"
)
// WithTestClaims injects auth claims into the request context for handler tests.
// Production auth behavior is unchanged; use only in tests.
func WithTestClaims(claims *auth.Claims) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := context.WithValue(r.Context(), claimsKey, claims)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
}