MCPcopy Index your code
hub / github.com/NdoleStudio/httpsms / TestSendSMS_OutstandingFlow

Function TestSendSMS_OutstandingFlow

tests/integration_test.go:302–349  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

300}
301
302func TestSendSMS_OutstandingFlow(t *testing.T) {
303 ctx := context.Background()
304 phone := setupPhone(ctx, t, 60)
305
306 signingKey, webhookPath := setupWebhook(ctx, t, phone.PhoneNumber, []string{
307 "message.phone.sent",
308 "message.phone.delivered",
309 })
310
311 client := newAPIClient()
312 contactNumber := randomPhoneNumber()
313 content := "Outstanding flow test " + randomEncryptionKey()
314
315 sendResp, resp, err := client.Messages.Send(ctx, &httpsms.MessageSendParams{
316 From: phone.PhoneNumber,
317 To: contactNumber,
318 Content: content,
319 })
320 require.NoError(t, err)
321 require.Equal(t, http.StatusOK, resp.HTTPResponse.StatusCode)
322
323 messageID := sendResp.Data.ID.String()
324 t.Logf("sent message: %s", messageID)
325
326 fcmReqs := waitForFCMPush(t, messageID, 30*time.Second)
327 require.Len(t, fcmReqs, 1)
328 assert.Contains(t, fcmReqs[0].Request.Body, messageID)
329 assert.True(t, strings.Contains(fcmReqs[0].Request.URL, "/messages:send") || strings.Contains(fcmReqs[0].Request.AbsoluteURL, "/messages:send"))
330
331 outstanding := fetchOutstandingMessage(ctx, t, phone.PhoneAPIKey, messageID)
332 assert.Equal(t, messageID, outstanding["id"])
333 assert.Equal(t, content, outstanding["content"])
334 assert.Equal(t, phone.PhoneNumber, outstanding["owner"])
335 assert.Equal(t, contactNumber, outstanding["contact"])
336
337 fireEvent(ctx, t, phone.PhoneAPIKey, messageID, "SENT")
338 time.Sleep(200 * time.Millisecond)
339 fireEvent(ctx, t, phone.PhoneAPIKey, messageID, "DELIVERED")
340
341 msg := pollMessageStatus(ctx, t, messageID, "delivered", 30*time.Second)
342 assert.Equal(t, "delivered", msg.Status)
343 assert.Equal(t, content, msg.Content)
344
345 webhookReqs := waitForWebhookEvents(t, webhookPath, 2, 30*time.Second)
346 for _, req := range webhookReqs {
347 assertWebhookJWT(t, req.Request, signingKey)
348 }
349}
350
351func TestHeartbeat_StoreAndIndex(t *testing.T) {
352 ctx := context.Background()

Callers

nothing calls this directly

Calls 13

setupPhoneFunction · 0.85
setupWebhookFunction · 0.85
newAPIClientFunction · 0.85
randomPhoneNumberFunction · 0.85
randomEncryptionKeyFunction · 0.85
waitForFCMPushFunction · 0.85
fetchOutstandingMessageFunction · 0.85
fireEventFunction · 0.85
pollMessageStatusFunction · 0.85
waitForWebhookEventsFunction · 0.85
assertWebhookJWTFunction · 0.85
SendMethod · 0.65

Tested by

no test coverage detected