mirror of
https://github.com/Dvorinka/Bookra.git
synced 2026-10-29 07:54:44 +00:00
feat(reminders): SMS channel for reminder jobs
Tenants paying for the SMS add-on still got email-only reminders — the channel column existed but nothing armed or dispatched sms jobs. Booking creation now adds a second job when SMS is enabled and the customer left a phone; dispatch routes sms jobs through an injected sender adapter wired to the existing sms.Service, so monthly limits, usage metering, and Stripe billing apply unchanged. Lifecycle handling from the previous milestone clears and re-arms both channels together. 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
c7172544b8
commit
7509e82261
8 files changed
+164
-1
No files matched your search
@@ -366,6 +366,17 @@ func (s *Service) Create(ctx context.Context, request domain.CreateBookingReques
|
||||
}); err != nil {
|
||||
return domain.CreateBookingResponse{}, err
|
||||
}
|
||||
// SMS reminders are a per-tenant opt-in and need a customer phone.
|
||||
if request.CustomerPhone != "" {
|
||||
if smsSettings, err := s.repo.GetTenantSMSSettings(ctx, tenant.ID); err == nil && smsSettings.Enabled {
|
||||
_ = s.repo.CreateReminderJob(ctx, db.ReminderJobParams{
|
||||
TenantID: tenant.ID,
|
||||
BookingID: created.ID,
|
||||
Channel: "sms",
|
||||
ScheduledFor: scheduledFor,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send confirmation emails (async - don't fail booking if email fails)
|
||||
|
||||
@@ -648,3 +648,58 @@ func TestRescheduleRejectsTimeOutsideAvailabilityWindow(t *testing.T) {
|
||||
t.Fatalf("expected ErrInvalidReschedule, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateArmsSmsReminderWhenEnabled(t *testing.T) {
|
||||
repo := db.NewMemoryRepository()
|
||||
service := NewService(repo, nil, "http://localhost:3000")
|
||||
ctx := context.Background()
|
||||
|
||||
membership, _ := repo.GetTenantMembershipBySubject(ctx, "demo-owner")
|
||||
if err := repo.UpsertTenantSMSSettings(ctx, db.TenantSMSSettingsRecord{
|
||||
TenantID: membership.Tenant.ID,
|
||||
Enabled: true,
|
||||
}); err != nil {
|
||||
t.Fatalf("sms settings: %v", err)
|
||||
}
|
||||
|
||||
// Booking with a phone: expect email + sms reminder jobs.
|
||||
availability, err := service.Availability(ctx, "studio-atelier", AvailabilityFilter{
|
||||
Date: time.Now().UTC().AddDate(0, 0, 3).Format("2006-01-02"),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("availability: %v", err)
|
||||
}
|
||||
var slot domain.TimeSlot
|
||||
for _, s := range availability.Slots {
|
||||
if s.Mode == "appointment" {
|
||||
slot = s
|
||||
break
|
||||
}
|
||||
}
|
||||
resp, err := service.Create(ctx, domain.CreateBookingRequest{
|
||||
TenantSlug: "studio-atelier",
|
||||
BookingMode: "appointment",
|
||||
ServiceID: slot.ServiceID,
|
||||
StaffID: slot.StaffID,
|
||||
LocationID: slot.LocationID,
|
||||
CustomerName: "SMS Test",
|
||||
CustomerEmail: "[email protected]",
|
||||
CustomerPhone: "+420777123456",
|
||||
StartsAt: slot.StartsAt,
|
||||
EndsAt: slot.EndsAt,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("create: %v", err)
|
||||
}
|
||||
jobs := pendingJobsFor(t, repo, resp.BookingID)
|
||||
if len(jobs) != 2 {
|
||||
t.Fatalf("expected 2 pending jobs, got %d", len(jobs))
|
||||
}
|
||||
channels := map[string]bool{}
|
||||
for _, job := range jobs {
|
||||
channels[job.Channel] = true
|
||||
}
|
||||
if !channels["email"] || !channels["sms"] {
|
||||
t.Fatalf("expected email+sms channels, got %v", channels)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user