mirror of
https://github.com/Dvorinka/Bookra.git
synced 2026-06-03 20:13:00 +00:00
76 lines
1.9 KiB
Go
76 lines
1.9 KiB
Go
package billing
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"bookra/apps/backend/internal/config"
|
|
"bookra/apps/backend/internal/db"
|
|
"bookra/apps/backend/internal/domain"
|
|
)
|
|
|
|
func TestGetSubscriptionFallsBackToSnapshotAndEntitlements(t *testing.T) {
|
|
service := NewService(config.Config{
|
|
FrontendURL: "http://localhost:3000",
|
|
StripePriceIDs: map[string]string{
|
|
"growth": "price_growth_123",
|
|
},
|
|
}, db.NewMemoryRepository())
|
|
|
|
snapshot, err := service.GetSubscription(context.Background(), domain.Principal{
|
|
Subject: "demo-owner",
|
|
Email: "owner@bookra.dev",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("get subscription: %v", err)
|
|
}
|
|
|
|
if snapshot.PlanCode != "growth" {
|
|
t.Fatalf("expected growth, got %s", snapshot.PlanCode)
|
|
}
|
|
if snapshot.Entitlements.MaxLocations != 3 {
|
|
t.Fatalf("expected 3 locations, got %d", snapshot.Entitlements.MaxLocations)
|
|
}
|
|
}
|
|
|
|
func TestCreateCheckoutUsesMockURLWithoutStripeKey(t *testing.T) {
|
|
service := NewService(config.Config{
|
|
FrontendURL: "http://localhost:3000",
|
|
StripePriceIDs: map[string]string{
|
|
"growth": "price_growth_123",
|
|
},
|
|
}, db.NewMemoryRepository())
|
|
|
|
response, err := service.CreateCheckoutSession(context.Background(), domain.Principal{
|
|
Subject: "demo-owner",
|
|
Email: "owner@bookra.dev",
|
|
}, "growth")
|
|
if err != nil {
|
|
t.Fatalf("create checkout: %v", err)
|
|
}
|
|
if response.URL == "" {
|
|
t.Fatal("expected checkout url")
|
|
}
|
|
}
|
|
|
|
func TestRefreshReturnsSnapshotWithoutStripeKey(t *testing.T) {
|
|
service := NewService(config.Config{
|
|
FrontendURL: "http://localhost:3000",
|
|
StripePriceIDs: map[string]string{
|
|
"growth": "price_growth_123",
|
|
},
|
|
}, db.NewMemoryRepository())
|
|
|
|
snapshot, err := service.Refresh(context.Background(), domain.Principal{
|
|
Subject: "demo-owner",
|
|
Email: "owner@bookra.dev",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("refresh: %v", err)
|
|
}
|
|
|
|
if snapshot.Status != "active" {
|
|
t.Fatalf("expected active status, got %s", snapshot.Status)
|
|
}
|
|
}
|