set rookie flag on player creation

This commit is contained in:
Jonathan Lamothe 2020-02-13 10:35:35 -05:00
parent 4315b40732
commit c22849bb3b
2 changed files with 34 additions and 21 deletions

View File

@ -161,11 +161,13 @@ editSelectedGoalie f s = fromMaybe s $ do
addPlayer :: ProgState -> ProgState addPlayer :: ProgState -> ProgState
addPlayer s = fromMaybe s $ do addPlayer s = fromMaybe s $ do
let cps = s^.progMode.createPlayerStateL let cps = s^.progMode.createPlayerStateL
num <- cps^.cpsNumber num <- cps^.cpsNumber
rFlag <- cps^.cpsRookieFlag
let let
name = cps^.cpsName name = cps^.cpsName
pos = cps^.cpsPosition pos = cps^.cpsPosition
player = newPlayer num name pos player = newPlayer num name pos
& pRookie .~ rFlag
Just $ s & database.dbPlayers Just $ s & database.dbPlayers
%~ (++[player]) %~ (++[player])

View File

@ -312,28 +312,39 @@ editSelectedGoalieSpec = describe "editSelectedGoalie" $ mapM_
goalie' n = newGoalie n "foo" goalie' n = newGoalie n "foo"
addPlayerSpec :: Spec addPlayerSpec :: Spec
addPlayerSpec = describe "addPlayer" $ do addPlayerSpec = describe "addPlayer" $ mapM_
let (\(label, expectation, pm, players) -> context label $
p1 = newPlayer 1 "Joe" "centre" it expectation $ let
p2 = newPlayer 2 "Bob" "defense" ps = newProgState
db = newDatabase & progMode .~ pm
& dbPlayers .~ [p1] & database.dbPlayers .~ [joe]
s pm = newProgState ps' = addPlayer ps
& progMode .~ pm in ps'^.database.dbPlayers `shouldBe` players)
& database .~ db
context "data available" $ -- label, expectation, progMode, players
it "should create the player" $ let [ ( "wrong mode", failure, MainMenu, [joe] )
s' = addPlayer $ s $ CreatePlayer $ newCreatePlayerState , ( "missing number", failure, noNum, [joe] )
& cpsNumber ?~ 2 , ( "missing rookie flag", failure, noRookie, [joe] )
& cpsName .~ "Bob" , ( "rookie", success, mkRookie, [joe, rookie] )
& cpsPosition .~ "defense" , ( "normal player", success, mkNormal, [joe, normal] )
in s'^.database.dbPlayers `shouldBe` [p1, p2] ]
context "data unavailable" $ where
it "should not create the player" $ let failure = "should not create the player"
s' = addPlayer $ s MainMenu success = "should create the player"
in s'^.database.dbPlayers `shouldBe` [p1] noNum = mkpm Nothing (Just False)
noRookie = mkpm (Just 3) Nothing
mkRookie = mkpm (Just 3) (Just True)
mkNormal = mkpm (Just 3) (Just False)
joe = newPlayer 2 "Joe" "centre"
rookie = bob True
normal = bob False
bob rf = newPlayer 3 "Bob" "defense" & pRookie .~ rf
mkpm n rf = CreatePlayer $ newCreatePlayerState
& cpsNumber .~ n
& cpsName .~ "Bob"
& cpsPosition .~ "defense"
& cpsRookieFlag .~ rf
addGoalieSpec :: Spec addGoalieSpec :: Spec
addGoalieSpec = describe "addGoalie" $ do addGoalieSpec = describe "addGoalie" $ do