Skip to content
This repository has been archived by the owner on Oct 2, 2018. It is now read-only.

Commit

Permalink
api inherits errors (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
Masclins authored Sep 3, 2018
1 parent d383333 commit c8cd119
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions backend/src/api/base.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
[game-id player-id card-id row-id & target]
(let [game-state (persistence/fetch-game game-id)]
(if (= (:status (get-game game-id player-id)) messages/play)
(do
(persistence/save-game (play-card/play-card game-state player-id card-id row-id (first target)))
(get-game game-id player-id))
(let [new-game-state (play-card/play-card game-state player-id card-id row-id (first target))]
(if (contains? new-game-state :error)
new-game-state
(do
(persistence/save-game new-game-state)
(get-game game-id player-id))))
{:error messages/out-of-turn})))

(defn ^:private create-empty-game
Expand Down
3 changes: 3 additions & 0 deletions backend/test/api/base_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
p1 (:player-id game)
p2 (:player-id (base/add-player game-id))]

(expect {:error messages/no-row}
(base/play-card-as-player game-id p1 1 99))

(expect messages/wait
(:status (base/play-card-as-player game-id p1 1 0)))

Expand Down

0 comments on commit c8cd119

Please sign in to comment.