diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-05 06:28:38 +0100 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-05 06:28:38 +0100 |
| commit | 3621ddbdff4d52ad58f9af57b8a47e50d42be948 (patch) | |
| tree | 56f3a0e0d2dcf293364ed0a3f5c3429a1c5139a1 /lambda-calcul | |
| parent | 7fbba2eb68ec5855d7af0adcf4fe0d6948177a43 (diff) | |
| download | lambda-nantes-3621ddbdff4d52ad58f9af57b8a47e50d42be948.tar.gz | |
return correct leaderboard
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 |
