1
1
(ns xt-play.handler-test
2
- (:require [clojure.edn :as edn]
3
- [clojure.string :as str]
4
- [clojure.test :as t]
5
- [clojure.data.json :as json]
6
- [xt-play.handler :as h]
7
- [xt-play.xtdb-stubs :refer [with-stubs db clean-db mock-resp reset-resp]]))
2
+ (:require
3
+ [clojure.data.json :as json]
4
+ [clojure.edn :as edn]
5
+ [clojure.string :as str]
6
+ [clojure.test :as t]
7
+ [xt-play.handler :as h]
8
+ #_:clj-kondo/ignore
9
+ [time-literals.data-readers :as time]
10
+ [xt-play.xtdb-stubs :refer [clean-db db mock-resp reset-resp with-stubs]]))
8
11
; ; todo:
9
12
; ; [ ] test unhappy paths
10
13
; ; [ ] test wider range of scenarios / formats
16
19
17
20
(defn- t-file [path]
18
21
(edn/read-string (slurp (format " test-resources/%s.edn" path))))
19
- #_
22
+
20
23
(t/deftest run-handler-test
21
24
(with-stubs
22
25
#(do
35
38
(h/run-handler (t-file " sql-example-request" ))
36
39
(let [[txs query] @db]
37
40
(t/is (= 2 (count @db)))
38
- (t/is (= [[:sql " INSERT INTO docs (_id, col1) VALUES (1, 'foo')" ]
41
+ (t/is (= [[:sql " INSERT INTO docs (_id, col1) VALUES (1, 'foo')" ]
39
42
[:sql "
40
43
INSERT INTO docs RECORDS {_id: 2, col1: 'bar', col2:' baz'}" ]]
41
44
txs))
@@ -152,16 +155,16 @@ INSERT INTO docs RECORDS {_id: 2, col1: 'bar', col2:' baz'};"]
152
155
(mock-resp [{" _id" 1 ,
153
156
" name" " An Electric Bicycle" ,
154
157
" price" 350 ,
155
- " _valid_from" #time/zoned-date-time " 2024-01-10T00:00Z[UTC] " }
158
+ " _valid_from" #time/zoned-date-time " 2024-01-10T00:00Z" }
156
159
{" _id" 1 ,
157
160
" name" " An Electric Bicycle" ,
158
161
" price" 405 ,
159
- " _valid_from" #time/zoned-date-time " 2024-01-05T00:00Z[UTC] " }
162
+ " _valid_from" #time/zoned-date-time " 2024-01-05T00:00Z" }
160
163
{" _id" 1 ,
161
164
" name" " An Electric Bicycle" ,
162
165
" price" 400 ,
163
- " _valid_from" #time/zoned-date-time " 2024-01-01T00:00Z[UTC] " }])
164
-
166
+ " _valid_from" #time/zoned-date-time " 2024-01-01T00:00Z" }])
167
+
165
168
(let [response (h/docs-run-handler {:parameters {:body (json/read-str docs-json :key-fn keyword)}})
166
169
txs (drop-last @db)
167
170
query (last @db)]
@@ -173,7 +176,7 @@ INSERT INTO docs RECORDS {_id: 2, col1: 'bar', col2:' baz'};"]
173
176
174
177
(t/is (= " SELECT *, _valid_from\n FROM product\n FOR VALID_TIME ALL -- i.e. \" show me all versions\"\n FOR SYSTEM_TIME AS OF DATE '2024-01-31' -- \" ...as observed at month end\" "
175
178
query))
176
-
179
+
177
180
(t/testing " docs run returns map results"
178
181
(t/is (every? map? (:body response))))
179
182
@@ -183,13 +186,13 @@ INSERT INTO docs RECORDS {_id: 2, col1: 'bar', col2:' baz'};"]
183
186
[{" _id" 1 ,
184
187
" name" " An Electric Bicycle" ,
185
188
" price" 350 ,
186
- " _valid_from" #time/zoned-date-time " 2024-01-10T00:00Z[UTC] " }
189
+ " _valid_from" #time/zoned-date-time " 2024-01-10T00:00Z" }
187
190
{" _id" 1 ,
188
191
" name" " An Electric Bicycle" ,
189
192
" price" 405 ,
190
- " _valid_from" #time/zoned-date-time " 2024-01-05T00:00Z[UTC] " }
193
+ " _valid_from" #time/zoned-date-time " 2024-01-05T00:00Z" }
191
194
{" _id" 1 ,
192
195
" name" " An Electric Bicycle" ,
193
196
" price" 400 ,
194
- " _valid_from" #time/zoned-date-time " 2024-01-01T00:00Z[UTC] " }]}
197
+ " _valid_from" #time/zoned-date-time " 2024-01-01T00:00Z" }]}
195
198
response)))))))
0 commit comments