62 lines
1.9 KiB
Go
62 lines
1.9 KiB
Go
package domain
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestCalculateSubscriptionExpiresAt_lifetime(t *testing.T) {
|
|
start := time.Date(2026, 6, 10, 12, 0, 0, 0, time.UTC)
|
|
got := CalculateSubscriptionExpiresAt(start, true, 1, "MONTH")
|
|
if !got.Equal(LifetimeSubscriptionExpiresAt) {
|
|
t.Fatalf("expected lifetime expiry, got %v", got)
|
|
}
|
|
}
|
|
|
|
func TestCalculateSubscriptionExpiresAt_usesDurationWhenNotLifetime(t *testing.T) {
|
|
start := time.Date(2026, 6, 10, 12, 0, 0, 0, time.UTC)
|
|
got := CalculateSubscriptionExpiresAt(start, false, 1, "MONTH")
|
|
want := start.AddDate(0, 1, 0)
|
|
if !got.Equal(want) {
|
|
t.Fatalf("got %v, want %v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestIsLifetimeExpiry(t *testing.T) {
|
|
if !IsLifetimeExpiry(LifetimeSubscriptionExpiresAt) {
|
|
t.Fatal("sentinel should be lifetime")
|
|
}
|
|
if IsLifetimeExpiry(time.Date(2026, 12, 31, 0, 0, 0, 0, time.UTC)) {
|
|
t.Fatal("normal date should not be lifetime")
|
|
}
|
|
}
|
|
|
|
func TestNormalizeLifetimePlanCreateDuration(t *testing.T) {
|
|
v, u := NormalizeLifetimePlanCreateDuration(true, 3, "MONTH")
|
|
if v != LifetimeDurationValue || u != LifetimeDurationUnit {
|
|
t.Fatalf("got %d %s", v, u)
|
|
}
|
|
v, u = NormalizeLifetimePlanCreateDuration(false, 3, "MONTH")
|
|
if v != 3 || u != "MONTH" {
|
|
t.Fatalf("got %d %s", v, u)
|
|
}
|
|
}
|
|
|
|
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")
|
|
}
|
|
}
|