heddit-0.0.1: io-tests/MeSpec.hs
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE TypeApplications #-}
module MeSpec ( spec ) where
import Data.Either
import Data.Generics.Labels ()
import Lens.Micro.GHC
import Network.Reddit
import Profile
import Test.Hspec
spec :: Spec
spec = beforeAll loadClientAndProfile . describe "Network.Reddit.Me"
$ sequence_ [ account, multireddits, karma, friends ]
account :: SpecWith (Client, TestProfile)
account = it "gets the current user" $ \(c, profile) -> do
me <- runReddit c getMe
me ^. #username `shouldBe` profile ^. #username
me ^. #userID `shouldBe` profile ^. #userID
multireddits :: SpecWith (Client, TestProfile)
multireddits = it "gets the current user's multireddits" $ \(c, _) -> do
ms <- tryReddit @APIException c getMyMultireddits
ms `shouldSatisfy` isRight
karma :: SpecWith (Client, TestProfile)
karma = it "gets the current user's karma" $ \(c, _) -> do
ms <- tryReddit @APIException c getMyKarma
ms `shouldSatisfy` isRight
friends :: SpecWith (Client, TestProfile)
friends = it "gets the current user's friends" $ \(c, _) -> do
ms <- tryReddit @APIException c getMyFriends
ms `shouldSatisfy` isRight
loadClientAndProfile :: IO (Client, TestProfile)
loadClientAndProfile = (,) <$> loadClient Nothing <*> loadProfile