markandrus / twilio-haskell

Twilio library for Haskell
BSD 3-Clause "New" or "Revised" License
38 stars 39 forks source link

Testing the Library #49

Open StevenXL opened 6 years ago

StevenXL commented 6 years ago

Hi Folks,

I'm new to the Haskell world, and I want to start contributing to an open-source library as a means of improving myself.

I picked this project because I'm a web developer by trade (though not training), and communicating with REST APIs is definitely in my wheel house.

That being said, how am I supposed to run the test suite for this library?

I have a running rest suite, I have twilio test credentials in the environment in which I am running the test suite, but then I get an error (the error is below).

It's obvious from the error that we are making a request to an endpoint that doesn't allow test credentials. Is the expectation for the test suite that live credentials would be put in there?

twilio-0.2.0.0: test (suite: Tests)

Tests: HttpExceptionRequest Request {
  host                 = "api.twilio.com"
  port                 = 443
  secure               = True
  requestHeaders       = [("Authorization","Basic IAmHidingThisBecauseIDon'tWantToBeHacked!")]
  path                 = "/2010-04-01/Accounts.json"
  queryString          = ""
  method               = "GET"
  proxy                = Nothing
  rawBody              = False
  redirectCount        = 10
  responseTimeout      = ResponseTimeoutDefault
  requestVersion       = HTTP/1.1
}
 (StatusCodeException (Response {responseStatus = Status {statusCode = 403, statusMessage = "FORBIDDEN"}, responseVersion = HTTP/1.1, responseHeaders = [("Access-Control-Allow-Credentials","true"),("Access-Control-Allow-Headers","Accept, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since"),("Access-Control-Allow-Methods","GET, POST, DELETE, OPTIONS"),("Access-Control-Allow-Origin","*"),("Access-Control-Expose-Headers","ETag"),("Content-Type","application/json"),("Date","Fri, 13 Oct 2017 15:44:48 GMT"),("Twilio-Request-Duration","0.013"),("Twilio-Request-Id","RQa95adc7d0fe64dc8b171c98397cfc861"),("X-Powered-By","AT-5000"),("X-Shenanigans","none"),("Content-Length","155"),("Connection","keep-alive")], responseBody = (), responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose}) "{\"code\": 20008, \"message\": \"Resource not accessible with Test Account Credentials\", \"more_info\": \"https://www.twilio.com/docs/errors/20008\", \"status\": 403}")

Test suite failure for package twilio-0.2.0.0
    Tests:  exited with: ExitFailure 1
Logs printed to console
markandrus commented 6 years ago

Hi @StevenXL,

That's great to hear! This is a pretty small hobby project. It lacks many features, some things we don't have a solution for yet (like, paging! it's a bit embarrassing 😅), and—as you've noticed (and others—the testing isn't in the best place. But, if you're willing to choose-your-own-adventure here, I hope you can contribute!

The tests we have currently are integration tests that require non-test credentials which are read in from the ACCOUNT_SID and AUTH_TOKEN environment variables. Travis CI will inject these environment variables into any PR opened from a branch on the repository itself, but it will not inject them on PRs opened from forks (see here).

You can override ACCOUNT_SID and AUTH_TOKEN, but the integration tests currently hard-code phone numbers specific to the test account (see here and here). In order to be able to run these on any account, we need to

  1. Let these phone numbers be configurable, and
  2. Document what capabilities these phone numbers should have (e.g., ability to send/receive SMS, etc.) and how to provision them with Twilio.

Just this would be an improvement for our integration tests, but we also really need unit tests, too. Right now, any changes to the JSON parsing have to be tested by way of the integration tests, which slows down development.