feat: replace age integer with date_of_birth across backend and client
Store date_of_birth (DATE) instead of a static age integer so that age is always computed dynamically from the stored date of birth. - Migration 011: adds date_of_birth, backfills from age, drops age - AgeFromDOB helper computes current age from YYYY-MM-DD string - User model, repository SQL, and service validation updated - Flutter: User.age becomes a computed getter; profile edit screen uses a date picker bounded to [today-120y, today-10y] Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,10 +2,48 @@ package user
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func ptr[T any](v T) *T { return &v }
|
||||
|
||||
func TestAgeFromDOB_Nil(t *testing.T) {
|
||||
if AgeFromDOB(nil) != nil {
|
||||
t.Fatal("expected nil for nil input")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgeFromDOB_InvalidFormat(t *testing.T) {
|
||||
s := "not-a-date"
|
||||
if AgeFromDOB(&s) != nil {
|
||||
t.Fatal("expected nil for invalid format")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgeFromDOB_ExactAge(t *testing.T) {
|
||||
dob := time.Now().AddDate(-30, 0, 0).Format("2006-01-02")
|
||||
age := AgeFromDOB(&dob)
|
||||
if age == nil {
|
||||
t.Fatal("expected non-nil result")
|
||||
}
|
||||
if *age != 30 {
|
||||
t.Errorf("expected 30, got %d", *age)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgeFromDOB_BeforeBirthday(t *testing.T) {
|
||||
// Birthday is one day in the future relative to today-25y, so age should be 24
|
||||
now := time.Now()
|
||||
dob := time.Date(now.Year()-25, now.Month(), now.Day()+1, 0, 0, 0, 0, time.UTC).Format("2006-01-02")
|
||||
age := AgeFromDOB(&dob)
|
||||
if age == nil {
|
||||
t.Fatal("expected non-nil result")
|
||||
}
|
||||
if *age != 24 {
|
||||
t.Errorf("expected 24, got %d", *age)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCalculateDailyCalories_MaleMaintain(t *testing.T) {
|
||||
cal := CalculateDailyCalories(ptr(180), ptr(80.0), ptr(30), ptr("male"), ptr("moderate"), ptr("maintain"))
|
||||
if cal == nil {
|
||||
|
||||
Reference in New Issue
Block a user