<commit_before>{-# LANGUAGE OverloadedStrings #-}

-- TODO: Refactor Betty.Signup, make it testable, and actually test
-- that piece of code instead of this isolated code.

module SESTest (sesMailSpecs) where

import Yesod

import Betty.SESCreds                (access, ender, secret, sender)
import Network.HTTP.Conduit          (withManager)
import Network.Mail.Mime
import Network.Mail.Mime.SES
import Text.Blaze.Html.Renderer.Utf8 (renderHtml)

import TestImport

-- TODO: refactor to correctly use Betty.Signup.SES

sesMailSpecs :: Spec
sesMailSpecs = ydescribe "SES Email test" $ do
  yit "Does nothing in particular" $ do
    assertEqual "Nothing" True $ not False

  yit "Try SES" $ do
    withManager $ \manager ->
      renderSendMailSES manager ses mail
    assertEqual "Nothing" True $ not False

ses :: SES
ses = SES { sesFrom = sender
          , sesTo = [ender]
          , sesAccessKey = access
          , sesSecretKey = secret
          , sesRegion    = "us-east-1"
          }

mail :: Mail
mail = Mail { mailHeaders =
                 [("Subject", "Testing email")]
            , mailFrom = Address Nothing sender
            , mailTo = [Address Nothing ender]
            , mailCc = []
            , mailBcc = []
            , mailParts = return [textpart, htmlpart]
            }

textpart :: Part
textpart = Part "text/plain" None Nothing [] $
           "Just some text"

htmlpart :: Part
htmlpart = Part "text/html" None Nothing [] $
           renderHtml $ toHtml ("Just some html" :: String)

<commit_msg>Use `newManager` instead of `withManager`<commit_after>{-# LANGUAGE OverloadedStrings #-}

-- TODO: Refactor Betty.Signup, make it testable, and actually test
-- that piece of code instead of this isolated code.

module SESTest (sesMailSpecs) where

import Yesod

import Betty.SESCreds                (access, ender, secret, sender)
import Control.Monad.Trans.Resource  (runResourceT)
import Network.HTTP.Conduit          (newManager, tlsManagerSettings)
import Network.Mail.Mime
import Network.Mail.Mime.SES
import Text.Blaze.Html.Renderer.Utf8 (renderHtml)

import TestImport

-- TODO: refactor to correctly use Betty.Signup.SES

sesMailSpecs :: Spec
sesMailSpecs = ydescribe "SES Email test" $ do
  yit "Does nothing in particular" $ do
    assertEqual "Nothing" True $ not False

  yit "Try SES" $ do
      runResourceT $ do
          manager <- liftIO $ newManager tlsManagerSettings
          renderSendMailSES manager ses mail

    assertEqual "Nothing" True $ not False

ses :: SES
ses = SES { sesFrom = sender
          , sesTo = [ender]
          , sesAccessKey = access
          , sesSecretKey = secret
          , sesRegion    = "us-east-1"
          }

mail :: Mail
mail = Mail { mailHeaders =
                 [("Subject", "Testing email")]
            , mailFrom = Address Nothing sender
            , mailTo = [Address Nothing ender]
            , mailCc = []
            , mailBcc = []
            , mailParts = return [textpart, htmlpart]
            }

textpart :: Part
textpart = Part "text/plain" None Nothing [] $
           "Just some text"

htmlpart :: Part
htmlpart = Part "text/html" None Nothing [] $
           renderHtml $ toHtml ("Just some html" :: String)


{'fraction_non_alphanumeric': 0.09559279950341402, 'fraction_numerical': 0.0012414649286157666, 'mean_word_length': 2.4507494646680943, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3778826', 'n_tokens_mistral': 956, 'n_tokens_neox': 930, 'n_words': 300}