diff options
Diffstat (limited to 'test/clj/queue_api')
-rw-r--r-- | test/clj/queue_api/test/db/core_test.clj | 84 |
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 |