aboutsummaryrefslogtreecommitdiff
path: root/test/clj/queue_api
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2018-02-17 23:14:17 -0300
committerGabriel A. Giovanini <mail@gabrielgio.me>2018-02-17 23:14:17 -0300
commit65357035e6fee399993da80d6d26aa833979cfcf (patch)
tree86ebc6de8d6c4ff70674403deba887a5983e47e4 /test/clj/queue_api
parent64773838cb5c177994a7d86b557ea464fa06dcd2 (diff)
downloadqueue-api-65357035e6fee399993da80d6d26aa833979cfcf.tar.gz
queue-api-65357035e6fee399993da80d6d26aa833979cfcf.tar.bz2
queue-api-65357035e6fee399993da80d6d26aa833979cfcf.zip
Adds test for db.core
Diffstat (limited to 'test/clj/queue_api')
-rw-r--r--test/clj/queue_api/test/db/core_test.clj84
1 files changed, 84 insertions, 0 deletions
diff --git a/test/clj/queue_api/test/db/core_test.clj b/test/clj/queue_api/test/db/core_test.clj
new file mode 100644
index 0000000..4c30ed3
--- /dev/null
+++ b/test/clj/queue_api/test/db/core_test.clj
@@ -0,0 +1,84 @@
+(ns queue-api.test.db.core-test
+ (:require [clojure.test :refer :all]
+ [ring.mock.request :refer :all]
+ [queue-api.db.core :refer :all]
+ [datascript.core :as d]
+ [clj-time.core :as time]
+ [mount.core :as mount])
+ (:import (java.util UUID)))
+
+(def simple-schema [;;Job that will be kept :unassigned
+ {:job/id "51ab0771-f1e4-4268-868f-9029a58f6612"
+ :type "rewards-question"
+ :job/status :unassigned
+ :job/date (time/now)
+ :job/urgent false}
+ ;;Job that will be changed to processing
+ {:job/id "b201d085-91b5-4a13-9a74-7861426e9996"
+ :type "rewards-question"
+ :job/status :unassigned
+ :job/date (time/now)
+ :job/urgent true}
+ ;;Job that will be changed to completed
+ {:job/id "1e0d939d-494b-48d2-9247-b5ae207a519a"
+ :type "rewards-question"
+ :job/status :unassigned
+ :job/date (time/now)
+ :job/urgent true}
+ ;;Agent that will be linked to jobs
+ {:agent/id "644be0ce-035d-48cb-867e-8e6de2714a8d"
+ :agent/name "Dummy Derp"
+ :primary-skillset ["rewards-question" "bills-question"]
+ :secondary-skillset []}
+ ;;Change job status to :completed and link agent
+ {:job/id "1e0d939d-494b-48d2-9247-b5ae207a519a"
+ :job/status :completed
+ :job/agent [:agent/id "644be0ce-035d-48cb-867e-8e6de2714a8d"]}
+ ;;Change job status to processing and link agent
+ {:job/id "b201d085-91b5-4a13-9a74-7861426e9996"
+ :job/status :processing
+ :job/agent [:agent/id "644be0ce-035d-48cb-867e-8e6de2714a8d"]}
+ ;;Link jog with job that it is processing
+ {:agent/id "644be0ce-035d-48cb-867e-8e6de2714a8d"
+ :agent/job [:job/id "b201d085-91b5-4a13-9a74-7861426e9996"]}])
+
+(use-fixtures
+ :each
+ (fn [f]
+ (mount/stop #'queue-api.db.core/conn)
+ (mount/start #'queue-api.db.core/conn)
+ (d/transact! conn simple-schema)
+ (f)))
+
+(deftest add-agent-test
+ (testing "Test adding agent"
+ (let [tx (add-agent {:id "1d7158f8-f7a0-4ff9-9758-25efcc5aae65"
+ :name "Derpinson"
+ :primary-skillset ["rewards-question" "bills-question"]
+ :secondary-skillset []})
+ tx-data (:tx-data tx)]
+ (is (not (empty? tx-data))))))
+
+(deftest add-job-test
+ (testing "test adding job"
+ (let [tx (add-job {:id "2dc043a4-6708-4b1e-885d-e59082733e4d"
+ :type "rewards-question"
+ :urgent false})
+ tx-data (:tx-data tx)]
+ (is (not (empty? tx-data))))))
+
+(deftest q-status-test
+ (testing "test query job by status"
+ (are [left right]
+ (= left right)
+ #{["51ab0771-f1e4-4268-868f-9029a58f6612"]} (q-status :unassigned)
+ #{["1e0d939d-494b-48d2-9247-b5ae207a519a"]} (q-status :completed)
+ #{["b201d085-91b5-4a13-9a74-7861426e9996"]} (q-status :processing)
+ #{} (q-status :nil))))
+
+(deftest sum-queue-test
+ (testing "test get summary of current state of the queue"
+ (is (= {:completed ["1e0d939d-494b-48d2-9247-b5ae207a519a"]
+ :processing ["b201d085-91b5-4a13-9a74-7861426e9996"]
+ :unassigned ["51ab0771-f1e4-4268-868f-9029a58f6612"]}
+ (sum-queue))))) \ No newline at end of file