|
| 1 | +{-# LANGUAGE OverloadedStrings #-} |
| 2 | +{-# LANGUAGE TemplateHaskell #-} |
| 3 | +module Github.ReposSpec where |
| 4 | + |
| 5 | +import Github.Auth (GithubAuth (..)) |
| 6 | +import Github.Repos (currentUserRepos, userRepos', RepoPublicity(..)) |
| 7 | + |
| 8 | +-- import Data.Aeson.Compat (eitherDecodeStrict) |
| 9 | +import Data.Either.Compat (isRight) |
| 10 | +-- import Data.FileEmbed (embedFile) |
| 11 | +import System.Environment (lookupEnv) |
| 12 | +import Test.Hspec (Spec, describe, it, pendingWith, shouldSatisfy) |
| 13 | + |
| 14 | +fromRightS :: Show a => Either a b -> b |
| 15 | +fromRightS (Right b) = b |
| 16 | +fromRightS (Left a) = error $ "Expected a Right and got a Left" ++ show a |
| 17 | + |
| 18 | +withAuth :: (GithubAuth -> IO ()) -> IO () |
| 19 | +withAuth action = do |
| 20 | + mtoken <- lookupEnv "GITHUB_TOKEN" |
| 21 | + case mtoken of |
| 22 | + Nothing -> pendingWith "no GITHUB_TOKEN" |
| 23 | + Just token -> action (GithubOAuth token) |
| 24 | + |
| 25 | +spec :: Spec |
| 26 | +spec = do |
| 27 | + describe "currentUserRepos" $ do |
| 28 | + it "works" $ withAuth $ \auth -> do |
| 29 | + cs <- currentUserRepos auth All |
| 30 | + cs `shouldSatisfy` isRight |
| 31 | + |
| 32 | + describe "userRepos" $ do |
| 33 | + it "works" $ withAuth $ \auth -> do |
| 34 | + cs <- userRepos' (Just auth) "phadej" All |
| 35 | + cs `shouldSatisfy` isRight |
0 commit comments