Treat IELTS and DUOLINGO subscriptions as lifetime one-time plans.
Extend the DUOLINGO far-future expires_at pattern to IELTS, backfill existing IELTS rows, and limit expiry sweeps to LEARN_ENGLISH only. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
162f822343
commit
342b10a35a
|
|
@ -0,0 +1 @@
|
|||
-- No-op: prior per-subscription expires_at values cannot be restored.
|
||||
9
db/migrations/000099_ielts_lifetime_subscriptions.up.sql
Normal file
9
db/migrations/000099_ielts_lifetime_subscriptions.up.sql
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
-- IELTS subscriptions are one-time purchases with no real expiry.
|
||||
UPDATE user_subscriptions us
|
||||
SET
|
||||
expires_at = TIMESTAMPTZ '9999-12-31 23:59:59+00',
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
FROM subscription_plans sp
|
||||
WHERE us.plan_id = sp.id
|
||||
AND sp.category = 'IELTS'
|
||||
AND us.expires_at < TIMESTAMPTZ '9999-01-01 00:00:00+00';
|
||||
|
|
@ -220,7 +220,7 @@ SELECT us.*, sp.name AS plan_name
|
|||
FROM user_subscriptions us
|
||||
JOIN subscription_plans sp ON sp.id = us.plan_id
|
||||
WHERE us.status = 'ACTIVE'
|
||||
AND sp.category <> 'DUOLINGO'
|
||||
AND sp.category = 'LEARN_ENGLISH'
|
||||
AND us.expires_at <= CURRENT_TIMESTAMP;
|
||||
|
||||
-- name: ListLearnEnglishSubscriptionsExpiringInSevenDays :many
|
||||
|
|
@ -248,7 +248,7 @@ FROM user_subscriptions us
|
|||
JOIN subscription_plans sp ON sp.id = us.plan_id
|
||||
JOIN users u ON u.id = us.user_id
|
||||
WHERE us.status = 'ACTIVE'
|
||||
AND sp.category <> 'DUOLINGO'
|
||||
AND sp.category = 'LEARN_ENGLISH'
|
||||
AND us.expires_at > CURRENT_TIMESTAMP
|
||||
AND us.expires_at <= CURRENT_TIMESTAMP + INTERVAL '7 days';
|
||||
|
||||
|
|
|
|||
|
|
@ -322,7 +322,7 @@ SELECT us.id, us.user_id, us.plan_id, us.starts_at, us.expires_at, us.status, us
|
|||
FROM user_subscriptions us
|
||||
JOIN subscription_plans sp ON sp.id = us.plan_id
|
||||
WHERE us.status = 'ACTIVE'
|
||||
AND sp.category <> 'DUOLINGO'
|
||||
AND sp.category = 'LEARN_ENGLISH'
|
||||
AND us.expires_at <= CURRENT_TIMESTAMP
|
||||
`
|
||||
|
||||
|
|
@ -386,7 +386,7 @@ FROM user_subscriptions us
|
|||
JOIN subscription_plans sp ON sp.id = us.plan_id
|
||||
JOIN users u ON u.id = us.user_id
|
||||
WHERE us.status = 'ACTIVE'
|
||||
AND sp.category <> 'DUOLINGO'
|
||||
AND sp.category = 'LEARN_ENGLISH'
|
||||
AND us.expires_at > CURRENT_TIMESTAMP
|
||||
AND us.expires_at <= CURRENT_TIMESTAMP + INTERVAL '7 days'
|
||||
`
|
||||
|
|
|
|||
|
|
@ -182,15 +182,21 @@ type AdminApplySubscriptionResult struct {
|
|||
Created bool // true when a new subscription row was granted
|
||||
}
|
||||
|
||||
// LifetimeSubscriptionExpiresAt is stored for one-time (non-expiring) DUOLINGO subscriptions.
|
||||
// LifetimeSubscriptionExpiresAt is stored for one-time (non-expiring) IELTS and DUOLINGO subscriptions.
|
||||
var LifetimeSubscriptionExpiresAt = time.Date(9999, 12, 31, 23, 59, 59, 0, time.UTC)
|
||||
|
||||
// IsLifetimeSubscriptionCategory reports categories that grant permanent access after purchase.
|
||||
func IsLifetimeSubscriptionCategory(category string) bool {
|
||||
return strings.ToUpper(strings.TrimSpace(category)) == string(SubscriptionCategoryDuolingo)
|
||||
switch normalizeSubscriptionCategory(category) {
|
||||
case string(SubscriptionCategoryIELTS), string(SubscriptionCategoryDuolingo):
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// CalculateSubscriptionExpiresAt returns when a subscription ends. DUOLINGO plans never expire.
|
||||
// CalculateSubscriptionExpiresAt returns when a subscription ends.
|
||||
// IELTS and DUOLINGO plans are one-time and never expire.
|
||||
func CalculateSubscriptionExpiresAt(startTime time.Time, category string, durationValue int32, durationUnit string) time.Time {
|
||||
if IsLifetimeSubscriptionCategory(category) {
|
||||
return LifetimeSubscriptionExpiresAt
|
||||
|
|
|
|||
|
|
@ -13,6 +13,33 @@ func TestCalculateSubscriptionExpiresAt_duolingoIsLifetime(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestCalculateSubscriptionExpiresAt_ieltsIsLifetime(t *testing.T) {
|
||||
start := time.Date(2026, 6, 10, 12, 0, 0, 0, time.UTC)
|
||||
got := CalculateSubscriptionExpiresAt(start, "IELTS", 1, "MONTH")
|
||||
if !got.Equal(LifetimeSubscriptionExpiresAt) {
|
||||
t.Fatalf("expected lifetime expiry, got %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsLifetimeSubscriptionCategory(t *testing.T) {
|
||||
cases := []struct {
|
||||
category string
|
||||
want bool
|
||||
}{
|
||||
{"IELTS", true},
|
||||
{"ielts", true},
|
||||
{"DUOLINGO", true},
|
||||
{" duolingo ", true},
|
||||
{"LEARN_ENGLISH", false},
|
||||
{"", false},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
if got := IsLifetimeSubscriptionCategory(tc.category); got != tc.want {
|
||||
t.Fatalf("IsLifetimeSubscriptionCategory(%q)=%v, want %v", tc.category, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubscriptionGrantsContentAccess(t *testing.T) {
|
||||
if !SubscriptionGrantsContentAccess("LEARN_ENGLISH", "LEARN_ENGLISH") {
|
||||
t.Fatal("LEARN_ENGLISH plan should unlock LMS content")
|
||||
|
|
|
|||
|
|
@ -18,14 +18,20 @@ func TestSubscriptionPackageLabel(t *testing.T) {
|
|||
|
||||
func TestSubscriptionExpiresLabel(t *testing.T) {
|
||||
expiresAt := time.Date(2026, 12, 31, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
label, lifetime := subscriptionExpiresLabel(string(domain.SubscriptionCategoryIELTS), expiresAt)
|
||||
if lifetime || label != "Dec 31, 2026" {
|
||||
t.Fatalf("label=%q lifetime=%v", label, lifetime)
|
||||
if !lifetime || label != "" {
|
||||
t.Fatalf("IELTS label=%q lifetime=%v", label, lifetime)
|
||||
}
|
||||
|
||||
label, lifetime = subscriptionExpiresLabel(string(domain.SubscriptionCategoryDuolingo), expiresAt)
|
||||
if !lifetime || label != "" {
|
||||
t.Fatalf("label=%q lifetime=%v", label, lifetime)
|
||||
t.Fatalf("DUOLINGO label=%q lifetime=%v", label, lifetime)
|
||||
}
|
||||
|
||||
label, lifetime = subscriptionExpiresLabel(string(domain.SubscriptionCategoryLearnEnglish), expiresAt)
|
||||
if lifetime || label != "Dec 31, 2026" {
|
||||
t.Fatalf("LEARN_ENGLISH label=%q lifetime=%v", label, lifetime)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user