Skip to content

Commit 7783822

Browse files
committed
Setup for first test
1 parent 593e5e5 commit 7783822

File tree

4 files changed

+64
-23
lines changed

4 files changed

+64
-23
lines changed

dev-resources/user.clj

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,8 @@
33
[com.walmartlabs.lacinia :as lacinia]
44
[clojure.java.browse :refer [browse-url]]
55
[clojure-game-geek.system :as system]
6-
[clojure.walk :as walk]
7-
[com.stuartsierra.component :as component])
8-
(:import (clojure.lang IPersistentMap)))
9-
10-
(defn simplify
11-
"Converts all ordered maps nested within the map into standard hash maps, and
12-
sequences into vectors, which makes for easier constants in the tests, and eliminates ordering problems."
13-
[m]
14-
(walk/postwalk
15-
(fn [node]
16-
(cond
17-
(instance? IPersistentMap node)
18-
(into {} node)
19-
20-
(seq? node)
21-
(vec node)
22-
23-
:else
24-
node))
25-
m))
6+
[clojure-game-geek.test-utils :refer [simplify]]
7+
[com.stuartsierra.component :as component]))
268

279
(defonce system nil)
2810

src/clojure_game_geek/server.clj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
[com.walmartlabs.lacinia.pedestal :as lp]
44
[io.pedestal.http :as http]))
55

6-
(defrecord Server [schema-provider server]
6+
(defrecord Server [schema-provider server port]
77

88
component/Lifecycle
99
(start [this]
1010
(assoc this :server (-> schema-provider
1111
:schema
12-
(lp/service-map {:graphiql true})
12+
(lp/service-map {:graphiql true
13+
:port port})
1314
http/create-server
1415
http/start)))
1516

@@ -19,7 +20,7 @@
1920

2021
(defn new-server
2122
[]
22-
{:server (component/using (map->Server {})
23+
{:server (component/using (map->Server {:port 8888})
2324
[:schema-provider])})
2425

2526

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
(ns clojure-game-geek.system-tests
2+
(:require
3+
[clojure.test :refer [deftest is]]
4+
[clojure-game-geek.system :as system]
5+
[clojure-game-geek.test-utils :refer [simplify]]
6+
[com.stuartsierra.component :as component]
7+
[com.walmartlabs.lacinia :as lacinia]))
8+
9+
(defn ^:private test-system
10+
"Creates a new system suitable for testing, and ensures that
11+
the HTTP port won't conflict with a default running system."
12+
[]
13+
(-> (system/new-system)
14+
(assoc-in [:server :port] 8989)))
15+
16+
(defn ^:private q
17+
"Extracts the compiled schema and executes a query."
18+
[system query variables]
19+
(-> system
20+
(get-in [:schema-provider :schema])
21+
(lacinia/execute query variables nil)
22+
simplify))
23+
24+
(deftest can-read-board-game
25+
(let [system (component/start-system (test-system))
26+
results (q system
27+
"{ game_by_id(id: 1234) { name summary min_players max_players play_time }}"
28+
nil)]
29+
(is (= {:data {:game_by_id {:max_players 2
30+
:min_players 2
31+
:name "Zertz"
32+
:play_time nil
33+
:summary "Two player abstract with forced moves and shrinking board"}}}
34+
results))
35+
(component/stop-system system)))

test/clojure_game_geek/test_utils.clj

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(ns clojure-game-geek.test-utils
2+
(:require
3+
[clojure.walk :as walk])
4+
(:import
5+
(clojure.lang IPersistentMap)))
6+
7+
(defn simplify
8+
"Converts all ordered maps nested within the map into standard hash maps, and
9+
sequences into vectors, which makes for easier constants in the tests, and eliminates ordering problems."
10+
[m]
11+
(walk/postwalk
12+
(fn [node]
13+
(cond
14+
(instance? IPersistentMap node)
15+
(into {} node)
16+
17+
(seq? node)
18+
(vec node)
19+
20+
:else
21+
node))
22+
m))
23+

0 commit comments

Comments
 (0)