fix: add test for all sms providers#676
Conversation
|
LGTM 👍 I prefer to set up a real http(ws, grpc) server where possible, but this is ok too. You may find examples here: https://github.com/supabase/cli/blob/main/test/mocks/supabase/server.go https://github.com/supabase/cli/blob/e92784551f57d9861fdd80e1a5965ec9e909641b/test/mocks/docker/server.go |
4a03f35 to
54ba0c6
Compare
|
🎉 This PR is included in version 2.16.6 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
| } | ||
|
|
||
| func (ts *SmsProviderTestSuite) TestTwilioSendSms() { | ||
| defer gock.Off() |
There was a problem hiding this comment.
I usually use defer gock.OffAll() so that unmatched requests don't carry over to the next test. https://pkg.go.dev/github.com/h2non/gock#OffAll
| err = twilioProvider.SendSms(phone, message) | ||
| require.Equal(ts.T(), c.ExpectedError, err) | ||
| }) | ||
| } |
There was a problem hiding this comment.
Another good check at the end of a test is assert.Empty(t, gock.GetUnmatchedRequests()). It ensures that all expectations you've set with gock are called once.
I also find its default logging a little unclear, so I created a helper to print out unmatched requests.
* refactor: use custom HttpClient interface * test: add test for twilio SendSms * use gock for mocking requests * test twilio error edge cases
* refactor: use custom HttpClient interface * test: add test for twilio SendSms * use gock for mocking requests * test twilio error edge cases
* refactor: use custom HttpClient interface * test: add test for twilio SendSms * use gock for mocking requests * test twilio error edge cases
* refactor: use custom HttpClient interface * test: add test for twilio SendSms * use gock for mocking requests * test twilio error edge cases
* refactor: use custom HttpClient interface * test: add test for twilio SendSms * use gock for mocking requests * test twilio error edge cases
* refactor: use custom HttpClient interface * test: add test for twilio SendSms * use gock for mocking requests * test twilio error edge cases
What kind of change does this PR introduce?
Introduce a customHttpClientinterface which can be overridden in tests.For tests insms_provider, we can overwrite the nativehttp.Clientwith aMockHttpClientand define the expected API behaviour from the 3rd-party sms providers withhandleApiRequest.To-Do
SendSmsfor messagebird, textlocal and vonage