git.iko.soy/typeable/mandrill
on master help sign in
Online tests triggered by environment variable
8613a49Alfredo Di Napoli
mandrill.cabal+4−1
@@ -33,6 +33,7 @@ library
33 , aeson >= 0.7.0.3 && < 0.8
33 , aeson >= 0.7.0.3 && < 0.8
34 , lens >= 4.1 && < 4.6
34 , lens >= 4.1 && < 4.6
35 , blaze-html >= 0.5.0.0
35 , blaze-html >= 0.5.0.0
36+ , QuickCheck >= 2.6 && < 2.8
36 , time
37 , time
37 , old-locale
38 , old-locale
38 hs-source-dirs:
39 hs-source-dirs:
@@ -50,6 +51,7 @@ test-suite mandrill-tests
50 other-modules:
51 other-modules:
51 Tests
52 Tests
52 RawData
53 RawData
54+ Online
53 hs-source-dirs:
55 hs-source-dirs:
54 test
56 test
55 default-language:
57 default-language:
@@ -59,8 +61,9 @@ test-suite mandrill-tests
59 , base
61 , base
60 , aeson
62 , aeson
61 , bytestring
63 , bytestring
62− , QuickCheck >= 2.6 && < 2.8
64+ , QuickCheck
63 , tasty >= 0.7 && < 0.9
65 , tasty >= 0.7 && < 0.9
64 , tasty-quickcheck
66 , tasty-quickcheck
65 , tasty-hunit
67 , tasty-hunit
66 , raw-strings-qq < 1.2
68 , raw-strings-qq < 1.2
69+ , text
src/Network/API/Mandrill/Types.hs+12
@@ -5,6 +5,7 @@
5module Network.API.Mandrill.Types where
5module Network.API.Mandrill.Types where
6
6
7import Network.API.Mandrill.Utils
7import Network.API.Mandrill.Utils
8+import Test.QuickCheck
8import Data.Char
9import Data.Char
9import Data.Time
10import Data.Time
10import Control.Applicative
11import Control.Applicative
@@ -97,6 +98,8 @@ data MandrillRecipient = MandrillRecipient {
97makeLenses ''MandrillRecipient
98makeLenses ''MandrillRecipient
98deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillRecipient
99deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillRecipient
99
100
101+instance Arbitrary MandrillRecipient where
102+ arbitrary = pure $ MandrillRecipient "test@example.com" Nothing Nothing
100
103
101--------------------------------------------------------------------------------
104--------------------------------------------------------------------------------
102newtype MandrillHtml = MandrillHtml Blaze.Html
105newtype MandrillHtml = MandrillHtml Blaze.Html
@@ -117,6 +120,8 @@ instance FromJSON MandrillHtml where
117 parseJSON (String h) = return $ MandrillHtml (Blaze.toHtml h)
120 parseJSON (String h) = return $ MandrillHtml (Blaze.toHtml h)
118 parseJSON v = typeMismatch "Expecting a String for MandrillHtml" v
121 parseJSON v = typeMismatch "Expecting a String for MandrillHtml" v
119
122
123+instance Arbitrary MandrillHtml where
124+ arbitrary = pure $ mkMandrillHtml "<p><b>FooBar</b></p>"
120
125
121--------------------------------------------------------------------------------
126--------------------------------------------------------------------------------
122-- | The information on the message to send
127-- | The information on the message to send
@@ -138,6 +143,13 @@ data MandrillMessage = MandrillMessage {
138makeLenses ''MandrillMessage
143makeLenses ''MandrillMessage
139deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMessage
144deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMessage
140
145
146+instance Arbitrary MandrillMessage where
147+ arbitrary = MandrillMessage <$> arbitrary
148+ <*> pure Nothing
149+ <*> pure "Test Subject"
150+ <*> pure "sender@example.com"
151+ <*> pure Nothing
152+ <*> resize 2 arbitrary
141
153
142--------------------------------------------------------------------------------
154--------------------------------------------------------------------------------
143type MandrillKey = T.Text
155type MandrillKey = T.Text
test/Main.hs+29−10
@@ -1,20 +1,39 @@
1−
1+{-# LANGUAGE OverloadedStrings #-}
2module Main where
2module Main where
3
3
4+import System.Environment
5+import Data.Monoid
4−import Tests
6+import Tests
7+import Online
5−import Test.Tasty
8+import Test.Tasty
6−import Test.Tasty.HUnit
9+import Test.Tasty.HUnit
7−import Test.Tasty.QuickCheck
10+import Test.Tasty.QuickCheck
11+import qualified Data.Text as T
8
12
9----------------------------------------------------------------------
13----------------------------------------------------------------------
10withQuickCheckDepth :: TestName -> Int -> [TestTree] -> TestTree
14withQuickCheckDepth :: TestName -> Int -> [TestTree] -> TestTree
11withQuickCheckDepth tn depth tests =
15withQuickCheckDepth tn depth tests =
12 localOption (QuickCheckTests depth) (testGroup tn tests)
16 localOption (QuickCheckTests depth) (testGroup tn tests)
13
17
18+----------------------------------------------------------------------
19+onlineTestsIfEnabled :: IO [TestTree]
20+onlineTestsIfEnabled = do
21+ apiKey <- (return . fmap T.pack) =<< lookupEnv "MANDRILL_API_KEY"
22+ case apiKey of
23+ Nothing -> return []
24+ Just k -> return [
25+ testGroup "Mandrill online tests" [
26+ testCase "messages/send.json" (testOnlineMessagesSend k)
27+ ]]
28+
14----------------------------------------------------------------------
29----------------------------------------------------------------------
15main :: IO ()
30main :: IO ()
31+main = do
32+ onlineTests <- onlineTestsIfEnabled
16−main = defaultMainWithIngredients defaultIngredients $
33+ defaultMainWithIngredients defaultIngredients $
17− testGroup "Mandrill tests" [
34+ testGroup "Mandrill tests" $ onlineTests <> [
35+ testGroup "Mandrill offline tests" [
18− testCase "users/info.json API parsing" testUsersInfo
36+ testCase "users/info.json API parsing" testUsersInfo
19− , testCase "messages/send.json API parsing" testMessagesSend
37+ , testCase "messages/send.json API parsing" testMessagesSend
38+ ]
20− ]
39+ ]
test/Online.hsnew file+24
@@ -0,0 +1,24 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+module Online where
3+
4+import Test.QuickCheck
5+import Test.Tasty.HUnit
6+import Text.RawString.QQ
7+import Data.Either
8+import Data.Aeson
9+import Network.API.Mandrill.Messages.Types
10+import Network.API.Mandrill.Users.Types
11+import qualified Data.ByteString.Char8 as C8
12+import RawData
13+
14+import Network.API.Mandrill.Types
15+import qualified Network.API.Mandrill.Messages as API
16+
17+
18+testOnlineMessagesSend :: MandrillKey -> Assertion
19+testOnlineMessagesSend k = do
20+ msg <- generate arbitrary
21+ res <- API.send k msg Nothing Nothing Nothing
22+ case res of
23+ MandrillSuccess _ -> return ()
24+ MandrillFailure e -> fail $ "messages/send.json " ++ show e