123
This commit is contained in:
parent
68591237c0
commit
3f342053f5
14
test/Spec.hs
14
test/Spec.hs
@ -5,6 +5,7 @@ import UserManager
|
||||
import Database.SQLite.Simple
|
||||
import Control.Exception (bracket_)
|
||||
import System.Directory (removeFile, doesFileExist)
|
||||
import Data.String (fromString)
|
||||
|
||||
main :: IO ()
|
||||
main = hspec $ do
|
||||
@ -12,21 +13,20 @@ main = hspec $ do
|
||||
beforeAll_ setupDB $
|
||||
afterAll_ cleanupDB $ do
|
||||
it "initializes the database" $ do
|
||||
conn <- open "test_users.db"
|
||||
conn <- open "users.db"
|
||||
tables <- query_ conn "SELECT name FROM sqlite_master WHERE type='table' AND name='users';" :: IO [Only String]
|
||||
close conn
|
||||
tables `shouldBe` [Only "users"]
|
||||
|
||||
it "adds a user" $ do
|
||||
addUser "test_user" "test@example.com" "password"
|
||||
users <- listUsers
|
||||
users <- findUsers "test_user"
|
||||
users `shouldBe` [User "test_user" "test@example.com" "password"]
|
||||
|
||||
it "lists users" $ do
|
||||
addUser "test_user1" "test1@example.com" "password1"
|
||||
addUser "test_user2" "test2@example.com" "password2"
|
||||
users <- listUsers
|
||||
users `shouldBe` [User "test_user1" "test1@example.com" "password1", User "test_user2" "test2@example.com" "password2"]
|
||||
users `shouldBe` [User "test_user" "test@example.com" "password", User "test_user1" "test1@example.com" "password1" ]
|
||||
|
||||
it "finds users by name" $ do
|
||||
addUser "unique_user" "unique@example.com" "password"
|
||||
@ -46,9 +46,9 @@ main = hspec $ do
|
||||
|
||||
setupDB :: IO ()
|
||||
setupDB = do
|
||||
conn <- open "test_users.db"
|
||||
execute_ conn "CREATE TABLE users (name TEXT PRIMARY KEY, email TEXT, password TEXT)"
|
||||
conn <- open "users.db"
|
||||
execute_ conn "CREATE TABLE IF NOT EXISTS users (name TEXT PRIMARY KEY, email TEXT, password TEXT)"
|
||||
close conn
|
||||
|
||||
cleanupDB :: IO ()
|
||||
cleanupDB = removeFile "test_users.db"
|
||||
cleanupDB = removeFile "users.db"
|
||||
|
Loading…
Reference in New Issue
Block a user