Skip to content
Browse files

Updated tests to check roles/meta. Added destroyUser test.

  • Loading branch information...
1 parent 668b942 commit 4d92cdbb5836e7a36b0c06889a7fa5675a955e0e @alexanderkjeldaas alexanderkjeldaas committed with
Showing with 27 additions and 3 deletions.
  1. +2 −1 snaplet-sqlite-simple.cabal
  2. +2 −2 test/TestSuite.hs
  3. +23 −0 test/Tests.hs
View
3 snaplet-sqlite-simple.cabal
@@ -98,7 +98,8 @@ test-suite test
test-framework-hunit >= 0.2.7 && < 0.4,
text >= 0.11 && < 0.12,
time >= 1.1,
- transformers >= 0.2
+ transformers >= 0.2,
+ unordered-containers >= 0.2 && < 0.3
default-extensions:
FlexibleInstances
View
4 test/TestSuite.hs
@@ -23,6 +23,6 @@ main =
defaultMain tests `finally` (return ())
tests =
- [ mutuallyExclusive $ testGroup "with db migration" [Tests.testsDbInit]
- , mutuallyExclusive $ testGroup "from empty db" [Tests.tests]
+ [ mutuallyExclusive $ testGroup "from empty db" [Tests.tests]
+ , mutuallyExclusive $ testGroup "with db migration" [Tests.testsDbInit]
]
View
23 test/Tests.hs
@@ -6,6 +6,7 @@ module Tests
------------------------------------------------------------------------------
+import qualified Data.HashMap.Lazy as HM
import qualified Data.Map as M
import qualified Data.Text as T
import Test.Framework
@@ -44,6 +45,7 @@ testsDbInit = mutuallyExclusive $ testGroup "Snap.Snaplet.SqliteSimple"
-- Create empty db, add user in old schema, then access it
, testInitDbSchema0WithUser
, testUpdateUser
+ , testDestroyUser
]
isRight :: Either a b -> Bool
@@ -107,6 +109,25 @@ testInitDbSchema0WithUser = testCase "init + add foo user directly" $ do
(_, _handler, _doCleanup) <- runSnaplet Nothing appInit
assertBool "init ok" True
+-- | Why is this not in HUnit?
+assertFalse :: String -> Bool -> Assertion
+assertFalse s c = assertBool s (not c)
+
+testDestroyUser :: Test
+testDestroyUser = testCase "destroyUser works" assertDestroyUser
+ where
+ assertDestroyUser :: Assertion
+ assertDestroyUser = do
+ let hdl = with auth $ do
+ user <- createUser "destroy" "destroy"
+ -- This works
+ either (const $ return ()) destroyUser user
+ -- This has no effect when run
+ -- return $ fmap destroyUser user
+ usernameExists "destroy"
+ res <- evalHandler (ST.get "" M.empty) hdl appInit
+ either (assertFailure . show)
+ (assertFalse "destroyUser failed: User still there.") res
------------------------------------------------------------------------------
testCreateUserGood :: Test
@@ -129,6 +150,8 @@ testCreateUserGood = testCase "createUser good params" assertGoodUser
assertEqual "local host ip" Nothing (userLastLoginIp u)
assertEqual "locked until" Nothing (userLockedOutUntil u)
assertEqual "empty email" Nothing (userEmail u)
+ assertEqual "roles" [] (userRoles u)
+ assertEqual "meta" HM.empty (userMeta u)
------------------------------------------------------------------------------
-- Create a user, modify it, persist it and load again, check fields ok.

0 comments on commit 4d92cdb

Please sign in to comment.
Something went wrong with that request. Please try again.