-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathIssuesSpec.hs
More file actions
70 lines (59 loc) · 2.49 KB
/
IssuesSpec.hs
File metadata and controls
70 lines (59 loc) · 2.49 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
{-# LANGUAGE OverloadedStrings #-}
module GitHub.IssuesSpec where
import qualified GitHub
import Prelude ()
import Prelude.Compat
import Data.Either.Compat (isRight)
import Data.Foldable (for_)
import Data.String (fromString)
import Network.HTTP.Client (newManager, responseBody)
import System.Environment (lookupEnv)
import Test.Hspec (Spec, describe, expectationFailure, it, pendingWith, shouldSatisfy)
fromRightS :: Show a => Either a b -> b
fromRightS (Right b) = b
fromRightS (Left a) = error $ "Expected a Right and got a Left" ++ show a
withAuth :: (GitHub.Auth -> IO ()) -> IO ()
withAuth action = do
mtoken <- lookupEnv "GITHUB_TOKEN"
case mtoken of
Nothing -> pendingWith "no GITHUB_TOKEN"
Just token -> action (GitHub.OAuth $ fromString token)
spec :: Spec
spec = do
describe "issuesForRepoR" $ do
it "works" $ withAuth $ \auth -> for_ repos $ \(owner, repo) -> do
cs <- GitHub.executeRequest auth $
GitHub.issuesForRepoR owner repo mempty GitHub.FetchAll
case cs of
Left e ->
expectationFailure . show $ e
Right cs' -> do
for_ cs' $ \i -> do
cms <- GitHub.executeRequest auth $
GitHub.commentsR owner repo (GitHub.issueNumber i) 1
cms `shouldSatisfy` isRight
describe "issuesForRepoR paged" $ do
it "works" $ withAuth $ \auth -> for_ repos $ \(owner, repo) -> do
mgr <- newManager GitHub.tlsManagerSettings
ret <- GitHub.executeRequestWithMgrAndRes mgr auth $
GitHub.issuesForRepoR owner repo mempty (GitHub.FetchPage (GitHub.PageParams (Just 2) (Just 1)))
case ret of
Left e ->
expectationFailure . show $ e
Right res -> do
let issues = responseBody res
length issues `shouldSatisfy` (<= 2)
for_ issues $ \i -> do
cms <- GitHub.executeRequest auth $
GitHub.commentsR owner repo (GitHub.issueNumber i) 1
cms `shouldSatisfy` isRight
describe "issueR" $ do
it "fetches issue #428" $ withAuth $ \auth -> do
resIss <- GitHub.executeRequest auth $
GitHub.issueR "haskell-github" "github" (GitHub.IssueNumber 428)
resIss `shouldSatisfy` isRight
where
repos =
[ ("thoughtbot", "paperclip")
, ("haskell-github", "github")
]