Improve CORS origin handling; extend invoice repo/service and payments dispatch; rate limit and nginx config updates

Made-with: Love
This commit is contained in:
2026-04-29 05:44:59 +00:00
parent 2cb17df4c5
commit a01797e9b2
12 changed files with 224 additions and 35 deletions

View File

@@ -127,26 +127,66 @@ func TestCreate_BlocksActiveLifetimeUser(t *testing.T) {
}
}
func TestCreate_RejectsDuplicatePending(t *testing.T) {
func TestCreate_ResumesDuplicatePending(t *testing.T) {
svc, _, _ := newServiceFixture(t)
if _, err := svc.Create(context.Background(), invoice.CreateRequest{
Pubkey: testHex,
Username: "alice",
SubscriptionType: user.SubYearly,
Years: 1,
}); err != nil {
t.Fatalf("first create: %v", err)
}
_, err := svc.Create(context.Background(), invoice.CreateRequest{
first, err := svc.Create(context.Background(), invoice.CreateRequest{
Pubkey: testHex,
Username: "alice",
SubscriptionType: user.SubYearly,
Years: 1,
})
if !errors.Is(err, invoice.ErrPendingInvoiceExists) {
t.Fatalf("expected ErrPendingInvoiceExists, got %v", err)
if err != nil {
t.Fatalf("first create: %v", err)
}
second, err := svc.Create(context.Background(), invoice.CreateRequest{
Pubkey: testHex,
Username: "alice",
SubscriptionType: user.SubYearly,
Years: 1,
})
if err != nil {
t.Fatalf("second create should resume pending: %v", err)
}
if second.PaymentHash != first.PaymentHash || second.PaymentRequest != first.PaymentRequest {
t.Fatalf("expected same pending invoice on resume, got hash=%q vs %q", second.PaymentHash, first.PaymentHash)
}
}
func TestCreate_SupersedesDifferentPendingPlan(t *testing.T) {
svc, _, _ := newServiceFixture(t)
first, err := svc.Create(context.Background(), invoice.CreateRequest{
Pubkey: testHex,
Username: "alice",
SubscriptionType: user.SubLifetime,
})
if err != nil {
t.Fatalf("lifetime pending: %v", err)
}
second, err := svc.Create(context.Background(), invoice.CreateRequest{
Pubkey: testHex,
Username: "alice",
SubscriptionType: user.SubYearly,
Years: 1,
})
if err != nil {
t.Fatalf("yearly after lifetime pending: %v", err)
}
stored, err := svc.Repo().Get(context.Background(), second.PaymentHash)
if err != nil {
t.Fatal(err)
}
if stored.SubscriptionType != user.SubYearly || stored.Years != 1 || stored.AmountSats != 1000 {
t.Fatalf("DB row should reflect yearly plan after supersede: %+v", stored)
}
if second.SubscriptionType != user.SubYearly || second.Years != 1 || second.AmountSats != 1000 {
t.Fatalf("unexpected yearly invoice: %+v", second)
}
if first.SubscriptionType == second.SubscriptionType || first.AmountSats == second.AmountSats {
t.Fatalf("expected plan switch lifetime -> yearly")
}
}