<commit_before>{-# LANGUAGE OverloadedStrings #-}
module Main (
  main
) where

import           Data.Text (Text)
import qualified Data.Text as T

import           Control.Monad ( join )
import           Control.Exception

import           System.Exit

import           Text.Show.Pretty ( ppShow )

import           Test.Tasty
import           Test.Tasty.HUnit

import           Network.Mattermost
import           Network.Mattermost.Logging
import           Network.Mattermost.Util

data Config
  = Config
  { configUsername :: Text
  , configHostname :: Text
  , configTeam     :: Text
  , configPort     :: Int
  , configPassword :: Text
  , configEmail    :: Text
  }

testConfig :: Config
testConfig = Config
  { configUsername = "test"
  , configEmail    = "<EMAIL>"
  , configHostname = "localhost"
  , configTeam     = "testteam"
  , configPort     = 8065
  , configPassword = "password"
  }

main :: IO ()
main = defaultMain tests
  `catch` \(SomeException e) -> do
    print e
    exitFailure

tests :: TestTree
tests = testCaseSteps "MM Tests" $ \step -> do
  step "Creating Admin account"
  _token <- setup step `catch` \(SomeException e) -> do
    print e
    exitFailure
  return ()

setup :: (String -> IO ()) -> IO Token
setup prnt = do
  cd' <- initConnectionDataInsecure (T.unpack (configHostname testConfig))
                                    (fromIntegral (configPort testConfig))
  let newAccount = UsersCreate { usersCreateEmail          = configEmail    testConfig
                               , usersCreatePassword       = <PASSWORD> testConfig
                               , usersCreateUsername       = configUsername testConfig
                               , usersCreateAllowMarketing = True
                               }
      cd = cd' `withLogger` mmLoggerDebugErr

  newUser <- mmUsersCreate cd newAccount
  let login = Login { username = configUsername testConfig
                    , password = <PASSWORD> test<PASSWORD>
                    }
  prnt "New user created"
  (token, mmUser) <- join (hoistE <$> mmLogin cd login)
  prnt "Authenticated as new user"
  return token<commit_msg>Remove redundant (and problematic) top-level catch. Also disable logging by default<commit_after>{-# LANGUAGE OverloadedStrings #-}
module Main (
  main
) where

import           Data.Text (Text)
import qualified Data.Text as T

import           Control.Monad ( join )
import           Control.Exception

import           System.Exit

import           Text.Show.Pretty ( ppShow )

import           Test.Tasty
import           Test.Tasty.HUnit

import           Network.Mattermost
import           Network.Mattermost.Logging
import           Network.Mattermost.Util

data Config
  = Config
  { configUsername :: Text
  , configHostname :: Text
  , configTeam     :: Text
  , configPort     :: Int
  , configPassword :: Text
  , configEmail    :: Text
  }

testConfig :: Config
testConfig = Config
  { configUsername = "test"
  , configEmail    = "<EMAIL>"
  , configHostname = "localhost"
  , configTeam     = "testteam"
  , configPort     = 8065
  , configPassword = "password"
  }

main :: IO ()
main = defaultMain tests

tests :: TestTree
tests = testCaseSteps "MM Tests" $ \step -> do
  step "Creating Admin account"
  _token <- setup step
  return ()

setup :: (String -> IO ()) -> IO Token
setup prnt = do
  cd <- initConnectionDataInsecure (T.unpack (configHostname testConfig))
                                   (fromIntegral (configPort testConfig))
  let newAccount = UsersCreate { usersCreateEmail          = configEmail    testConfig
                               , usersCreatePassword       = <PASSWORD> testConfig
                               , usersCreateUsername       = configUsername testConfig
                               , usersCreateAllowMarketing = True
                               }
      -- XXX: Use something like this if you want logging (useful when debugging)
      -- cd = cd `withLogger` mmLoggerDebugErr

  newUser <- mmUsersCreate cd newAccount
  let login = Login { username = configUsername testConfig
                    , password = <PASSWORD> testConfig
                    }
  prnt "Admin user created"
  (token, mmUser) <- join (hoistE <$> mmLogin cd login)
  prnt "Authenticated as admin user"
  return token
{'fraction_non_alphanumeric': 0.08189454036397574, 'fraction_numerical': 0.0018665422305179655, 'mean_word_length': 2.0490753911806543, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5848238', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1136, 'n_words': 339}