feat(store): set trial_ends_at on tenant create
CreateTenant now defaults trial_ends_at to NOW() + 14 days when the new tenant lands in status='trial'. Demo-kind tenants get status='demo' (per PLATFORM_ARCHITECTURE.md §5d) and trial_ends_at stays NULL — those flow through the M13.2 demo-provisioning path. Both store implementations (Memory + Postgres) updated; tests assert the 14-day window for customers and the absent end for demo kind. Unblocks M12.1 (portal trial banner can render a real countdown). Refs: M4.1 + M12.1
This commit is contained in:
@@ -3,6 +3,7 @@ package server_test
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.meghsakha.com/platform/tenant-registry/internal/store"
|
||||
)
|
||||
@@ -119,3 +120,42 @@ func TestCancelTenant(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateTenant_setsTrialEndsAt(t *testing.T) {
|
||||
eachStore(t, func(t *testing.T, h *testHarness) {
|
||||
_, body := h.do("POST", "/v1/tenants", map[string]any{
|
||||
"slug": "trial-ends-co", "name": "Trial Ends Co.",
|
||||
})
|
||||
out := decode[struct {
|
||||
Tenant *store.Tenant `json:"tenant"`
|
||||
}](t, body)
|
||||
if out.Tenant.Status != "trial" {
|
||||
t.Fatalf("status = %q, want trial", out.Tenant.Status)
|
||||
}
|
||||
if out.Tenant.TrialEndsAt == nil {
|
||||
t.Fatal("trial_ends_at is nil; should be ~14 days from now")
|
||||
}
|
||||
// Sanity-check: ends_at is in the future, within 13.5-14.5 days.
|
||||
delta := time.Until(*out.Tenant.TrialEndsAt)
|
||||
if delta < 13*24*time.Hour || delta > 15*24*time.Hour {
|
||||
t.Errorf("trial_ends_at offset = %v, want ~14d", delta)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateTenant_demoKindHasNoTrialEnd(t *testing.T) {
|
||||
eachStore(t, func(t *testing.T, h *testHarness) {
|
||||
_, body := h.do("POST", "/v1/tenants", map[string]any{
|
||||
"slug": "demo-co", "name": "Demo", "kind": "demo",
|
||||
})
|
||||
out := decode[struct {
|
||||
Tenant *store.Tenant `json:"tenant"`
|
||||
}](t, body)
|
||||
if out.Tenant.Status != "demo" {
|
||||
t.Errorf("status = %q, want demo", out.Tenant.Status)
|
||||
}
|
||||
if out.Tenant.TrialEndsAt != nil {
|
||||
t.Errorf("trial_ends_at = %v, want nil for demo kind", out.Tenant.TrialEndsAt)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user