Skip to content

Commit

Permalink
sample tests to prove how the backend should behave
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaCrotti committed Feb 19, 2019
1 parent a4f4400 commit 1ac1586
Showing 1 changed file with 52 additions and 22 deletions.
74 changes: 52 additions & 22 deletions test/clj/byf/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,38 @@

[p1-id p2-id]))

(defn- invert-game
[game]
(-> game
(assoc :p1 (:p2 game))
(assoc :p2 (:p1 game))
(assoc :p1_points (:p2_points game))
(assoc :p2_points (:p1_points game))
(assoc :p1_using (:p2_using game))
(assoc :p2_using (:p1_using game))))

(deftest store-results-invariants-test
(testing "Can't add two equal games"
(let [[p1-id p2-id] (store-users!)
game1 {:p1 (:player-id p1-id)
:p2 (:player-id p2-id)
:league_id sample-league-id
:p1_using "RM"
:p2_using "Juv"
:p1_points 3
:p2_points 0
:played_at "2018-08-29+01:0021:50:32"}
game2 (invert-game game1)
game3 (assoc game2 :force true)]

(let [first-call (write-api-call "/add-game" game1)
second-call (write-api-call "/add-game" game2)
third-call (write-api-call "/add-game" game3)]

(is (= 201 (:status first-call)))
(is (= 400 (:status second-call)))
(is (= 201 (:status third-call)))))))

(deftest store-results-test
(testing "Should be able to store results"
(let [[p1-id p2-id] (store-users!)
Expand All @@ -80,28 +112,26 @@
:p2_using "Juv"
:p1_points 3
:p2_points 0
:played_at "2018-08-29+01:0021:50:32"}

_ (write-api-call "/add-game" sample)
games (read-api-call "/api/games" {:league_id sample-league-id})

desired {"p1" (str (:player-id p1-id))
"p1_points" 3,
"p1_using" "RM",
"p2" (str (:player-id p2-id)),
"p2_points" 0,
"p2_using" "Juv"
"played_at" "2018-08-29T20:50:00Z"}]

(is (= 200 (:status games)))

(is (= desired
(select-keys
(first (json/read-str (:body games)))
["p1_points" "p2_points"
"p1" "p2"
"p1_using" "p2_using"
"played_at"]))))))
:played_at "2018-08-29+01:0021:50:32"}]
(write-api-call "/add-game" sample)
(let [games (read-api-call "/api/games" {:league_id sample-league-id})
desired {"p1" (str (:player-id p1-id))
"p1_points" 3,
"p1_using" "RM",
"p2" (str (:player-id p2-id)),
"p2_points" 0,
"p2_using" "Juv"
"played_at" "2018-08-29T20:50:00Z"}]

(is (= 200 (:status games)))

(is (= desired
(select-keys
(first (json/read-str (:body games)))
["p1_points" "p2_points"
"p1" "p2"
"p1_using" "p2_using"
"played_at"])))))))

(deftest get-players-test
(testing "Fetching all the existing players"
Expand Down

0 comments on commit 1ac1586

Please sign in to comment.