feat(twilio): expose root callback
This commit is contained in:
@@ -805,6 +805,73 @@ func TestTwilioWebhookPersistsIncomingMessage(t *testing.T) {
|
||||
assertPersistedMessage(t, db, inbox.ID, "SMIN1", "hello sms")
|
||||
}
|
||||
|
||||
func TestTwilioCallbackExactRoutePersistsIncomingMessage(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
db := newWebhookLookupTestDB(t)
|
||||
inbox := seedWebhookInbox(t, db, "twilio_sms")
|
||||
channelRecord := channelmodel.ChannelTwilioSMS{AccountID: 1, InboxID: inbox.ID, AccountSID: "AC123", PhoneNumber: "+15551234567", MessagingServiceSID: "MG123"}
|
||||
if err := db.Create(&channelRecord).Error; err != nil {
|
||||
t.Fatalf("create twilio channel: %v", err)
|
||||
}
|
||||
|
||||
twilioRepo := twiliochannel.NewRepository(db)
|
||||
twilioService := twiliochannel.NewTwilioService(twilioRepo)
|
||||
twilioPipeline := twiliochannel.NewIncomingProcessor(twilioService)
|
||||
twilioWebhook := twiliochannel.NewWebhookHandler(twilioPipeline, twilioService)
|
||||
h := NewTwilioWebhookHandler(twilioWebhook, db)
|
||||
r := gin.New()
|
||||
r.POST("/twilio/callback", h.HandleTwilioCallback)
|
||||
form := url.Values{}
|
||||
form.Set("MessageSid", "SMROOT1")
|
||||
form.Set("AccountSid", "AC123")
|
||||
form.Set("From", "+15550002222")
|
||||
form.Set("To", "15551234567")
|
||||
form.Set("Body", "hello root callback")
|
||||
req := httptest.NewRequest(http.MethodPost, "/twilio/callback", strings.NewReader(form.Encode()))
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusNoContent {
|
||||
t.Fatalf("expected 204, got %d body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
assertPersistedMessage(t, db, inbox.ID, "SMROOT1", "hello root callback")
|
||||
}
|
||||
|
||||
func TestTwilioCallbackExactRouteFallsBackToMessagingServiceSid(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
db := newWebhookLookupTestDB(t)
|
||||
inbox := seedWebhookInbox(t, db, "twilio_sms")
|
||||
channelRecord := channelmodel.ChannelTwilioSMS{AccountID: 1, InboxID: inbox.ID, AccountSID: "AC123", PhoneNumber: "+15551234567", MessagingServiceSID: "MG123"}
|
||||
if err := db.Create(&channelRecord).Error; err != nil {
|
||||
t.Fatalf("create twilio channel: %v", err)
|
||||
}
|
||||
|
||||
twilioRepo := twiliochannel.NewRepository(db)
|
||||
twilioService := twiliochannel.NewTwilioService(twilioRepo)
|
||||
twilioPipeline := twiliochannel.NewIncomingProcessor(twilioService)
|
||||
twilioWebhook := twiliochannel.NewWebhookHandler(twilioPipeline, twilioService)
|
||||
h := NewTwilioWebhookHandler(twilioWebhook, db)
|
||||
r := gin.New()
|
||||
r.POST("/twilio/callback", h.HandleTwilioCallback)
|
||||
form := url.Values{}
|
||||
form.Set("MessageSid", "SMROOTMG1")
|
||||
form.Set("MessagingServiceSid", "MG123")
|
||||
form.Set("From", "+15550002222")
|
||||
form.Set("Body", "hello service callback")
|
||||
req := httptest.NewRequest(http.MethodPost, "/twilio/callback", strings.NewReader(form.Encode()))
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusNoContent {
|
||||
t.Fatalf("expected 204, got %d body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
assertPersistedMessage(t, db, inbox.ID, "SMROOTMG1", "hello service callback")
|
||||
}
|
||||
|
||||
func TestTwilioInboundSMSQueuesIncomingMessageWithWorker(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
db := newWebhookLookupTestDB(t)
|
||||
|
||||
Reference in New Issue
Block a user