aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2018-02-17 22:41:00 -0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2018-02-17 22:41:00 -0200
commit64773838cb5c177994a7d86b557ea464fa06dcd2 (patch)
treebf11003fc2bd02b8dc9e534b35a8209ac4f8eabb
parent2198d8990da4535b6d81cf7008b85e5c14c3e0f3 (diff)
downloadqueue-api-64773838cb5c177994a7d86b557ea464fa06dcd2.tar.gz
queue-api-64773838cb5c177994a7d86b557ea464fa06dcd2.tar.bz2
queue-api-64773838cb5c177994a7d86b557ea464fa06dcd2.zip
Adds test for service.clj
-rw-r--r--project.clj3
-rw-r--r--src/clj/queue_api/db/core.clj47
-rw-r--r--src/clj/queue_api/routes/services.clj4
-rw-r--r--test/clj/queue_api/test/handler.clj42
4 files changed, 80 insertions, 16 deletions
diff --git a/project.clj b/project.clj
index 3c2289c..e9738db 100644
--- a/project.clj
+++ b/project.clj
@@ -30,7 +30,8 @@
:main ^:skip-aot queue-api.core
:plugins [[lein-immutant "2.1.0"]
- [lein-kibit "0.1.2"]]
+ [lein-kibit "0.1.2"]
+ [lein-cloverage "1.0.10"]]
:profiles
{:uberjar {:omit-source true
diff --git a/src/clj/queue_api/db/core.clj b/src/clj/queue_api/db/core.clj
index 2d32736..fa3db41 100644
--- a/src/clj/queue_api/db/core.clj
+++ b/src/clj/queue_api/db/core.clj
@@ -1,20 +1,51 @@
-(ns queue-api.db.core)
+(ns queue-api.db.core
+ (:require [datascript.core :as d]
+ [mount.core :as mount]))
+(def schema {:agent/id {:db/unique :db.unique/identity}
+ :agent/primary-skillset {:db/cardinality :db.cardinality/many}
+ :agent/secondary-skillset {:db/cardinality :db.cardinality/many}
+ :agent/jobs {:db.valueType :db.type/ref}
+ :job/id {:db/unique :db.unique/identity}
+ :job/agent {:db.valueType :db.type/ref}})
+
+(mount/defstate conn
+ :start (d/create-conn schema))
(defn add-agent [{:keys [id name primary-skillset secondary-skillset]}]
- (println (str "Dummy " name)))
+ (d/transact! queue-api.db.core/conn [{:agent/id id
+ :agent/name name
+ :agent/primary-skillset primary-skillset
+ :agent/secondary-skillset secondary-skillset}]))
(defn add-job [{:keys [id type urgent]}]
- (println (str "Dummy " type)))
+ (d/transact! queue-api.db.core/conn [{:job/id id
+ :job/type type
+ :job/urgent urgent
+ :job/status :unassigned}]))
(defn request-job [id]
{:job_request {:job_id "Dummy" :agent_id "Dummy"}})
(defn get-agent [id]
- [{:type "reward_question" :jobs 2}
- {:type "bills_question" :jobs 3}])
+ [{:type "Dummy"
+ :jobs -2}])
+
+(defn q-agent [id]
+ (d/q '[:find ?type :in $ ?id
+ :where
+ [?e :agent/id ?id]
+ [?x :job/type ?type]
+ [?x :job/agent ?e]]))
+
+(defn q-status [s]
+ (d/q '[:find ?id :in $ ?status
+ :where
+ [?e :job/status ?status]
+ [?e :job/id ?id]]
+ @conn s))
(defn get-queue []
- {:completed ["1" "2" "3"]
- :in_process["2" "3" "4"]
- :waiting ["2" "5" "6"]}) \ No newline at end of file
+ {:completed (map #(first %) (q-status :completed))
+ :processing (map #(first %) (q-status :processing))
+ :unassigned (map #(first %) (q-status :unassigned))}) \ No newline at end of file
diff --git a/src/clj/queue_api/routes/services.clj b/src/clj/queue_api/routes/services.clj
index 326ee68..0e94c18 100644
--- a/src/clj/queue_api/routes/services.clj
+++ b/src/clj/queue_api/routes/services.clj
@@ -44,8 +44,8 @@
(context "/queue" []
(GET "/" []
:return {:completed [String]
- :in_process[String]
- :waiting [String]}
+ :processing[String]
+ :unassigned [String]}
:summary "Get a summary of an agent"
(ok (db/get-queue)))))
diff --git a/test/clj/queue_api/test/handler.clj b/test/clj/queue_api/test/handler.clj
index 1aceb3c..aa0dfa1 100644
--- a/test/clj/queue_api/test/handler.clj
+++ b/test/clj/queue_api/test/handler.clj
@@ -8,14 +8,46 @@
:once
(fn [f]
(mount/start #'queue-api.config/env
- #'queue-api.handler/app)
+ #'queue-api.handler/app
+ #'queue-api.db.core/conn)
+
(f)))
-(deftest test-app
- (testing "main route"
- (let [response (app (request :get "/"))]
- (is (= 200 (:status response)))))
+(deftest agent-test
+ (testing "Agent route"
+ (let [response (-> (request :put "/agent")
+ (json-body {:id "8ab86c18-3fae-4804-bfd9-c3d6e8f66260"
+ :name "Dummy"
+ :primary_skillset ["reward_request"]
+ :secondary_skillset []})
+ app)]
+ (is (= 200 (:status response))))
+ (let [response (-> (request :post "/agent")
+ (json-body {:agent_id "8ab86c18-3fae-4804-bfd9-c3d6e8f66260"})
+ app)]
+ (is (= 200 (:status response))))))
+
+(deftest job-test
+ (testing "Job route"
+ (let [response (-> (request :put "/job")
+ (json-body {:id "895e9b31-5690-486e-b8dd-5c2345e056f6"
+ :type "bills_request"
+ :urgent false})
+ app)]
+ (is (= 200 (:status response))))
+ (let [response (-> (request :post "/job")
+ (json-body {:agent_id "8ab86c18-3fae-4804-bfd9-c3d6e8f66260"})
+ app)]
+ (is (= 200 (:status response))))))
+
+(deftest queue-test
+ (testing "Queue route"
+ (let [response (app (request :get "/queue"))]
+ (is (= 200 (:status response))))))
+
+(deftest queue "/queue")
+(deftest invalid-test
(testing "not-found route"
(let [response (app (request :get "/invalid"))]
(is (= 404 (:status response))))))