RezinaLMS-BackEnd/internal/domain/subscription_checkout_link_test.go
Yared Yemane 2791894e14 Add web checkout link API for iOS subscription paywall.
Send checkout URLs by email or SMS via POST /subscriptions/request-checkout-link, with LEARNER_WEB_CHECKOUT_BASE_URL config, RBAC permission, rate limiting, and client integration docs.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-24 13:09:09 +03:00

68 lines
2.1 KiB
Go

package domain
import "testing"
func TestResolveCheckoutLinkDeliveryChannel(t *testing.T) {
t.Run("verified phone first", func(t *testing.T) {
ch, dest, err := ResolveCheckoutLinkDeliveryChannel(User{
PhoneNumber: "0912345678",
PhoneVerified: true,
Email: "a@b.com",
EmailVerified: true,
})
if err != nil || ch != CheckoutLinkDeliverySMS || dest != "0912345678" {
t.Fatalf("got %q %q err=%v", ch, dest, err)
}
})
t.Run("verified email when phone not verified", func(t *testing.T) {
ch, dest, err := ResolveCheckoutLinkDeliveryChannel(User{
Email: "learner@example.com",
EmailVerified: true,
})
if err != nil || ch != CheckoutLinkDeliveryEmail || dest != "learner@example.com" {
t.Fatalf("got %q %q err=%v", ch, dest, err)
}
})
t.Run("phone only on file", func(t *testing.T) {
ch, dest, err := ResolveCheckoutLinkDeliveryChannel(User{PhoneNumber: "0911111111"})
if err != nil || ch != CheckoutLinkDeliverySMS {
t.Fatalf("got %q err=%v", ch, err)
}
if dest != "0911111111" {
t.Fatal(dest)
}
})
t.Run("no contact", func(t *testing.T) {
_, _, err := ResolveCheckoutLinkDeliveryChannel(User{})
if err != ErrNoContactForCheckoutLink {
t.Fatalf("expected ErrNoContactForCheckoutLink, got %v", err)
}
})
}
func TestBuildWebCheckoutURL(t *testing.T) {
planID := int64(5)
cat := "IELTS"
if u := BuildWebCheckoutURL("https://subscribe.example.com", &planID, nil); u != "https://subscribe.example.com/subscribe/checkout?plan_id=5" {
t.Fatal(u)
}
if u := BuildWebCheckoutURL("https://subscribe.example.com/", nil, &cat); u != "https://subscribe.example.com/subscribe?category=IELTS" {
t.Fatal(u)
}
if u := BuildWebCheckoutURL("https://subscribe.example.com", nil, nil); u != "https://subscribe.example.com/subscribe" {
t.Fatal(u)
}
}
func TestMaskCheckoutLinkDestination(t *testing.T) {
if got := MaskCheckoutLinkDestination(CheckoutLinkDeliverySMS, "0912345678"); got != "***5678" {
t.Fatal(got)
}
if got := MaskCheckoutLinkDestination(CheckoutLinkDeliveryEmail, "john@example.com"); got != "j***@example.com" {
t.Fatal(got)
}
}