diff options
Diffstat (limited to 'lambda-calcul')
| -rw-r--r-- | lambda-calcul/haskell/src/Minilang/App.hs | 6 | ||||
| -rw-r--r-- | lambda-calcul/haskell/test/Minilang/ServerSpec.hs | 9 |
2 files changed, 10 insertions, 5 deletions
diff --git a/lambda-calcul/haskell/src/Minilang/App.hs b/lambda-calcul/haskell/src/Minilang/App.hs index 57c1fd6..52a7352 100644 --- a/lambda-calcul/haskell/src/Minilang/App.hs +++ b/lambda-calcul/haskell/src/Minilang/App.hs @@ -88,10 +88,10 @@ generateToken = writeTVar tvar newGen pure $ Token $ decodeUtf8 $ Base64.encode $ LBS.toStrict tokenBytes -getLeaderboard :: (MonadIO m) => m [Score] +getLeaderboard :: (MonadIO m, MonadReader Env m) => m [Score] getLeaderboard = do - now <- liftIO getCurrentTime - pure [Score (User "Alice") 95 (Just now), Score (User "Bob") 88 (Just now)] + usersMap <- asks users >>= liftIO . readTVarIO + pure $ Map.elems usersMap getChallenge :: (MonadReader Env m, MonadIO m) => Maybe Token -> m Challenge getChallenge Nothing = liftIO $ throwM $ err400 {errBody = "Missing token"} diff --git a/lambda-calcul/haskell/test/Minilang/ServerSpec.hs b/lambda-calcul/haskell/test/Minilang/ServerSpec.hs index 50c1590..c7c45b3 100644 --- a/lambda-calcul/haskell/test/Minilang/ServerSpec.hs +++ b/lambda-calcul/haskell/test/Minilang/ServerSpec.hs @@ -39,9 +39,9 @@ spec = with (app testSeed) $ do else Just "Expected HTML content" } - it "GET /api/leaderboard returns empty list of scores" $ do + it "GET /api/leaderboard returns empty list of scores at start" $ do get "/api/leaderboard" - `shouldRespondWith` 200 {matchBody = arrayOfLengthOf (Proxy @Score) 2} + `shouldRespondWith` 200 {matchBody = arrayOfLengthOf (Proxy @Score) 0} it "POST /api/register returns registration token given user is not registered" $ do postJSON "/api/register" alice @@ -53,6 +53,11 @@ spec = with (app testSeed) $ do else Just ("Expected token " ++ show token ++ ", but got " ++ show t) } + it "GET /api/leaderboard returns list of one element after user registers" $ do + void $ postJSON "/api/register" alice + get "/api/leaderboard" + `shouldRespondWith` 200 {matchBody = arrayOfLengthOf (Proxy @Score) 1} + it "POST /api/register returns 400 given user is already registered" $ do void $ postJSON "/api/register" alice |
