Files
apocapoc-api/internal/domain/entities/habit_entry_test.go
T
david 7cb2756b67
CI/CD Pipeline / Test (push) Has been cancelled
CI/CD Pipeline / Lint (push) Has been cancelled
CI/CD Pipeline / Build and Push Docker Image (push) Has been cancelled
Implement Sprint 2 security enhancements
Add user-based rate limiting middleware (100 req/min) for authenticated endpoints using httprate library. Implement common password validation blocking 50+ weak passwords. Improve test coverage from 38.3% to 44.6% with comprehensive refresh token tests.

Security improvements:
- Rate limiting by user ID for /habits and /stats endpoints
- X-RateLimit-Limit header in responses
- Common password blacklist in password validation
- Refresh token test suite with 5 scenarios (valid, invalid, expired, revoked, empty)
2025-11-27 10:33:01 +01:00

46 lines
983 B
Go

package entities
import (
"testing"
"time"
)
func TestNewHabitEntry(t *testing.T) {
habitID := "habit-123"
scheduledDate := time.Now().Truncate(24 * time.Hour)
value := 5.0
entry := NewHabitEntry(habitID, scheduledDate, &value)
if entry.HabitID != habitID {
t.Errorf("Expected HabitID %s, got %s", habitID, entry.HabitID)
}
if !entry.ScheduledDate.Equal(scheduledDate) {
t.Errorf("Expected ScheduledDate %v, got %v", scheduledDate, entry.ScheduledDate)
}
if entry.Value == nil {
t.Error("Value should not be nil")
}
if *entry.Value != value {
t.Errorf("Expected Value %f, got %f", value, *entry.Value)
}
if entry.CompletedAt.IsZero() {
t.Error("CompletedAt should not be zero")
}
}
func TestNewHabitEntry_BooleanHabit(t *testing.T) {
habitID := "habit-123"
scheduledDate := time.Now().Truncate(24 * time.Hour)
entry := NewHabitEntry(habitID, scheduledDate, nil)
if entry.Value != nil {
t.Error("Value should be nil for boolean habit")
}
}