aboutsummaryrefslogtreecommitdiff
path: root/test/clj
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2018-02-20 00:04:08 -0300
committerGabriel A. Giovanini <mail@gabrielgio.me>2018-02-20 00:04:08 -0300
commitd1c15fe5fa8d5aac6a7ca056e79ca8872971a9d9 (patch)
tree86f0b7c3d3efe68c6ec2dde770487d3fe2fe18ef /test/clj
parent8e06fdb6f18e8cc63a5d501e68a175685fb808b5 (diff)
downloadqueue-api-d1c15fe5fa8d5aac6a7ca056e79ca8872971a9d9.tar.gz
queue-api-d1c15fe5fa8d5aac6a7ca056e79ca8872971a9d9.tar.bz2
queue-api-d1c15fe5fa8d5aac6a7ca056e79ca8872971a9d9.zip
Even more test
Diffstat (limited to 'test/clj')
-rw-r--r--test/clj/queue_api/test/db/core_test.clj224
1 files changed, 149 insertions, 75 deletions
diff --git a/test/clj/queue_api/test/db/core_test.clj b/test/clj/queue_api/test/db/core_test.clj
index d64b550..3909c31 100644
--- a/test/clj/queue_api/test/db/core_test.clj
+++ b/test/clj/queue_api/test/db/core_test.clj
@@ -6,68 +6,99 @@
[clj-time.core :as time]
[mount.core :as mount]))
-(def simple-schema [;;Job that will be kept :unassigned
- {:job/id "51ab0771-f1e4-4268-868f-9029a58f6612"
- :job/type "rewards-question"
- :job/status :unassigned
- :job/date (time/date-time 2018 2 18 1 0 2)
- :job/urgent false}
- {:job/id "96cf6f11-591d-4cde-9ab0-56e371acb6d2"
- :job/type "rewards-question"
- :job/status :unassigned
- :job/date (time/date-time 2018 2 18 1 0 1)
- :job/urgent false}
- ;;Job that will be changed to processing
- {:job/id "b201d085-91b5-4a13-9a74-7861426e9996"
- :job/type "purchases-question"
- :job/status :unassigned
- :job/date (time/date-time 2018 2 18 1 0 4)
- :job/urgent true}
- ;;Job that will be changed to completed
- {:job/id "1e0d939d-494b-48d2-9247-b5ae207a519a"
- :job/type "bills-question"
- :job/status :unassigned
- :job/date (time/date-time 2018 2 18 1 0 3)
- :job/urgent false}
- {:job/id "aa327540-4e24-47f4-9e9c-81cdd5195934"
- :job/type "bills-question"
- :job/status :unassigned
- :job/date (time/date-time 2018 2 18 1 0 6)
- :job/urgent true}
- {:job/id "3cdc52fe-b538-40a6-a9d7-92fa840c2c4b"
- :job/type "purchases-question"
- :job/status :unassigned
- :job/date (time/date-time 2018 2 18 1 0 8)
- :job/urgent true}
- ;;Agent that will be linked to jobs
- {:agent/id "644be0ce-035d-48cb-867e-8e6de2714a8d"
- :agent/name "Dummy Derp"
- :agent/primary-skillset ["rewards-question" "bills-question"]
- :agent/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"]}
- {:job/id "aa327540-4e24-47f4-9e9c-81cdd5195934"
- :job/status :completed
- :job/agent [:agent/id "644be0ce-035d-48cb-867e-8e6de2714a8d"]}
- {:job/id "3cdc52fe-b538-40a6-a9d7-92fa840c2c4b"
- :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 agent with job that it is being processed
- {:agent/id "644be0ce-035d-48cb-867e-8e6de2714a8d"
- :agent/job [:job/id "b201d085-91b5-4a13-9a74-7861426e9996"]}])
+(def base-schema [;;Job that will be kept :unassigned
+ {:job/id "dfa7744f-8d61-4d37-885f-dbef2d4df13b"
+ :job/type "rewards-question"
+ :job/status :unassigned
+ :job/date (time/date-time 2018 2 19 1 0 1)
+ :job/urgent false}
+ {:job/id "c471f9e0-fbbd-461d-adb0-7466c2d9830f"
+ :job/type "purchases-question"
+ :job/status :unassigned
+ :job/date (time/date-time 2018 2 19 1 0 0)
+ :job/urgent false}
+ {:job/id "51ab0771-f1e4-4268-868f-9029a58f6612"
+ :job/type "rewards-question"
+ :job/status :unassigned
+ :job/date (time/date-time 2018 2 18 1 0 2)
+ :job/urgent true}
+ {:job/id "96cf6f11-591d-4cde-9ab0-56e371acb6d2"
+ :job/type "rewards-question"
+ :job/status :unassigned
+ :job/date (time/date-time 2018 2 18 1 0 1)
+ :job/urgent false}
+ {:job/id "6e90db58-7a6d-46e2-a02a-e33dc82e6e33"
+ :job/type "purchases-question"
+ :job/status :unassigned
+ :job/date (time/date-time 2018 2 18 1 0 0)
+ :job/urgent true}
+ {:job/id "f90e149e-fa51-4212-a6bf-8cf81c78d28c"
+ :job/type "purchases-question"
+ :job/status :unassigned
+ :job/date (time/date-time 2018 2 17 1 0 0)
+ :job/urgent false}
+ ;;Job that will be changed to processing
+ {:job/id "b201d085-91b5-4a13-9a74-7861426e9996"
+ :job/type "purchases-question"
+ :job/status :unassigned
+ :job/date (time/date-time 2018 2 18 1 0 4)
+ :job/urgent true}
+ ;;Job that will be changed to completed
+ {:job/id "1e0d939d-494b-48d2-9247-b5ae207a519a"
+ :job/type "bills-question"
+ :job/status :unassigned
+ :job/date (time/date-time 2018 2 18 1 0 3)
+ :job/urgent false}
+ {:job/id "aa327540-4e24-47f4-9e9c-81cdd5195934"
+ :job/type "bills-question"
+ :job/status :unassigned
+ :job/date (time/date-time 2018 2 18 1 0 6)
+ :job/urgent true}
+ {:job/id "3cdc52fe-b538-40a6-a9d7-92fa840c2c4b"
+ :job/type "purchases-question"
+ :job/status :unassigned
+ :job/date (time/date-time 2018 2 18 1 0 8)
+ :job/urgent true}
+ ;;Agents
+ {:agent/id "644be0ce-035d-48cb-867e-8e6de2714a8d"
+ :agent/name "Dummy Derp"
+ :agent/primary-skillset ["rewards-question" "bills-question"]
+ :agent/secondary-skillset []}
+ {:agent/id "ff02347a-1b2d-440c-a2a1-7a593dba564e"
+ :agent/name "Derpinson"
+ :agent/primary-skillset ["nil-question"]
+ :agent/secondary-skillset ["purchases-question"]}
+ ;;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"]}
+ {:job/id "aa327540-4e24-47f4-9e9c-81cdd5195934"
+ :job/status :completed
+ :job/agent [:agent/id "644be0ce-035d-48cb-867e-8e6de2714a8d"]}
+ {:job/id "3cdc52fe-b538-40a6-a9d7-92fa840c2c4b"
+ :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 agent with job that it is being processed
+ {:agent/id "644be0ce-035d-48cb-867e-8e6de2714a8d"
+ :agent/job [:job/id "b201d085-91b5-4a13-9a74-7861426e9996"]}])
+
+(def complete-schema [{:job/id "51ab0771-f1e4-4268-868f-9029a58f6612"
+ :job/status :completed
+ :job/agent [:agent/id "644be0ce-035d-48cb-867e-8e6de2714a8d"]}
+ {:job/id "6e90db58-7a6d-46e2-a02a-e33dc82e6e33"
+ :job/status :completed
+ :job/agent [:agent/id "ff02347a-1b2d-440c-a2a1-7a593dba564e"]}])
(use-fixtures
:each
(fn [f]
(mount/stop #'queue-api.db.core/conn)
(mount/start #'queue-api.db.core/conn)
- (d/transact! conn simple-schema)
+ (d/transact! conn base-schema)
(f)))
(defn agent [id]
@@ -97,8 +128,12 @@
(testing "test query job by status"
(are [left right]
(= left right)
- #{["51ab0771-f1e4-4268-868f-9029a58f6612"]
- ["96cf6f11-591d-4cde-9ab0-56e371acb6d2"]} (q-status :unassigned)
+ #{["96cf6f11-591d-4cde-9ab0-56e371acb6d2"]
+ ["51ab0771-f1e4-4268-868f-9029a58f6612"]
+ ["f90e149e-fa51-4212-a6bf-8cf81c78d28c"]
+ ["dfa7744f-8d61-4d37-885f-dbef2d4df13b"]
+ ["c471f9e0-fbbd-461d-adb0-7466c2d9830f"]
+ ["6e90db58-7a6d-46e2-a02a-e33dc82e6e33"]} (q-status :unassigned)
#{["1e0d939d-494b-48d2-9247-b5ae207a519a"]
["aa327540-4e24-47f4-9e9c-81cdd5195934"]
["3cdc52fe-b538-40a6-a9d7-92fa840c2c4b"]} (q-status :completed)
@@ -112,13 +147,17 @@
"3cdc52fe-b538-40a6-a9d7-92fa840c2c4b"],
:processing ["b201d085-91b5-4a13-9a74-7861426e9996"],
:unassigned ["96cf6f11-591d-4cde-9ab0-56e371acb6d2"
- "51ab0771-f1e4-4268-868f-9029a58f6612"]}
+ "f90e149e-fa51-4212-a6bf-8cf81c78d28c"
+ "dfa7744f-8d61-4d37-885f-dbef2d4df13b"
+ "51ab0771-f1e4-4268-868f-9029a58f6612"
+ "c471f9e0-fbbd-461d-adb0-7466c2d9830f"
+ "6e90db58-7a6d-46e2-a02a-e33dc82e6e33"]}
(sum-queue)))))
(deftest q-job-test
(testing "test query job"
(is (= [(job "96cf6f11-591d-4cde-9ab0-56e371acb6d2")
- (job "51ab0771-f1e4-4268-868f-9029a58f6612")]
+ (job "dfa7744f-8d61-4d37-885f-dbef2d4df13b")]
(q-job false :unassigned "rewards-question")))
(is (= [(job "b201d085-91b5-4a13-9a74-7861426e9996")]
(q-job true :processing "purchases-question")))
@@ -142,15 +181,10 @@
(deftest sum-agent-test
(testing "Test sum-agent"
- (is (= [{:type "bills-question", :jobs 2} {:type "purchases-question", :jobs 1}]
+ (is (= {"bills-question" 2
+ "purchases-question" 1}
(sum-agent "644be0ce-035d-48cb-867e-8e6de2714a8d")))
- (is (= [] (sum-agent "00000000-0000-0000-0000-000000000000")))))
-
-;;TODO:adicionar mais testes
-(deftest request-job-test
- (testing "test query for skillset"
- (is (= (job "96cf6f11-591d-4cde-9ab0-56e371acb6d2")
- (request-job "644be0ce-035d-48cb-867e-8e6de2714a8d")))))
+ (is (= {} (sum-agent "00000000-0000-0000-0000-000000000000")))))
(deftest bind-agent-test
(testing "Test bind agent"
@@ -179,11 +213,51 @@
:agent/job :job/status))))))
(deftest start-job-test
- (testing "Test start a new job"
- (let [_ (start-job "644be0ce-035d-48cb-867e-8e6de2714a8d" "96cf6f11-591d-4cde-9ab0-56e371acb6d2")
- a (agent "644be0ce-035d-48cb-867e-8e6de2714a8d")]
- (are [left right]
- (= left right)
- :processing (-> a :agent/job :job/status)
- "96cf6f11-591d-4cde-9ab0-56e371acb6d2" (-> a :agent/job :job/id)))))
+ (testing "Test start a new job"
+ (let [_ (start-job "644be0ce-035d-48cb-867e-8e6de2714a8d" "96cf6f11-591d-4cde-9ab0-56e371acb6d2")
+ a (agent "644be0ce-035d-48cb-867e-8e6de2714a8d")]
+ (are [left right]
+ (= left right)
+ :processing (-> a :agent/job :job/status)
+ "96cf6f11-591d-4cde-9ab0-56e371acb6d2" (-> a :agent/job :job/id)))))
+
+(deftest request-job-test
+ (testing "test query for skillset"
+ ;;primary-skillset urgent
+ (is (= (job "51ab0771-f1e4-4268-868f-9029a58f6612")
+ (request-job "644be0ce-035d-48cb-867e-8e6de2714a8d")))
+ ;;secondary-skillset urgent
+ (is (= (job "6e90db58-7a6d-46e2-a02a-e33dc82e6e33")
+ (request-job "ff02347a-1b2d-440c-a2a1-7a593dba564e")))
+ (d/transact! conn complete-schema)
+ ;;primary-skillset not urgent
+ (is (= (job "96cf6f11-591d-4cde-9ab0-56e371acb6d2")
+ (request-job "644be0ce-035d-48cb-867e-8e6de2714a8d")))
+ ;;secondary-skillset not urgent
+ (is (= (job "f90e149e-fa51-4212-a6bf-8cf81c78d28c")
+ (request-job "ff02347a-1b2d-440c-a2a1-7a593dba564e")))))
+
+(deftest dequeue-job-test
+ (testing "Test Dummy Derp dequeuing process"
+ (are [left right]
+ (= left right)
+ ;;first iteration
+ "51ab0771-f1e4-4268-868f-9029a58f6612" (dequeue-job "644be0ce-035d-48cb-867e-8e6de2714a8d")
+ :completed (:job/status (job "b201d085-91b5-4a13-9a74-7861426e9996"))
+ :processing (:job/status (job "51ab0771-f1e4-4268-868f-9029a58f6612"))
+ (job "51ab0771-f1e4-4268-868f-9029a58f6612") (:agent/job (agent "644be0ce-035d-48cb-867e-8e6de2714a8d"))
+ ;;second iteration
+ "96cf6f11-591d-4cde-9ab0-56e371acb6d2" (dequeue-job "644be0ce-035d-48cb-867e-8e6de2714a8d")
+ :completed (:job/status (job "51ab0771-f1e4-4268-868f-9029a58f6612"))
+ :processing (:job/status (job "96cf6f11-591d-4cde-9ab0-56e371acb6d2"))
+ (job "96cf6f11-591d-4cde-9ab0-56e371acb6d2") (:agent/job (agent "644be0ce-035d-48cb-867e-8e6de2714a8d"))
+ ;; third iteration
+ "dfa7744f-8d61-4d37-885f-dbef2d4df13b" (dequeue-job "644be0ce-035d-48cb-867e-8e6de2714a8d")
+ :completed (:job/status (job "96cf6f11-591d-4cde-9ab0-56e371acb6d2"))
+ :processing (:job/status (job "dfa7744f-8d61-4d37-885f-dbef2d4df13b"))
+ (job "dfa7744f-8d61-4d37-885f-dbef2d4df13b") (:agent/job (agent "644be0ce-035d-48cb-867e-8e6de2714a8d"))
+ ;; last empty iteration
+ nil (dequeue-job "644be0ce-035d-48cb-867e-8e6de2714a8d")
+ :completed (:job/status (job "dfa7744f-8d61-4d37-885f-dbef2d4df13b")))))
+