Added Luminus app skeleton; added ADL.
This commit is contained in:
parent
8a923c1b33
commit
f3c0e728a4
52 changed files with 1761 additions and 0 deletions
38
test/clj/pastoralist/test/db/core.clj
Normal file
38
test/clj/pastoralist/test/db/core.clj
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
(ns pastoralist.test.db.core
|
||||
(:require
|
||||
[pastoralist.db.core :refer [*db*] :as db]
|
||||
[java-time.pre-java8]
|
||||
[luminus-migrations.core :as migrations]
|
||||
[clojure.test :refer :all]
|
||||
[clojure.java.jdbc :as jdbc]
|
||||
[pastoralist.config :refer [env]]
|
||||
[mount.core :as mount]))
|
||||
|
||||
(use-fixtures
|
||||
:once
|
||||
(fn [f]
|
||||
(mount/start
|
||||
#'pastoralist.config/env
|
||||
#'pastoralist.db.core/*db*)
|
||||
(migrations/migrate ["migrate"] (select-keys env [:database-url]))
|
||||
(f)))
|
||||
|
||||
(deftest test-users
|
||||
(jdbc/with-db-transaction [t-conn *db*]
|
||||
(jdbc/db-set-rollback-only! t-conn)
|
||||
(is (= 1 (db/create-user!
|
||||
t-conn
|
||||
{:id "1"
|
||||
:first_name "Sam"
|
||||
:last_name "Smith"
|
||||
:email "sam.smith@example.com"
|
||||
:pass "pass"})))
|
||||
(is (= {:id "1"
|
||||
:first_name "Sam"
|
||||
:last_name "Smith"
|
||||
:email "sam.smith@example.com"
|
||||
:pass "pass"
|
||||
:admin nil
|
||||
:last_login nil
|
||||
:is_active nil}
|
||||
(db/get-user t-conn {:id "1"})))))
|
||||
52
test/clj/pastoralist/test/handler.clj
Normal file
52
test/clj/pastoralist/test/handler.clj
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
(ns pastoralist.test.handler
|
||||
(:require
|
||||
[clojure.test :refer :all]
|
||||
[ring.mock.request :refer :all]
|
||||
[pastoralist.handler :refer :all]
|
||||
[pastoralist.middleware.formats :as formats]
|
||||
[muuntaja.core :as m]
|
||||
[mount.core :as mount]))
|
||||
|
||||
(defn parse-json [body]
|
||||
(m/decode formats/instance "application/json" body))
|
||||
|
||||
(use-fixtures
|
||||
:once
|
||||
(fn [f]
|
||||
(mount/start #'pastoralist.config/env
|
||||
#'pastoralist.handler/app-routes)
|
||||
(f)))
|
||||
|
||||
(deftest test-app
|
||||
(testing "main route"
|
||||
(let [response ((app) (request :get "/"))]
|
||||
(is (= 200 (:status response)))))
|
||||
|
||||
(testing "not-found route"
|
||||
(let [response ((app) (request :get "/invalid"))]
|
||||
(is (= 404 (:status response)))))
|
||||
(testing "services"
|
||||
|
||||
(testing "success"
|
||||
(let [response ((app) (-> (request :post "/api/math/plus")
|
||||
(json-body {:x 10, :y 6})))]
|
||||
(is (= 200 (:status response)))
|
||||
(is (= {:total 16} (m/decode-response-body response)))))
|
||||
|
||||
(testing "parameter coercion error"
|
||||
(let [response ((app) (-> (request :post "/api/math/plus")
|
||||
(json-body {:x 10, :y "invalid"})))]
|
||||
(is (= 400 (:status response)))))
|
||||
|
||||
(testing "response coercion error"
|
||||
(let [response ((app) (-> (request :post "/api/math/plus")
|
||||
(json-body {:x -10, :y 6})))]
|
||||
(is (= 500 (:status response)))))
|
||||
|
||||
(testing "content negotiation"
|
||||
(let [response ((app) (-> (request :post "/api/math/plus")
|
||||
(body (pr-str {:x 10, :y 6}))
|
||||
(content-type "application/edn")
|
||||
(header "accept" "application/transit+json")))]
|
||||
(is (= 200 (:status response)))
|
||||
(is (= {:total 16} (m/decode-response-body response)))))))
|
||||
9
test/cljs/pastoralist/core_test.cljs
Normal file
9
test/cljs/pastoralist/core_test.cljs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(ns pastoralist.core-test
|
||||
(:require [cljs.test :refer-macros [is are deftest testing use-fixtures]]
|
||||
[pjstadig.humane-test-output]
|
||||
[reagent.core :as reagent :refer [atom]]
|
||||
[pastoralist.core :as rc]))
|
||||
|
||||
(deftest test-home
|
||||
(is (= true true)))
|
||||
|
||||
6
test/cljs/pastoralist/doo_runner.cljs
Normal file
6
test/cljs/pastoralist/doo_runner.cljs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(ns pastoralist.doo-runner
|
||||
(:require [doo.runner :refer-macros [doo-tests]]
|
||||
[pastoralist.core-test]))
|
||||
|
||||
(doo-tests 'pastoralist.core-test)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue