mirror of
https://github.com/Dvorinka/Bookra.git
synced 2026-10-29 16:04:45 +00:00
feat(bookings): dashboard cancellation and waitlist promotion
- POST /v1/catalog/bookings/{id}/cancel lets businesses cancel
tenant-owned bookings; two-step confirm in the detail modal
- Shared PromoteWaitlist helper promotes earliest waitlisted bookings
when a class seat frees, on both dashboard and customer cancel paths;
promoted customers get a confirmation email, waitlist ledger marked
resolved
- waitlisted status surfaced in bookings UI: stats card, filter, warning
badge, demo seed, CS+EN strings
- BookingRecord gains created_at for fair ordering; GetBookingByID and
ResolveWaitlistEntry added to the repository surface
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
0405106587
commit
668a54ae1d
15 files changed
+563
-5
No files matched your search
@@ -3,6 +3,8 @@ package bookings
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -399,3 +401,52 @@ func TestCreateAppointmentRejectsForeignStaff(t *testing.T) {
|
||||
t.Fatalf("expected ErrInvalidBooking, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCustomerCancelPromotesWaitlist(t *testing.T) {
|
||||
repo := db.NewMemoryRepository()
|
||||
service := NewService(repo, nil, "http://localhost:3000")
|
||||
customerService := NewCustomerService(repo, nil, "http://localhost:3000")
|
||||
ctx := context.Background()
|
||||
|
||||
session, err := repo.GetClassSessionByID(ctx, "4bf74c12-44dd-45ca-86bb-b104f16f2435")
|
||||
if err != nil {
|
||||
t.Fatalf("get session: %v", err)
|
||||
}
|
||||
sessionID := session.ID
|
||||
book := func(email string) domain.CreateBookingResponse {
|
||||
resp, err := service.Create(ctx, domain.CreateBookingRequest{
|
||||
TenantSlug: "studio-atelier",
|
||||
BookingMode: "class",
|
||||
ClassSessionID: &sessionID,
|
||||
CustomerName: "Test User",
|
||||
CustomerEmail: email,
|
||||
StartsAt: session.StartsAt.UTC().Format(time.RFC3339),
|
||||
EndsAt: session.EndsAt.UTC().Format(time.RFC3339),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("book %s: %v", email, err)
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
var confirmed []domain.CreateBookingResponse
|
||||
for i := 0; i < 4; i++ {
|
||||
confirmed = append(confirmed, book(fmt.Sprintf("seat%[email protected]", i)))
|
||||
}
|
||||
waiter := book("[email protected]")
|
||||
if waiter.Status != "waitlisted" {
|
||||
t.Fatalf("expected waitlisted, got %s", waiter.Status)
|
||||
}
|
||||
|
||||
// Customer cancels a confirmed seat via the management token.
|
||||
manageURL, _ := url.Parse(confirmed[0].ManageURL)
|
||||
token := manageURL.Query().Get("token")
|
||||
if err := customerService.CancelBooking(ctx, confirmed[0].Reference, token); err != nil {
|
||||
t.Fatalf("customer cancel: %v", err)
|
||||
}
|
||||
|
||||
booking, _ := repo.GetBookingByID(ctx, waiter.BookingID)
|
||||
if booking.Status != "confirmed" {
|
||||
t.Fatalf("expected waiter promoted to confirmed, got %q", booking.Status)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user