How do you test http requests with unit tests?

Hello,
I’m writing a microservice that will get events from an event bus and pass them to a set of http endpoints. I’m using free monad to separate business logic from execution. As a part of interpretation I created a function that just sends http request with provided payload and handles server response (code below).

My question: how do I test this function? I’d like to make sure that headers are properly set and responses handled (possibly with retries). I couldn’t find any recommendations for that problem except for Affjax tests that use FFI to create a http server ( Affjax tests )

Should I interpret my free monad to another free monad that handles the responses and retries like here and test that? It looks like an overkill for a simple service it supposed to be.

Or maybe I shouldn’t be testing http requests with unit tests at all?

Please halp :slight_smile:

sendAlert ::
  forall r.
  { url :: String, secret :: String | r } ->
  MyRequest ->
  WriterT (Array ProcessingError) Aff Unit
sendAlert config request = do
  res <-
    lift $ AX.request
      $ AX.defaultRequest
          { method = Left POST
          , url = config.url
          , headers = headers config.secret
          , responseFormat = ResponseFormat.json
          , content = Just $ RequestBody.json $ encodeJson request
          }
  case res of
    Left e -> tell $ [ requestErrorOf request e ]
    Right response
      | statusOk response.status -> pure unit
      | statusServerError response.status -> tell $ [ responseErrorOf request response ] -- TODO retry?
      | otherwise -> tell $ [ responseErrorOf request response ]