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

Function fireEvent

tests/helpers_test.go:140–163  ·  view source on GitHub ↗
(ctx context.Context, t *testing.T, phoneAPIKey string, messageID string, eventName string)

Source from the content-addressed store, hash-verified

138}
139
140func fireEvent(ctx context.Context, t *testing.T, phoneAPIKey string, messageID string, eventName string) {
141 t.Helper()
142
143 url := fmt.Sprintf("%s/v1/messages/%s/events", apiBaseURL, messageID)
144 payload := map[string]interface{}{
145 "event_name": eventName,
146 "timestamp": time.Now().UTC().Format(time.RFC3339),
147 }
148 body, err := json.Marshal(payload)
149 require.NoError(t, err)
150
151 req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body))
152 require.NoError(t, err)
153 req.Header.Set("Content-Type", "application/json")
154 req.Header.Set("x-api-key", phoneAPIKey)
155
156 resp, err := http.DefaultClient.Do(req)
157 require.NoError(t, err)
158 defer resp.Body.Close()
159
160 respBody, err := io.ReadAll(resp.Body)
161 require.NoError(t, err)
162 require.Equal(t, http.StatusOK, resp.StatusCode, "fire event %s failed: %s", eventName, string(respBody))
163}
164
165func pollMessageStatus(ctx context.Context, t *testing.T, messageID string, targetStatus string, timeout time.Duration) httpsms.Message {
166 t.Helper()

Callers 5

TestSendSMS_EncryptedFunction · 0.85
TestSendSMS_RateLimitFunction · 0.85
TestBulkSMS_CSVFunction · 0.85
TestBulkSMS_ExcelFunction · 0.85

Calls 1

SetMethod · 0.65

Tested by

no test coverage detected