File tree Expand file tree Collapse file tree 4 files changed +64
-23
lines changed Expand file tree Collapse file tree 4 files changed +64
-23
lines changed Original file line number Diff line number Diff line change 3
3
[com.walmartlabs.lacinia :as lacinia]
4
4
[clojure.java.browse :refer [browse-url]]
5
5
[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]))
26
8
27
9
(defonce system nil )
28
10
Original file line number Diff line number Diff line change 3
3
[com.walmartlabs.lacinia.pedestal :as lp]
4
4
[io.pedestal.http :as http]))
5
5
6
- (defrecord Server [schema-provider server]
6
+ (defrecord Server [schema-provider server port ]
7
7
8
8
component /Lifecycle
9
9
(start [this]
10
10
(assoc this :server (-> schema-provider
11
11
:schema
12
- (lp/service-map {:graphiql true })
12
+ (lp/service-map {:graphiql true
13
+ :port port})
13
14
http/create-server
14
15
http/start)))
15
16
19
20
20
21
(defn new-server
21
22
[]
22
- {:server (component/using (map->Server {})
23
+ {:server (component/using (map->Server {:port 8888 })
23
24
[:schema-provider ])})
24
25
25
26
Original file line number Diff line number Diff line change
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)))
Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments