package middleware import ( "testing" "time" "github.com/stretchr/testify/assert" ) func TestCalcLicensePhase(t *testing.T) { now := time.Now() // nil = perpetual → normal assert.Equal(t, PhaseNormal, CalcLicensePhase(nil)) // future expiry → normal future := now.Add(10 * 24 * time.Hour) assert.Equal(t, PhaseNormal, CalcLicensePhase(&future)) // just expired (1h ago) → grace grace := now.Add(-1 * time.Hour) assert.Equal(t, PhaseGrace, CalcLicensePhase(&grace)) // expired 6 days ago → grace (boundary) grace6d := now.Add(-6 * 24 * time.Hour) assert.Equal(t, PhaseGrace, CalcLicensePhase(&grace6d)) // expired 8 days ago → readonly readonly := now.Add(-8 * 24 * time.Hour) assert.Equal(t, PhaseReadOnly, CalcLicensePhase(&readonly)) // expired 14 days ago → readonly (boundary) readonly14d := now.Add(-14 * 24 * time.Hour) assert.Equal(t, PhaseReadOnly, CalcLicensePhase(&readonly14d)) // expired 16 days ago → locked locked := now.Add(-16 * 24 * time.Hour) assert.Equal(t, PhaseLocked, CalcLicensePhase(&locked)) }