mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-12-02 10:09:02 +01:00
Community installs already stored 90 days of daily metric averages and 366 days of availability history, but the chart, availability and agent history reads refused anything past seven days, and lapsed paid installs had history past seven days purged 60 days after a downgrade. Locking users out of data on their own disk is the kind of limit that drew the loudest complaints before (the monitored-system cap, SSO), and it is not what people pay for: 12 of 88 covered paid installs read past seven days in the last 30 days. The history routes now serve every supported range on every plan, and storage retention alone decides how far back the answer goes. long_term_metrics moves into Community as a compatibility key with no upgrade reason. TierHistoryDays, max_history_days and the downgrade purge (DowngradeRetentionState, the metrics store commercial ceiling and the generated-report purge) are removed, so nothing deletes history or reports because a plan ended. The chart and drawer lock panels, the history plan link, the billing summary row and the plan copy that sold history go with them. Paying users lose nothing. The public pricing pages and licence server copy in pulse-pro change when the release carrying this ships.
193 lines
5.1 KiB
Go
193 lines
5.1 KiB
Go
package licensing
|
|
|
|
import "testing"
|
|
|
|
func TestCanTransition_ValidTransitions(t *testing.T) {
|
|
for transition := range validTransitions {
|
|
transition := transition
|
|
t.Run(string(transition.From)+"_to_"+string(transition.To), func(t *testing.T) {
|
|
if !CanTransition(transition.From, transition.To) {
|
|
t.Fatalf("expected transition %s -> %s to be valid", transition.From, transition.To)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCanTransition_InvalidTransitions(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
from SubscriptionState
|
|
to SubscriptionState
|
|
}{
|
|
{name: "trial_to_grace", from: SubStateTrial, to: SubStateGrace},
|
|
{name: "trial_to_suspended", from: SubStateTrial, to: SubStateSuspended},
|
|
{name: "active_to_trial", from: SubStateActive, to: SubStateTrial},
|
|
{name: "active_to_expired", from: SubStateActive, to: SubStateExpired},
|
|
{name: "grace_to_suspended", from: SubStateGrace, to: SubStateSuspended},
|
|
{name: "grace_to_trial", from: SubStateGrace, to: SubStateTrial},
|
|
{name: "expired_to_grace", from: SubStateExpired, to: SubStateGrace},
|
|
{name: "expired_to_trial", from: SubStateExpired, to: SubStateTrial},
|
|
{name: "expired_to_suspended", from: SubStateExpired, to: SubStateSuspended},
|
|
{name: "suspended_to_grace", from: SubStateSuspended, to: SubStateGrace},
|
|
{name: "suspended_to_trial", from: SubStateSuspended, to: SubStateTrial},
|
|
}
|
|
|
|
states := []SubscriptionState{
|
|
SubStateTrial,
|
|
SubStateActive,
|
|
SubStateGrace,
|
|
SubStateExpired,
|
|
SubStateSuspended,
|
|
}
|
|
for _, state := range states {
|
|
tests = append(tests, struct {
|
|
name string
|
|
from SubscriptionState
|
|
to SubscriptionState
|
|
}{
|
|
name: string(state) + "_to_itself",
|
|
from: state,
|
|
to: state,
|
|
})
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if CanTransition(tt.from, tt.to) {
|
|
t.Fatalf("expected transition %s -> %s to be invalid", tt.from, tt.to)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestValidTransitionsFrom(t *testing.T) {
|
|
tests := []struct {
|
|
from SubscriptionState
|
|
expected map[SubscriptionState]struct{}
|
|
}{
|
|
{
|
|
from: SubStateTrial,
|
|
expected: map[SubscriptionState]struct{}{
|
|
SubStateActive: {},
|
|
SubStateExpired: {},
|
|
},
|
|
},
|
|
{
|
|
from: SubStateActive,
|
|
expected: map[SubscriptionState]struct{}{
|
|
SubStateGrace: {},
|
|
SubStateSuspended: {},
|
|
},
|
|
},
|
|
{
|
|
from: SubStateGrace,
|
|
expected: map[SubscriptionState]struct{}{
|
|
SubStateActive: {},
|
|
SubStateExpired: {},
|
|
},
|
|
},
|
|
{
|
|
from: SubStateExpired,
|
|
expected: map[SubscriptionState]struct{}{
|
|
SubStateActive: {},
|
|
},
|
|
},
|
|
{
|
|
from: SubStateSuspended,
|
|
expected: map[SubscriptionState]struct{}{
|
|
SubStateActive: {},
|
|
SubStateExpired: {},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(string(tt.from), func(t *testing.T) {
|
|
got := ValidTransitionsFrom(tt.from)
|
|
gotSet := make(map[SubscriptionState]struct{}, len(got))
|
|
for _, target := range got {
|
|
gotSet[target] = struct{}{}
|
|
}
|
|
|
|
if len(gotSet) != len(tt.expected) {
|
|
t.Fatalf("unexpected number of transitions for %s: got=%d want=%d", tt.from, len(gotSet), len(tt.expected))
|
|
}
|
|
|
|
for expectedTarget := range tt.expected {
|
|
if _, ok := gotSet[expectedTarget]; !ok {
|
|
t.Fatalf("missing expected transition for %s -> %s", tt.from, expectedTarget)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetBehavior(t *testing.T) {
|
|
tests := []struct {
|
|
state SubscriptionState
|
|
operations OperationClass
|
|
featuresAvailable bool
|
|
showWarning bool
|
|
}{
|
|
{
|
|
state: SubStateTrial,
|
|
operations: OpFull,
|
|
featuresAvailable: true,
|
|
showWarning: false,
|
|
},
|
|
{
|
|
state: SubStateActive,
|
|
operations: OpFull,
|
|
featuresAvailable: true,
|
|
showWarning: false,
|
|
},
|
|
{
|
|
state: SubStateGrace,
|
|
operations: OpFull,
|
|
featuresAvailable: true,
|
|
showWarning: true,
|
|
},
|
|
{
|
|
state: SubStateExpired,
|
|
operations: OpDegraded,
|
|
featuresAvailable: false,
|
|
showWarning: true,
|
|
},
|
|
{
|
|
state: SubStateSuspended,
|
|
operations: OpLocked,
|
|
featuresAvailable: false,
|
|
showWarning: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(string(tt.state), func(t *testing.T) {
|
|
got := GetBehavior(tt.state)
|
|
if got.State != tt.state {
|
|
t.Fatalf("unexpected state in behavior: got=%s want=%s", got.State, tt.state)
|
|
}
|
|
if got.Operations != tt.operations {
|
|
t.Fatalf("unexpected operations for %s: got=%s want=%s", tt.state, got.Operations, tt.operations)
|
|
}
|
|
if got.FeaturesAvailable != tt.featuresAvailable {
|
|
t.Fatalf("unexpected features flag for %s: got=%t want=%t", tt.state, got.FeaturesAvailable, tt.featuresAvailable)
|
|
}
|
|
if got.ShowWarning != tt.showWarning {
|
|
t.Fatalf("unexpected warning flag for %s: got=%t want=%t", tt.state, got.ShowWarning, tt.showWarning)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetBehavior_UnknownState(t *testing.T) {
|
|
got := GetBehavior(SubscriptionState("unknown_state"))
|
|
expected := StateBehaviors[SubStateExpired]
|
|
if got != expected {
|
|
t.Fatalf("expected unknown state fallback to expired behavior: got=%+v want=%+v", got, expected)
|
|
}
|
|
}
|