|
19 | 19 | :database-name "test"
|
20 | 20 | :migrations ["classpath:migrations/mysqltest"]})
|
21 | 21 |
|
| 22 | +(def h2-database {:hikaricp-config "h2test.properties" |
| 23 | + :driver :h2 |
| 24 | + :database-name "test" |
| 25 | + :migrations ["classpath:migrations/h2test"]}) |
| 26 | + |
22 | 27 | (def test-schema {::core/graph->sql {:person/name :member/name
|
23 | 28 | :person/account :member/account_id
|
24 | 29 | :settings/auto-open? :settings/auto_open
|
|
42 | 47 | :driver :mysql
|
43 | 48 | :database-name "test")) ; needed for create/drop in mysql...there is no drop schema
|
44 | 49 |
|
| 50 | +(def h2-schema |
| 51 | + (assoc test-schema :driver :h2)) |
| 52 | + |
45 | 53 | (specification "Database Component" :integration
|
46 | 54 | (behavior "Can create a functional database pool from HikariCP properties and Flyway migrations."
|
47 | 55 | (with-database [db test-database]
|
|
225 | 233 | (core/seed-row :todo_list_item {:id :item-2-1 :label "B.1" :parent_item_id :item-2})
|
226 | 234 | (core/seed-row :todo_list_item {:id :item-2-2 :label "B.2" :parent_item_id :item-2})])
|
227 | 235 |
|
228 |
| -(specification "Integration Tests for Graph Queries (PostgreSQL)" :integration :focused |
| 236 | +(specification "Integration Tests for Graph Queries (PostgreSQL)" :integration |
229 | 237 | (with-database [db test-database]
|
230 | 238 | (let [{:keys [id/joe id/mary id/invoice-1 id/invoice-2 id/gadget id/widget id/spanner id/sam id/sally id/judy id/joe-settings
|
231 | 239 | list-1 item-1 item-1-1 item-1-1-1 item-2 item-2-1 item-2-2]} (core/seed! db test-schema test-rows)
|
|
303 | 311 | :account/members [{:db/id sam :person/name "Sam"}
|
304 | 312 | {:db/id sally :person/name "Sally"}]
|
305 | 313 | :account/settings {:db/id joe-settings :settings/auto-open? true}}
|
306 |
| - {:db/id mary |
307 |
| - :account/name "Mary" |
308 |
| - :account/members [{:db/id judy :person/name "Judy"}]}] |
| 314 | + {:db/id mary |
| 315 | + :account/name "Mary" |
| 316 | + :account/members [{:db/id judy :person/name "Judy"}]}] |
309 | 317 | query-3 [:db/id :item/name {:item/invoices [:db/id {:invoice/account [:db/id :account/name]}]}]
|
310 | 318 | expected-result-3 [{:db/id gadget :item/name "gadget"
|
311 | 319 | :item/invoices [{:db/id invoice-1 :invoice/account {:db/id joe :account/name "Joe"}}
|
|
326 | 334 | "many-to-many (reverse)"
|
327 | 335 | (core/run-query db mysql-schema :account/id query-3 (sorted-set gadget)) => expected-result-3))))
|
328 | 336 |
|
| 337 | +(specification "H2 Integration Tests" :h2 |
| 338 | + (with-database [db h2-database] |
| 339 | + (let [{:keys [id/joe id/mary id/invoice-1 id/invoice-2 id/gadget id/widget id/spanner id/sam id/sally id/judy id/joe-settings]} (core/seed! db h2-schema test-rows) |
| 340 | + query [:db/id :account/name {:account/invoices [:db/id |
| 341 | + ; TODO: data on join table |
| 342 | + ;{:invoice/invoice_items [:invoice_items/quantity]} |
| 343 | + {:invoice/items [:db/id :item/name]}]}] |
| 344 | + expected-result {:db/id joe |
| 345 | + :account/name "Joe" |
| 346 | + :account/invoices [{:db/id invoice-1 :invoice/items [{:db/id gadget :item/name "gadget"}]} |
| 347 | + {:db/id invoice-2 :invoice/items [{:db/id widget :item/name "widget"} |
| 348 | + {:db/id spanner :item/name "spanner"} |
| 349 | + {:db/id gadget :item/name "gadget"}]}]} |
| 350 | + query-2 [:db/id :account/name {:account/members [:db/id :person/name]} {:account/settings [:db/id :settings/auto-open?]}] |
| 351 | + expected-result-2 [{:db/id joe |
| 352 | + :account/name "Joe" |
| 353 | + :account/members [{:db/id sam :person/name "Sam"} |
| 354 | + {:db/id sally :person/name "Sally"}] |
| 355 | + :account/settings {:db/id joe-settings :settings/auto-open? true}} |
| 356 | + {:db/id mary |
| 357 | + :account/name "Mary" |
| 358 | + :account/members [{:db/id judy :person/name "Judy"}]}] |
| 359 | + query-3 [:db/id :item/name {:item/invoices [:db/id {:invoice/account [:db/id :account/name]}]}] |
| 360 | + expected-result-3 [{:db/id gadget :item/name "gadget" |
| 361 | + :item/invoices [{:db/id invoice-1 :invoice/account {:db/id joe :account/name "Joe"}} |
| 362 | + {:db/id invoice-2 :invoice/account {:db/id joe :account/name "Joe"}}]}] |
| 363 | + root-set #{joe} |
| 364 | + source-table :account |
| 365 | + fix-nums (fn [result] |
| 366 | + (clojure.walk/postwalk |
| 367 | + (fn [ele] |
| 368 | + (if (= java.math.BigInteger (type ele)) |
| 369 | + (long ele) |
| 370 | + ele)) result))] |
| 371 | + (assertions |
| 372 | + "many-to-many (forward)" |
| 373 | + (core/run-query db h2-schema :account/id query #{joe}) => [expected-result] |
| 374 | + "one-to-many query (forward)" |
| 375 | + (core/run-query db h2-schema :account/id query-2 (sorted-set joe mary)) => expected-result-2 |
| 376 | + "many-to-many (reverse)" |
| 377 | + (core/run-query db h2-schema :account/id query-3 (sorted-set gadget)) => expected-result-3)))) |
| 378 | + |
| 379 | + |
329 | 380 | (comment
|
330 | 381 | (do
|
331 | 382 | (require 'taoensso.timbre)
|
|
0 commit comments