From 76b4b85a0fa95b76fe9f67b2e461f5f1709c0e4d Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Tue, 20 Aug 2019 12:26:24 -0400 Subject: [PATCH] implemented startNewSeason --- src/Mtlstats/Actions.hs | 4 +++- test/ActionsSpec.hs | 28 +++++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Mtlstats/Actions.hs b/src/Mtlstats/Actions.hs index 6dc1b85..9978c50 100644 --- a/src/Mtlstats/Actions.hs +++ b/src/Mtlstats/Actions.hs @@ -21,11 +21,13 @@ along with this program. If not, see . module Mtlstats.Actions (startNewSeason, startNewGame) where +import Lens.Micro ((.~)) + import Mtlstats.Types -- | Starts a new season startNewSeason :: ProgState -> ProgState -startNewSeason = undefined +startNewSeason = (progMode .~ NewSeason) . (database . dbGames .~ 0) -- | Starts a new game startNewGame :: ProgState -> ProgState diff --git a/test/ActionsSpec.hs b/test/ActionsSpec.hs index 3478a6e..3d8dcc1 100644 --- a/test/ActionsSpec.hs +++ b/test/ActionsSpec.hs @@ -21,15 +21,29 @@ along with this program. If not, see . module ActionsSpec (spec) where -import Test.Hspec (Spec, describe) +import Lens.Micro ((&), (.~), (^.)) +import Test.Hspec (Spec, describe, it, shouldBe) + +import Mtlstats.Actions +import Mtlstats.Types spec :: Spec spec = describe "Mtlstats.Actions" $ do - startSeasonSpec - startGameSpec + startNewSeasonSpec + startNewGameSpec -startSeasonSpec :: Spec -startSeasonSpec = describe "startSeason" $ return () +startNewSeasonSpec :: Spec +startNewSeasonSpec = describe "startNewSeason" $ do + let + s = newProgState + & database . dbGames .~ 1 + & startNewSeason -startGameSpec :: Spec -startGameSpec = describe "startGame" $ return () + it "should set the progState to NewSeason" $ + s ^. progMode `shouldBe` NewSeason + + it "should set the number of games to 0" $ + s ^. database . dbGames `shouldBe` 0 + +startNewGameSpec :: Spec +startNewGameSpec = describe "startGame" $ return ()