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
@@ -138,3 +138,50 @@ func TestDispatchDueSkipsNonConfirmedBooking(t *testing.T) {
|
||||
t.Fatalf("expected 1 skipped, got %+v", response)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatchDueSendsSmsReminder(t *testing.T) {
|
||||
repo := db.NewMemoryRepository()
|
||||
startsAt := time.Now().UTC().Add(26 * time.Hour)
|
||||
created, err := repo.CreateBooking(context.Background(), db.CreateBookingParams{
|
||||
TenantID: "5d6b3551-0a3e-4b86-bdf0-e9df20a47148",
|
||||
BookingMode: "appointment",
|
||||
CustomerPhone: "+420777000111",
|
||||
StartsAt: startsAt,
|
||||
EndsAt: startsAt.Add(time.Hour),
|
||||
Status: "confirmed",
|
||||
Reference: "BK-TEST-SMS",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("create booking: %v", err)
|
||||
}
|
||||
if err := repo.CreateReminderJob(context.Background(), db.ReminderJobParams{
|
||||
TenantID: "5d6b3551-0a3e-4b86-bdf0-e9df20a47148",
|
||||
BookingID: created.ID,
|
||||
Channel: "sms",
|
||||
ScheduledFor: time.Now().UTC().Add(-time.Minute),
|
||||
}); err != nil {
|
||||
t.Fatalf("create reminder job: %v", err)
|
||||
}
|
||||
|
||||
var sentPhone, sentBody string
|
||||
service := NewService(config.Config{Environment: "development"}, repo)
|
||||
service.SetSMSSender(func(_ context.Context, tenantID, phone, body string) error {
|
||||
sentPhone = phone
|
||||
sentBody = body
|
||||
return nil
|
||||
})
|
||||
|
||||
response, err := service.DispatchDue(context.Background(), 10)
|
||||
if err != nil {
|
||||
t.Fatalf("dispatch due: %v", err)
|
||||
}
|
||||
if response.SentCount != 1 {
|
||||
t.Fatalf("expected 1 sent, got %+v", response)
|
||||
}
|
||||
if sentPhone != "+420777000111" {
|
||||
t.Fatalf("expected phone recipient, got %q", sentPhone)
|
||||
}
|
||||
if sentBody == "" {
|
||||
t.Fatal("expected rendered sms body")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user