11(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]]))
811; ; todo:
912; ; [ ] test unhappy paths
1013; ; [ ] test wider range of scenarios / formats
1619
1720(defn- t-file [path]
1821 (edn/read-string (slurp (format " test-resources/%s.edn" path))))
19- #_
22+
2023(t/deftest run-handler-test
2124 (with-stubs
2225 #(do
3538 (h/run-handler (t-file " sql-example-request" ))
3639 (let [[txs query] @db]
3740 (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')" ]
3942 [:sql "
4043INSERT INTO docs RECORDS {_id: 2, col1: 'bar', col2:' baz'}" ]]
4144 txs))
@@ -152,16 +155,16 @@ INSERT INTO docs RECORDS {_id: 2, col1: 'bar', col2:' baz'};"]
152155 (mock-resp [{" _id" 1 ,
153156 " name" " An Electric Bicycle" ,
154157 " 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" }
156159 {" _id" 1 ,
157160 " name" " An Electric Bicycle" ,
158161 " 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" }
160163 {" _id" 1 ,
161164 " name" " An Electric Bicycle" ,
162165 " 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+
165168 (let [response (h/docs-run-handler {:parameters {:body (json/read-str docs-json :key-fn keyword)}})
166169 txs (drop-last @db)
167170 query (last @db)]
@@ -173,7 +176,7 @@ INSERT INTO docs RECORDS {_id: 2, col1: 'bar', col2:' baz'};"]
173176
174177 (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\" "
175178 query))
176-
179+
177180 (t/testing " docs run returns map results"
178181 (t/is (every? map? (:body response))))
179182
@@ -183,13 +186,13 @@ INSERT INTO docs RECORDS {_id: 2, col1: 'bar', col2:' baz'};"]
183186 [{" _id" 1 ,
184187 " name" " An Electric Bicycle" ,
185188 " 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" }
187190 {" _id" 1 ,
188191 " name" " An Electric Bicycle" ,
189192 " 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" }
191194 {" _id" 1 ,
192195 " name" " An Electric Bicycle" ,
193196 " 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" }]}
195198 response)))))))
0 commit comments