aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2018-02-19 21:33:15 -0300
committerGabriel A. Giovanini <mail@gabrielgio.me>2018-02-19 21:33:15 -0300
commit8e06fdb6f18e8cc63a5d501e68a175685fb808b5 (patch)
tree3672b85d75186191aaf06f64e415c4b13874adaa
parentff69f08e64ad890255fb0f9e957be4e00b1c404f (diff)
downloadqueue-api-8e06fdb6f18e8cc63a5d501e68a175685fb808b5.tar.gz
queue-api-8e06fdb6f18e8cc63a5d501e68a175685fb808b5.tar.bz2
queue-api-8e06fdb6f18e8cc63a5d501e68a175685fb808b5.zip
Adds more test
-rw-r--r--src/clj/queue_api/db/core.clj2
-rw-r--r--test/clj/queue_api/test/db/core_test.clj71
2 files changed, 58 insertions, 15 deletions
diff --git a/src/clj/queue_api/db/core.clj b/src/clj/queue_api/db/core.clj
index 88e6eed..f40548c 100644
--- a/src/clj/queue_api/db/core.clj
+++ b/src/clj/queue_api/db/core.clj
@@ -147,7 +147,7 @@
(bind-agent a j))))
(defn dequeue-job
- "Dequeue a job from a agent `id`"
+ "Dequeue a job to a agent `id`"
[^String id]
(let [a (d/entity @conn [:agent/id id])]
(if (not (nil? a))
diff --git a/test/clj/queue_api/test/db/core_test.clj b/test/clj/queue_api/test/db/core_test.clj
index a624319..d64b550 100644
--- a/test/clj/queue_api/test/db/core_test.clj
+++ b/test/clj/queue_api/test/db/core_test.clj
@@ -40,8 +40,8 @@
: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/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
@@ -70,6 +70,12 @@
(d/transact! conn simple-schema)
(f)))
+(defn agent [id]
+ (d/entity @conn [:agent/id id]))
+
+(defn job [id]
+ (d/entity @conn [:job/id id]))
+
(deftest add-agent-test
(testing "Test adding agent"
(let [tx (add-agent {:id "1d7158f8-f7a0-4ff9-9758-25efcc5aae65"
@@ -111,26 +117,26 @@
(deftest q-job-test
(testing "test query job"
- (is (= [(d/entity @conn [:job/id "96cf6f11-591d-4cde-9ab0-56e371acb6d2"])
- (d/entity @conn [:job/id "51ab0771-f1e4-4268-868f-9029a58f6612"])]
+ (is (= [(job "96cf6f11-591d-4cde-9ab0-56e371acb6d2")
+ (job "51ab0771-f1e4-4268-868f-9029a58f6612")]
(q-job false :unassigned "rewards-question")))
- (is (= [(d/entity @conn [:job/id "b201d085-91b5-4a13-9a74-7861426e9996"])]
+ (is (= [(job "b201d085-91b5-4a13-9a74-7861426e9996")]
(q-job true :processing "purchases-question")))
- (is (= [(d/entity @conn [:job/id "aa327540-4e24-47f4-9e9c-81cdd5195934"])]
+ (is (= [(job "aa327540-4e24-47f4-9e9c-81cdd5195934")]
(q-job true :completed "bills-question")))
(is (= [] (q-job false :completed "rewards-question")))
- (is (= [(d/entity @conn [:job/id "1e0d939d-494b-48d2-9247-b5ae207a519a"])]
+ (is (= [(job "1e0d939d-494b-48d2-9247-b5ae207a519a")]
(q-job false :completed "rewards-question" "bills-question")))
- (is (= [(d/entity @conn [:job/id "1e0d939d-494b-48d2-9247-b5ae207a519a"])]
+ (is (= [(job "1e0d939d-494b-48d2-9247-b5ae207a519a")]
(q-job false :completed ["rewards-question" "bills-question"])))))
(deftest agent-jobs-test
(testing "Test fetch relation agent job"
- (is (= [(d/entity @conn [:job/id "1e0d939d-494b-48d2-9247-b5ae207a519a"])
- (d/entity @conn [:job/id "aa327540-4e24-47f4-9e9c-81cdd5195934"])
- (d/entity @conn [:job/id "3cdc52fe-b538-40a6-a9d7-92fa840c2c4b"])]
+ (is (= [(job "1e0d939d-494b-48d2-9247-b5ae207a519a")
+ (job "aa327540-4e24-47f4-9e9c-81cdd5195934")
+ (job "3cdc52fe-b538-40a6-a9d7-92fa840c2c4b")]
(agent-jobs "644be0ce-035d-48cb-867e-8e6de2714a8d" :completed)))
- (is (= [(d/entity @conn [:job/id "b201d085-91b5-4a13-9a74-7861426e9996"])]
+ (is (= [(job "b201d085-91b5-4a13-9a74-7861426e9996")]
(agent-jobs "644be0ce-035d-48cb-867e-8e6de2714a8d" :processing)))
(is (= [] (agent-jobs "644be0ce-035d-48cb-867e-8e6de2714a8d" :unassigned)))))
@@ -140,7 +146,44 @@
(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 (= (d/entity @conn [:job/id "96cf6f11-591d-4cde-9ab0-56e371acb6d2"])
- (request-job "644be0ce-035d-48cb-867e-8e6de2714a8d"))))) \ No newline at end of file
+ (is (= (job "96cf6f11-591d-4cde-9ab0-56e371acb6d2")
+ (request-job "644be0ce-035d-48cb-867e-8e6de2714a8d")))))
+
+(deftest bind-agent-test
+ (testing "Test bind agent"
+ (let [_ (bind-agent "644be0ce-035d-48cb-867e-8e6de2714a8d" "51ab0771-f1e4-4268-868f-9029a58f6612")
+ a (agent "644be0ce-035d-48cb-867e-8e6de2714a8d")]
+ (is (= "51ab0771-f1e4-4268-868f-9029a58f6612"
+ (-> a :agent/job :job/id))))))
+
+(deftest t-job-test
+ (testing "Test transact job"
+ (let [_ (t-job "51ab0771-f1e4-4268-868f-9029a58f6612" :completed)
+ j (job "51ab0771-f1e4-4268-868f-9029a58f6612")]
+ (is (= :completed (:job/status j))))
+ (let [_ (t-job "51ab0771-f1e4-4268-868f-9029a58f6612" :completed "644be0ce-035d-48cb-867e-8e6de2714a8d")
+ j (job "51ab0771-f1e4-4268-868f-9029a58f6612")]
+ (are [left right]
+ (= left right)
+ :completed (:job/status j)
+ "644be0ce-035d-48cb-867e-8e6de2714a8d" (-> j :job/agent :agent/id)))))
+
+(deftest end-job-test
+ (testing "Test end job"
+ (let [a (agent "644be0ce-035d-48cb-867e-8e6de2714a8d")
+ _ (end-job a)]
+ (is (= :completed (-> (agent "644be0ce-035d-48cb-867e-8e6de2714a8d")
+ :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)))))
+