forked from haskell-github/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventsSpec.hs
More file actions
36 lines (31 loc) · 1.17 KB
/
Copy pathEventsSpec.hs
File metadata and controls
36 lines (31 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{-# LANGUAGE OverloadedStrings #-}
module GitHub.EventsSpec where
import Data.Either (isRight)
import Data.String (fromString)
import Prelude ()
import Prelude.Compat
import System.Environment (lookupEnv)
import Test.Hspec (Spec, describe, it, shouldSatisfy,
pendingWith)
import qualified GitHub
import GitHub.Data (Auth(..))
fromRightS :: Show a => Either a b -> b
fromRightS (Left xs) = error $ "Should be Right" ++ show xs
fromRightS (Right xs) = xs
withAuth :: (Auth -> IO ()) -> IO ()
withAuth action = do
mtoken <- lookupEnv "GITHUB_TOKEN"
case mtoken of
Nothing -> pendingWith "no GITHUB_TOKEN"
Just token -> action (OAuth $ fromString token)
spec :: Spec
spec = do
describe "repositoryEventsR" $ do
it "returns non empty list of events" $ shouldSucceed $
GitHub.repositoryEventsR "phadej" "github" 1
describe "userEventsR" $ do
it "returns non empty list of events" $ shouldSucceed $ GitHub.userEventsR "phadej" 1
where shouldSucceed f = withAuth $ \auth -> do
cs <- GitHub.executeRequest auth $ f
cs `shouldSatisfy` isRight
length (fromRightS cs) `shouldSatisfy` (> 1)