[test] fix tests

parent 786d8c40
Pipeline #5483 passed with stages
in 126 minutes and 24 seconds
......@@ -38,7 +38,7 @@ import Test.QuickCheck.Arbitrary
------------------------------------------------------------------------
data ShareNodeParams = ShareTeamParams { username :: Text }
| SharePublicParams { node_id :: NodeId}
| SharePublicParams { node_id :: NodeId }
deriving (Generic)
------------------------------------------------------------------------
-- TODO unPrefix "pn_" FromJSON, ToJSON, ToSchema, adapt frontend.
......
......@@ -59,24 +59,17 @@ tests = sequential $ aroundAll withTestDBAndPort $ do
let authPayload = AuthRequest "alice" (GargPassword "alice")
result0 <- runClientM (auth_api authPayload) (clientEnv port)
let result = over (_Right . authRes_valid . _Just . authVal_token) (const cannedToken) result0
let result = over (_Right . authRes_token) (const cannedToken) result0
let expected = AuthResponse {
_authRes_valid = Just $
AuthValid {
_authVal_token = cannedToken
, _authVal_tree_id = fromMaybe (UnsafeMkNodeId 1) $ listToMaybe $ result0 ^.. _Right . authRes_valid . _Just . authVal_tree_id
, _authVal_user_id = fromMaybe (UnsafeMkUserId 1) $ listToMaybe $ result0 ^.. _Right . authRes_valid . _Just . authVal_user_id
}
, _authRes_inval = Nothing
}
_authRes_token = cannedToken
, _authRes_tree_id = fromMaybe (UnsafeMkNodeId 1) $ listToMaybe $ result0 ^.. _Right . authRes_tree_id
, _authRes_user_id = fromMaybe (UnsafeMkUserId 1) $ listToMaybe $ result0 ^.. _Right . authRes_user_id
}
result `shouldBe` (Right expected)
it "denies login for user 'alice' if password is invalid" $ \((_testEnv, port), _) -> do
let authPayload = AuthRequest "alice" (GargPassword "wrong")
result <- runClientM (auth_api authPayload) (clientEnv port)
let expected = AuthResponse {
_authRes_valid = Nothing
, _authRes_inval = Just $ AuthInvalid "Invalid username or password"
}
result `shouldBe` (Right expected)
putText $ "result: " <> show result
-- result `shouldBe` (Left $ InvalidUsernameOrPassword)
......@@ -47,7 +47,7 @@ tests = sequential $ aroundAll withTestDBAndPort $ do
| Status{..} <- simpleStatus
->liftIO $ do
statusCode `shouldBe` 404
simpleBody `shouldBe` [r|{"error":"Node does not exist (nodeId-99)"}|]
simpleBody `shouldBe` [r|{"node":99,"error":"Node does not exist"}|]
it "returns the new error if header X-Garg-Error-Scheme: new is passed" $ \((_testEnv, port), app) -> do
withApplication app $ do
......
......@@ -114,11 +114,7 @@ withValidLogin port ur pwd act = do
result <- liftIO $ runClientM (auth_api authPayload) clientEnv
case result of
Left err -> liftIO $ throwIO $ Prelude.userError (show err)
Right res
| Just tkn <- _authRes_valid res
-> act (_authVal_token tkn)
| otherwise
-> Prelude.fail $ "No token found in " <> show res
Right res -> act $ _authRes_token res
tests :: Spec
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment