Test for rating formatting/parsing
This commit is contained in:
parent
57ee32cc9c
commit
710fec9b18
@ -10,7 +10,8 @@
|
||||
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
|
||||
|
||||
module Handler.Utils.Zip.Rating
|
||||
( getRating
|
||||
( Rating(..)
|
||||
, getRating
|
||||
, formatRating
|
||||
, parseRating
|
||||
) where
|
||||
@ -77,9 +78,9 @@ formatRating Rating{..} = let
|
||||
|
||||
|
||||
parseRating :: ByteString
|
||||
-> Either Text ( Maybe Points
|
||||
, Maybe Text -- ^ Rating comment
|
||||
)
|
||||
-> Either Text ( Maybe Points
|
||||
, Maybe Text -- ^ Rating comment
|
||||
)
|
||||
parseRating input = do
|
||||
inputText <- first tshow $ Text.decodeUtf8' input
|
||||
let
|
||||
|
||||
33
test/Handler/Utils/Zip/RatingSpec.hs
Normal file
33
test/Handler/Utils/Zip/RatingSpec.hs
Normal file
@ -0,0 +1,33 @@
|
||||
{-# LANGUAGE NoImplicitPrelude #-}
|
||||
{-# LANGUAGE RecordWildCards #-}
|
||||
|
||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||
|
||||
module Handler.Utils.Zip.RatingSpec where
|
||||
|
||||
import TestImport
|
||||
|
||||
import Handler.Utils.Zip.Rating
|
||||
|
||||
import qualified Data.ByteString.Lazy as Lazy.ByteString
|
||||
|
||||
import qualified Data.Text as Text
|
||||
|
||||
import Database.Persist.Class
|
||||
import Database.Persist.Sql
|
||||
|
||||
|
||||
instance Arbitrary Rating where
|
||||
arbitrary = do
|
||||
ratingCourseName <- arbitrary
|
||||
ratingSheetName <- arbitrary
|
||||
ratingSubmissionId <- SubmissionKey . SqlBackendKey <$> arbitrary
|
||||
ratingComment <- fmap Text.strip <$> arbitrary `suchThat` maybe True (not . Text.null)
|
||||
ratingPoints <- arbitrary
|
||||
return Rating{..}
|
||||
|
||||
|
||||
spec :: Spec
|
||||
spec = describe "Rating files" $ do
|
||||
it "have compatible formatting/parsing" . property $
|
||||
\rating@(Rating{..}) -> parseRating (Lazy.ByteString.toStrict $ formatRating rating) `shouldBe` Right (ratingPoints, ratingComment)
|
||||
@ -86,3 +86,5 @@ authenticateAs (Entity _ User{..}) = do
|
||||
-- checking is switched off in wipeDB for those database backends which need it.
|
||||
createUser :: Text -> Text -> YesodExample UniWorX (Entity User)
|
||||
createUser userPlugin userIdent = runDB $ insertEntity User{..}
|
||||
where
|
||||
userMatrikelnummer = "DummyMatrikelnummer"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user