mirror of
https://github.com/Dvorinka/Bookra.git
synced 2026-06-05 04:52:59 +00:00
cleanup
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
package billing
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"bookra/apps/auth-service/internal/config"
|
||||
)
|
||||
|
||||
func TestPriceForPlanUsesConfiguredPlanCodesOnly(t *testing.T) {
|
||||
service := NewService(&config.Config{
|
||||
StripePriceIDs: map[string]string{
|
||||
"monthly": "price_monthly",
|
||||
"growth": "price_growth",
|
||||
},
|
||||
}, nil)
|
||||
|
||||
priceID, planCode, currency, err := service.priceForPlan("growth", "czk")
|
||||
if err != nil {
|
||||
t.Fatalf("price for plan: %v", err)
|
||||
}
|
||||
if priceID != "price_growth" || planCode != "pro" || currency != "czk" {
|
||||
t.Fatalf("expected pro mapping, got price=%q plan=%q currency=%q", priceID, planCode, currency)
|
||||
}
|
||||
|
||||
priceID, planCode, currency, err = service.priceForPlan("", "usd")
|
||||
if err != nil {
|
||||
t.Fatalf("default price for plan: %v", err)
|
||||
}
|
||||
if priceID != "price_monthly" || planCode != "monthly" || currency != "usd" {
|
||||
t.Fatalf("expected monthly default, got price=%q plan=%q currency=%q", priceID, planCode, currency)
|
||||
}
|
||||
|
||||
_, _, _, err = service.priceForPlan("price_attacker_controlled", "czk")
|
||||
if !errors.Is(err, ErrPlanNotConfigured) {
|
||||
t.Fatalf("expected ErrPlanNotConfigured, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKVKeyShape(t *testing.T) {
|
||||
if got := userCustomerKey("user_123"); got != "stripe:user:user_123" {
|
||||
t.Fatalf("unexpected user key: %s", got)
|
||||
}
|
||||
if got := customerSnapshotKey("cus_123"); got != "stripe:customer:cus_123" {
|
||||
t.Fatalf("unexpected customer key: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckoutAvailableForPlanRequiresSecret(t *testing.T) {
|
||||
service := NewService(&config.Config{
|
||||
StripePriceIDs: map[string]string{
|
||||
"pro:czk": "price_pro_czk",
|
||||
},
|
||||
}, nil)
|
||||
|
||||
if service.checkoutAvailableForPlan("pro") {
|
||||
t.Fatal("expected checkout unavailable without stripe secret")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckoutAvailableForPlanRequiresConfiguredPlan(t *testing.T) {
|
||||
service := NewService(&config.Config{
|
||||
StripeSecretKey: "sk_test_123",
|
||||
StripePriceIDs: map[string]string{
|
||||
"pro:czk": "price_pro_czk",
|
||||
},
|
||||
}, nil)
|
||||
|
||||
if !service.checkoutAvailableForPlan("pro") {
|
||||
t.Fatal("expected pro checkout available")
|
||||
}
|
||||
if service.checkoutAvailableForPlan("business") {
|
||||
t.Fatal("expected business checkout unavailable without configured price")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user