Skip to content

Commit b525899

Browse files
authored
Merge pull request #1 from hlship/master
Capture recent changes to apply to real repo
2 parents e0d360f + 4388d0d commit b525899

File tree

6 files changed

+71
-29
lines changed

6 files changed

+71
-29
lines changed
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+

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

project.clj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
:url "https://github.com/walmartlabs/clojure-game-geek"
44
:license {:name "Eclipse Public License"
55
:url "http://www.eclipse.org/legal/epl-v10.html"}
6-
:dependencies [[org.clojure/clojure "1.8.0"]
7-
[org.clojure/core.async "0.3.443"]
6+
:dependencies [[org.clojure/clojure "1.9.0"]
7+
[org.clojure/core.async "0.4.474"]
88
[com.stuartsierra/component "0.3.2"]
9-
[com.walmartlabs/lacinia "0.25.0"]
10-
[com.walmartlabs/lacinia-pedestal "0.7.0"]
9+
[com.walmartlabs/lacinia "0.30.0"]
10+
[com.walmartlabs/lacinia-pedestal "0.10.0"]
1111
[alaisi/postgres.async "0.8.0"]
12-
[io.aviso/logging "0.2.0"]])
12+
[io.aviso/logging "0.3.1"]])

src/clojure_game_geek/db.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
(ns clojure-game-geek.db
22
(:require
3-
[clojure.java.io :as io]
43
[com.stuartsierra.component :as component]
54
[postgres.async :refer [open-db query! close-db!]]
65
[clojure.core.async :refer [<!!]]))
@@ -27,6 +26,8 @@
2726
{:db (map->ClojureGameGeekDb {})})
2827

2928
(defn ^:private take!
29+
"Takes a value from a channel and rethrows an exception if that is the
30+
conveyed value."
3031
[ch]
3132
(let [v (<!! ch)]
3233
(if (instance? Throwable v)

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)))

0 commit comments

Comments
 (0)