Files
xarmian 6a63fba188 feat(store): add users.email_verified_at column + model plumbing (TASK-1935) (#805)
Wave 1 of PLAN-1933 (email verification). Pure infra — nothing reads the
column until Wave 3, so this is behaviourally a no-op and mergeable early.

- Migration 070 (SQLite) / 048 (Postgres): add nullable email_verified_at
  TEXT, mirroring disabled_at. UNCONDITIONALLY backfill every existing row
  to verified (RFC3339 'Z'-suffixed) so no existing / OAuth / self-host
  account is write-locked on deploy (inverted vs password_set's conditional
  backfill). SQLite ALTER without IF NOT EXISTS; Postgres with it.
- SAFE default = verified (DR-3): CreateUser / CreateOAuthUser write a
  verified timestamp unless UserCreate.Unverified is explicitly requested
  (only the future cloud self-serve branch will set that). A missed call
  site fails SAFE (verified), not write-locked.
- models.User.EmailVerifiedAt + IsEmailVerified() (mirror IsDisabled).
- Update userColumns + BOTH scan sites (scanUser AND the inline SearchUsers
  scan) so the admin user list keeps working.
- Expose derived email_verified bool in sessionUserPayload for a later wave.

Gates: make check + make test-pg both green (dual-dialect verified).

Claude-Session: https://claude.ai/code/session_01HxBkAMiFBtCRJ2tKSCt3ST
2026-07-04 00:45:48 -04:00

27 lines
806 B
Go

package models
import "testing"
// TestIsEmailVerified locks in the mirror-of-IsDisabled contract: a non-empty
// EmailVerifiedAt means verified, empty (the zero value / NULL round-trip)
// means unverified. PLAN-1933 / TASK-1935.
func TestIsEmailVerified(t *testing.T) {
cases := []struct {
name string
emailVerifiedAt string
want bool
}{
{"empty is unverified", "", false},
{"timestamp is verified", "2026-07-04T12:00:00Z", true},
{"any non-empty string is verified", "x", true},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
u := &User{EmailVerifiedAt: c.emailVerifiedAt}
if got := u.IsEmailVerified(); got != c.want {
t.Errorf("IsEmailVerified() with EmailVerifiedAt=%q = %v, want %v", c.emailVerifiedAt, got, c.want)
}
})
}
}