package account import ( "testing" "time" "galaxy/user/internal/domain/common" "github.com/stretchr/testify/require" ) func TestUserAccountValidate(t *testing.T) { t.Parallel() createdAt := time.Unix(1_775_240_000, 0).UTC() updatedAt := createdAt.Add(2 * time.Hour) tests := []struct { name string record UserAccount wantErr bool }{ { name: "valid without declared country", record: UserAccount{ UserID: common.UserID("user-123"), Email: common.Email("pilot@example.com"), RaceName: common.RaceName("Pilot Nova"), PreferredLanguage: common.LanguageTag("en"), TimeZone: common.TimeZoneName("Europe/Berlin"), CreatedAt: createdAt, UpdatedAt: updatedAt, }, }, { name: "valid with declared country", record: UserAccount{ UserID: common.UserID("user-123"), Email: common.Email("pilot@example.com"), RaceName: common.RaceName("Pilot Nova"), PreferredLanguage: common.LanguageTag("en"), TimeZone: common.TimeZoneName("Europe/Berlin"), DeclaredCountry: common.CountryCode("DE"), CreatedAt: createdAt, UpdatedAt: updatedAt, }, }, { name: "updated before created", record: UserAccount{ UserID: common.UserID("user-123"), Email: common.Email("pilot@example.com"), RaceName: common.RaceName("Pilot Nova"), PreferredLanguage: common.LanguageTag("en"), TimeZone: common.TimeZoneName("Europe/Berlin"), CreatedAt: createdAt, UpdatedAt: createdAt.Add(-time.Second), }, wantErr: true, }, } for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() err := tt.record.Validate() if tt.wantErr { require.Error(t, err) return } require.NoError(t, err) }) } } func TestRaceNameReservationValidate(t *testing.T) { t.Parallel() tests := []struct { name string record RaceNameReservation wantErr bool }{ { name: "valid", record: RaceNameReservation{ CanonicalKey: RaceNameCanonicalKey("pilot-nova"), UserID: common.UserID("user-123"), RaceName: common.RaceName("Pilot Nova"), ReservedAt: time.Unix(1_775_240_100, 0).UTC(), }, }, { name: "empty canonical key", record: RaceNameReservation{ UserID: common.UserID("user-123"), RaceName: common.RaceName("Pilot Nova"), ReservedAt: time.Unix(1_775_240_100, 0).UTC(), }, wantErr: true, }, } for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() err := tt.record.Validate() if tt.wantErr { require.Error(t, err) return } require.NoError(t, err) }) } }