Compare commits
No commits in common. "fb29a6e694e65b5d946a7b0f9b6c8bbf00d576f6" and "6cabe97b30a15072f4dbf59b02ddd46a58c34b56" have entirely different histories.
fb29a6e694
...
6cabe97b30
@ -86,20 +86,3 @@ executable backend
|
||||
, NoImplicitPrelude
|
||||
, OverloadedStrings
|
||||
, RecordWildCards
|
||||
|
||||
test-suite spec
|
||||
type: exitcode-stdio-1.0
|
||||
main-is: Spec.hs
|
||||
hs-source-dirs: src
|
||||
build-depends: base >=4.10
|
||||
, classy-prelude
|
||||
, http-api-data
|
||||
, selda
|
||||
, selda-postgresql
|
||||
, aeson
|
||||
, text
|
||||
, validity
|
||||
, genvalidity-hspec
|
||||
, genvalidity-property
|
||||
, genvalidity-text
|
||||
, hspec
|
||||
|
@ -14,13 +14,13 @@ import Data.Aeson
|
||||
import Web.HttpApiData
|
||||
|
||||
-- | User type
|
||||
newtype PlainPassword = PlainPassword Text deriving (Show, ToJSON, FromJSON, ToHttpApiData, FromHttpApiData, Eq, Generic)
|
||||
newtype PlainPassword = PlainPassword Text deriving (Show, ToJSON, FromJSON, ToHttpApiData, FromHttpApiData, Eq)
|
||||
newtype HashedPassword = HashedPassword {unHashed :: ByteString}
|
||||
data NoPassword = NoPassword
|
||||
|
||||
newtype Email = Email { unEmail :: Text } deriving (Show, ToJSON, FromJSON, ToHttpApiData, FromHttpApiData, Generic, Eq)
|
||||
newtype Email = Email { unEmail :: Text } deriving (Show, ToJSON, FromJSON, ToHttpApiData, FromHttpApiData)
|
||||
|
||||
newtype Username = Username { unUsername :: Text } deriving (Show, ToJSON, FromJSON, ToHttpApiData, FromHttpApiData, Eq, Generic)
|
||||
newtype Username = Username { unUsername :: Text } deriving (Show, ToJSON, FromJSON, ToHttpApiData, FromHttpApiData)
|
||||
|
||||
instance SqlType HashedPassword where
|
||||
mkLit = LCustom . LBlob . unHashed
|
||||
@ -42,9 +42,9 @@ instance SqlType Username where
|
||||
|
||||
newtype UserID = UserID {unUserID :: Int} deriving (Show)
|
||||
|
||||
newtype BookID = BookID {unBookID :: Int} deriving (Show, ToJSON, FromJSON, FromHttpApiData, Eq, Ord, ToHttpApiData, Generic)
|
||||
newtype BookID = BookID {unBookID :: Int} deriving (Show, ToJSON, FromJSON, FromHttpApiData, Eq, Ord, ToHttpApiData)
|
||||
|
||||
newtype ChannelID = ChannelID {unChannelID :: Int} deriving (Show, ToHttpApiData, FromHttpApiData, ToJSON, FromJSON, Eq, Generic)
|
||||
newtype ChannelID = ChannelID {unChannelID :: Int} deriving (Show, ToHttpApiData, FromHttpApiData, ToJSON, FromJSON)
|
||||
|
||||
newtype TagID = TagID {unTagID :: Int} deriving (Show)
|
||||
|
||||
@ -77,7 +77,7 @@ data User pass = User { identifier :: UserID
|
||||
, password :: pass }
|
||||
deriving (Show, Generic)
|
||||
|
||||
data Role = UserRole | AdminRole deriving (Show, Read, Enum, Bounded, Typeable, Generic, Eq)
|
||||
data Role = UserRole | AdminRole deriving (Show, Read, Enum, Bounded, Typeable, Generic)
|
||||
|
||||
instance ToJSON Role
|
||||
instance FromJSON Role
|
||||
@ -125,7 +125,7 @@ data Tag = Tag { identifier :: TagID
|
||||
deriving (Show, Generic)
|
||||
|
||||
data Visibility = Public | Private | Followers
|
||||
deriving (Show, Read, Generic, Eq)
|
||||
deriving (Show, Read, Generic)
|
||||
|
||||
instance ToJSON Visibility
|
||||
instance FromJSON Visibility
|
||||
|
@ -1,53 +0,0 @@
|
||||
{-# Language TypeApplications #-}
|
||||
module Main where
|
||||
|
||||
import qualified Data.Aeson as A
|
||||
import Data.Char (isPrint)
|
||||
import Data.GenValidity.Text ()
|
||||
import qualified Data.Text as T
|
||||
import Database.Schema
|
||||
import Test.Hspec
|
||||
import Test.Validity
|
||||
|
||||
instance GenUnchecked PlainPassword
|
||||
instance GenValid PlainPassword
|
||||
instance GenInvalid PlainPassword
|
||||
instance Validity PlainPassword
|
||||
instance GenUnchecked Email
|
||||
instance GenValid Email
|
||||
instance GenInvalid Email
|
||||
instance Validity Email
|
||||
instance GenUnchecked Username
|
||||
instance GenValid Username
|
||||
instance GenInvalid Username
|
||||
instance Validity Username
|
||||
instance GenUnchecked BookID
|
||||
instance GenValid BookID
|
||||
instance GenInvalid BookID
|
||||
instance Validity BookID
|
||||
instance GenUnchecked ChannelID
|
||||
instance GenValid ChannelID
|
||||
instance GenInvalid ChannelID
|
||||
instance Validity ChannelID
|
||||
instance GenUnchecked Role
|
||||
instance GenValid Role
|
||||
instance GenInvalid Role
|
||||
instance Validity Role
|
||||
instance GenUnchecked Visibility
|
||||
instance GenValid Visibility
|
||||
instance GenInvalid Visibility
|
||||
instance Validity Visibility
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "JSON encoding" $ do
|
||||
it "Works for PlainPassword" $ inverseFunctionsIfSecondSucceedsOnValid (A.encode @PlainPassword) A.decode
|
||||
it "Works for Email" $ inverseFunctionsIfSecondSucceedsOnValid (A.encode @Email) A.decode
|
||||
it "Username" $ inverseFunctionsIfSecondSucceedsOnValid (A.encode @Username) A.decode
|
||||
it "Works for BookID" $ inverseFunctionsIfSecondSucceedsOnValid (A.encode @BookID) A.decode
|
||||
it "Works for ChannelID" $ inverseFunctionsIfSecondSucceedsOnValid (A.encode @ChannelID) A.decode
|
||||
it "Works for Role" $ inverseFunctionsIfSecondSucceedsOnValid (A.encode @Role) A.decode
|
||||
it "Works for Visibility" $ inverseFunctionsIfSecondSucceedsOnValid (A.encode @Visibility) A.decode
|
||||
|
||||
main :: IO ()
|
||||
main = hspec spec
|
@ -31,21 +31,3 @@ library
|
||||
, OverloadedStrings
|
||||
, RecordWildCards
|
||||
default-language: Haskell2010
|
||||
|
||||
test-suite spec
|
||||
type: exitcode-stdio-1.0
|
||||
main-is: Spec.hs
|
||||
hs-source-dirs: src
|
||||
build-depends: base >=4.10
|
||||
, classy-prelude
|
||||
, dhall
|
||||
, foreign-store
|
||||
, generic-lens
|
||||
, lens
|
||||
, mtl
|
||||
, text
|
||||
, transformers
|
||||
, validity
|
||||
, genvalidity-hspec
|
||||
, genvalidity-property
|
||||
, hspec
|
@ -1,9 +0,0 @@
|
||||
module Main where
|
||||
|
||||
import Test.Hspec
|
||||
|
||||
spec :: Spec
|
||||
spec = describe "test" $ it "verifies tests work" $ True == True
|
||||
|
||||
main :: IO ()
|
||||
main = hspec spec
|
Loading…
Reference in New Issue
Block a user