tercul-backend/internal/testutil/mock_jwt_manager.go
Damir Mukimov d50722dad5
Some checks failed
Test / Integration Tests (push) Successful in 4s
Build / Build Binary (push) Failing after 2m9s
Docker Build / Build Docker Image (push) Failing after 2m32s
Test / Unit Tests (push) Failing after 3m12s
Lint / Go Lint (push) Failing after 1m0s
Refactor ID handling to use UUIDs across the application
- Updated database models and repositories to replace uint IDs with UUIDs.
- Modified test fixtures to generate and use UUIDs for authors, translations, users, and works.
- Adjusted mock implementations to align with the new UUID structure.
- Ensured all relevant functions and methods are updated to handle UUIDs correctly.
- Added necessary imports for UUID handling in various files.
2025-12-27 00:33:34 +01:00

42 lines
1.1 KiB
Go

package testutil
import (
"tercul/internal/domain"
"tercul/internal/platform/auth"
"time"
"github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
)
// MockJWTManager is a mock implementation of the JWTManagement interface.
type MockJWTManager struct{}
// NewMockJWTManager creates a new MockJWTManager.
func NewMockJWTManager() auth.JWTManagement {
return &MockJWTManager{}
}
// GenerateToken generates a dummy token for a user.
func (m *MockJWTManager) GenerateToken(user *domain.User) (string, error) {
return "dummy-token-for-" + user.Username, nil
}
// ValidateToken validates a dummy token.
func (m *MockJWTManager) ValidateToken(tokenString string) (*auth.Claims, error) {
if tokenString != "" {
// A real implementation would parse the user from the token.
// For this mock, we'll just return a generic user.
return &auth.Claims{
UserID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440106"),
Username: "testuser",
Email: "test@test.com",
Role: "reader",
RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(time.Now().Add(24 * time.Hour)),
},
}, nil
}
return nil, auth.ErrInvalidToken
}