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>
69 lines
2.1 KiB
Go
69 lines
2.1 KiB
Go
package domain
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestCalculateSubscriptionExpiresAt_duolingoIsLifetime(t *testing.T) {
|
|
start := time.Date(2026, 6, 10, 12, 0, 0, 0, time.UTC)
|
|
got := CalculateSubscriptionExpiresAt(start, "DUOLINGO", 1, "MONTH")
|
|
if !got.Equal(LifetimeSubscriptionExpiresAt) {
|
|
t.Fatalf("expected lifetime expiry, got %v", got)
|
|
}
|
|
}
|
|
|
|
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")
|
|
}
|
|
if SubscriptionGrantsContentAccess("LEARN_ENGLISH", "IELTS") {
|
|
t.Fatal("LEARN_ENGLISH plan should not unlock exam prep content")
|
|
}
|
|
if !SubscriptionGrantsContentAccess("IELTS", "IELTS") {
|
|
t.Fatal("IELTS plan should unlock IELTS content")
|
|
}
|
|
if SubscriptionGrantsContentAccess("IELTS", "DUOLINGO") {
|
|
t.Fatal("IELTS plan should not unlock Duolingo content")
|
|
}
|
|
if !SubscriptionGrantsContentAccess("DUOLINGO", "DUOLINGO") {
|
|
t.Fatal("DUOLINGO plan should unlock Duolingo content")
|
|
}
|
|
}
|
|
|
|
func TestCalculateSubscriptionExpiresAt_learnEnglishUsesDuration(t *testing.T) {
|
|
start := time.Date(2026, 6, 10, 12, 0, 0, 0, time.UTC)
|
|
got := CalculateSubscriptionExpiresAt(start, "LEARN_ENGLISH", 1, "MONTH")
|
|
want := start.AddDate(0, 1, 0)
|
|
if !got.Equal(want) {
|
|
t.Fatalf("expected %v, got %v", want, got)
|
|
}
|
|
}
|