|
| 1 | +{-# LANGUAGE TemplateHaskell #-} |
1 | 2 | module Github.UsersSpec where |
2 | 3 |
|
3 | | -import Github.Users (userInfoFor) |
| 4 | +import Github.Auth (GithubAuth(..)) |
| 5 | +import Github.Users (userInfoFor') |
4 | 6 | import Github.Data.Definitions (DetailedOwner(..)) |
5 | 7 |
|
6 | | -import Test.Hspec (it, describe, shouldBe, Spec) |
| 8 | +import Data.Aeson.Compat (eitherDecodeStrict) |
| 9 | +import Test.Hspec (it, describe, shouldBe, pendingWith, Spec) |
| 10 | +import System.Environment (lookupEnv) |
| 11 | +import Data.FileEmbed (embedFile) |
7 | 12 |
|
8 | 13 | fromRightS :: Show a => Either a b -> b |
9 | 14 | fromRightS (Right b) = b |
10 | 15 | fromRightS (Left a) = error $ "Expected a Right and got a Left" ++ show a |
11 | 16 |
|
| 17 | +withAuth :: (GithubAuth -> IO ()) -> IO () |
| 18 | +withAuth action = do |
| 19 | + mtoken <- lookupEnv "GITHUB_TOKEN" |
| 20 | + case mtoken of |
| 21 | + Nothing -> pendingWith "no GITHUB_TOKEN" |
| 22 | + Just token -> action (GithubOAuth token) |
| 23 | + |
12 | 24 | spec :: Spec |
13 | 25 | spec = |
14 | 26 | describe "userInfoFor" $ do |
15 | | - it "returns information about the user" $ do |
16 | | - userInfo <- userInfoFor "mike-burns" |
| 27 | + it "decodes user json" $ do |
| 28 | + let userInfo = eitherDecodeStrict $(embedFile "fixtures/user.json") :: Either String DetailedOwner |
| 29 | + detailedOwnerLogin (fromRightS userInfo) `shouldBe` "mike-burns" |
| 30 | + |
| 31 | + it "returns information about the user" $ withAuth $ \auth -> do |
| 32 | + userInfo <- userInfoFor' (Just auth) "mike-burns" |
17 | 33 | detailedOwnerLogin (fromRightS userInfo) `shouldBe` "mike-burns" |
0 commit comments