test(entry-offer): trial end does not restrict, subscription takes over
ci / shared (pull_request) Successful in 13s
ci / test (pull_request) Successful in 9m44s
ci / image (pull_request) Skipped

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-11-28 12:17:56 +01:00
1 parent 03f59c3114
commit c424e7b1d0
1 file changed
+43
+43
View File
@@ -122,3 +122,46 @@ func TestAdminEntryOffer(t *testing.T) {
t.Fatalf("grant over a trial grant: %d %s", code, raw)
}
}
// An entry workspace keeps its trial end on record; once that passes it is
// not restricted (only status trial expires), and a later subscription takes
// Prüfwerk over: plan from the ERP, no end date.
func TestEntryOfferLater(t *testing.T) {
f := newTeamFixture(t, portal, "portal-svc:*")
ctx := context.Background()
staff := map[string]string{"X-Staff-Subject": "staff-1", "X-Staff-Email": "staff@breakpilot.test"}
buyer, _ := f.s.Store.CreateTenant(ctx, store.TenantCreate{Slug: "k-00096", Name: "K-00096"})
month := time.Now().Add(30 * 24 * time.Hour).UTC().Format(time.RFC3339)
if code, _, raw := f.call(t, "POST", "/v1/admin/tenants/"+buyer.ID+"/entry-offer", `{"included_targets":1,"expires_at":"`+month+`"}`, staff); code != http.StatusOK {
t.Fatalf("grant: %d %s", code, raw)
}
cur, _ := f.s.Store.GetTenant(ctx, buyer.ID)
if cur.TrialEndsAt == nil {
t.Fatal("expected the trial end to stay on record")
}
if next, why := f.s.escalation(cur, cur.TrialEndsAt.Add(24*time.Hour)); next != "" {
t.Fatalf("an active entry workspace escalated after its trial end: %s (%s)", next, why)
}
if _, err := f.s.Store.UpsertSubscription(ctx, store.Subscription{TenantID: buyer.ID, Product: pruefwerkProduct, SKU: "CRA-CSA-CLD-STD",
Plan: "standard", Seats: 1, Status: store.SubscriptionActive, ErpSalesOrder: "SO-2"}); err != nil {
t.Fatal(err)
}
if _, err := f.s.recomputeEntitlements(ctx, nil, cur, "test"); err != nil {
t.Fatal(err)
}
tps, _ := f.s.Store.ListTenantProducts(ctx, buyer.ID)
for _, tp := range tps {
if tp.Product != pruefwerkProduct {
continue
}
if tp.Config["source"] != "erp" || tp.ExpiresAt != nil || !tp.Enabled {
t.Fatalf("subscription did not take over: %+v", tp)
}
if p := pruefwerkPlanOfConfig(tp.Config); p.Name != "standard" {
t.Fatalf("plan after the subscription: %s", p.Name)
}
return
}
t.Fatal("no Prüfwerk entitlement after the subscription")
}