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

Function setupPhone

tests/helpers_test.go:75–118  ·  view source on GitHub ↗
(ctx context.Context, t *testing.T, messagesPerMinute uint)

Source from the content-addressed store, hash-verified

73}
74
75func setupPhone(ctx context.Context, t *testing.T, messagesPerMinute uint) testPhone {
76 t.Helper()
77
78 phoneNumber := randomPhoneNumber()
79 fcmToken := "fcm-" + uuid.New().String()
80 client := newAPIClient()
81
82 // Create the phone API key first so that a few seconds pass (during phone upsert)
83 // before we use it, giving the cache time to clear.
84 apiKeyResp, resp, err := client.PhoneAPIKeys.Store(ctx, &httpsms.PhoneAPIKeyStoreParams{
85 Name: "test-key-" + uuid.New().String(),
86 })
87 require.NoError(t, err)
88 require.Equal(t, http.StatusOK, resp.HTTPResponse.StatusCode, "phone api key store failed")
89
90 phoneAPIKeyValue := apiKeyResp.Data.APIKey
91 require.NotEmpty(t, phoneAPIKeyValue)
92
93 _, resp, err = client.Phones.Upsert(ctx, &httpsms.PhoneUpsertParams{
94 PhoneNumber: phoneNumber,
95 FcmToken: fcmToken,
96 MessagesPerMinute: messagesPerMinute,
97 MaxSendAttempts: 2,
98 MessageExpirationSeconds: 600,
99 SIM: "SIM1",
100 })
101 require.NoError(t, err)
102 require.Equal(t, http.StatusOK, resp.HTTPResponse.StatusCode, "phone upsert failed")
103
104 phoneClient := newPhoneClient(phoneAPIKeyValue)
105 _, resp, err = phoneClient.Phones.UpsertFCMToken(ctx, &httpsms.PhoneFCMTokenParams{
106 PhoneNumber: phoneNumber,
107 FcmToken: fcmToken,
108 SIM: "SIM1",
109 })
110 require.NoError(t, err)
111 require.Equal(t, http.StatusOK, resp.HTTPResponse.StatusCode, "fcm token bind failed")
112
113 return testPhone{
114 PhoneNumber: phoneNumber,
115 PhoneAPIKey: phoneAPIKeyValue,
116 FcmToken: fcmToken,
117 }
118}
119
120func setupWebhook(ctx context.Context, t *testing.T, phoneNumber string, events []string) (signingKey string, webhookPath string) {
121 t.Helper()

Callers 7

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

Calls 7

randomPhoneNumberFunction · 0.85
newAPIClientFunction · 0.85
newPhoneClientFunction · 0.85
StoreMethod · 0.65
StringMethod · 0.45
UpsertMethod · 0.45
UpsertFCMTokenMethod · 0.45

Tested by

no test coverage detected