aboutsummaryrefslogtreecommitdiff
path: root/test/clj/queue_api
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2018-02-22 00:38:26 -0300
committerGabriel A. Giovanini <mail@gabrielgio.me>2018-02-22 00:38:26 -0300
commitf55b9febe8974f861e2179baddaf9d48fa73552c (patch)
treef0d11523c5f986643a0b37cc067dcd962ecd25de /test/clj/queue_api
parent0b8277f72cdc2ed2abeb566f30958bd8e0dc5167 (diff)
downloadqueue-api-f55b9febe8974f861e2179baddaf9d48fa73552c.tar.gz
queue-api-f55b9febe8974f861e2179baddaf9d48fa73552c.tar.bz2
queue-api-f55b9febe8974f861e2179baddaf9d48fa73552c.zip
A better swagger documentation and a better routing test
Diffstat (limited to 'test/clj/queue_api')
-rw-r--r--test/clj/queue_api/test/db/core_test.clj20
-rw-r--r--test/clj/queue_api/test/handler.clj64
2 files changed, 57 insertions, 27 deletions
diff --git a/test/clj/queue_api/test/db/core_test.clj b/test/clj/queue_api/test/db/core_test.clj
index 117cc26..4afa99d 100644
--- a/test/clj/queue_api/test/db/core_test.clj
+++ b/test/clj/queue_api/test/db/core_test.clj
@@ -105,17 +105,12 @@
(d/transact! conn base-schema)
(f)))
-
-
-(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"
:name "Derpinson"
- :primary-skillset ["rewards-question" "bills-question"]
- :secondary-skillset []})
+ :primary_skillset ["rewards-question" "bills-question"]
+ :secondary_skillset []})
tx-data (:tx-data tx)]
(is (not (empty? tx-data))))))
@@ -244,9 +239,18 @@
(testing "Test agent"
(are [left right]
(= left right)
- (d/entity @conn [:agent/id "644be0ce-035d-48cb-867e-8e6de2714a8d"]) (agent "644be0ce-035d-48cb-867e-8e6de2714a8d")
+ (d/entity @conn [:agent/id "644be0ce-035d-48cb-867e-8e6de2714a8d"])
+ (agent "644be0ce-035d-48cb-867e-8e6de2714a8d")
nil (agent "7b8e17fc-7953-44cf-9249-294c4eb73087"))))
+(deftest job-test
+ (testing "Test agent"
+ (are [left right]
+ (= left right)
+ (d/entity @conn [:job/id "dfa7744f-8d61-4d37-885f-dbef2d4df13b"])
+ (job "dfa7744f-8d61-4d37-885f-dbef2d4df13b")
+ nil (job "7b8e17fc-7953-44cf-9249-294c4eb73087"))))
+
(deftest dequeue-job-test
(testing "Test Dummy Derp dequeuing process"
(are [left right]
diff --git a/test/clj/queue_api/test/handler.clj b/test/clj/queue_api/test/handler.clj
index eeb860a..9dd13eb 100644
--- a/test/clj/queue_api/test/handler.clj
+++ b/test/clj/queue_api/test/handler.clj
@@ -2,50 +2,76 @@
(:require [clojure.test :refer :all]
[ring.mock.request :refer :all]
[queue-api.handler :refer :all]
- [mount.core :as mount]))
+ [queue-api.db.core :refer :all]
+ [mount.core :as mount]
+ [queue-api.test.db.core-test :refer [base-schema]]
+ [datascript.core :as d]))
(use-fixtures
:once
(fn [f]
(mount/start #'queue-api.config/env
- #'queue-api.handler/app
- #'queue-api.db.core/conn)git
+ #'queue-api.handler/app)
+ (f)))
+(use-fixtures
+ :each
+ (fn [f]
+ (mount/stop #'queue-api.db.core/conn)
+ (mount/start #'queue-api.db.core/conn)
+ (d/transact! conn base-schema)
(f)))
(deftest agent-test
- (testing "Agent route"
+ (testing "Agent route PUT"
(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))))
+ (is (= 201 (:status response))))
+ (let [response (-> (request :put "/agent")
+ (json-body {:id "644be0ce-035d-48cb-867e-8e6de2714a8d"
+ :name "Dummy"
+ :primary_skillset ["reward_request"]
+ :secondary_skillset []})
+ app)]
+ (is (= 400 (:status response)))))
+ (testing "Agent route POST"
(let [response (-> (request :post "/agent")
- (json-body {:agent_id "8ab86c18-3fae-4804-bfd9-c3d6e8f66260"})
+ (json-body {:agent_id "51c6324b-a176-4663-8b5f-03fc2544dbe2"})
+ app)]
+ (is (= 404 (:status response))))
+ (let [response (-> (request :post "/agent")
+ (json-body {:agent_id "644be0ce-035d-48cb-867e-8e6de2714a8d"})
app)]
(is (= 200 (:status response))))))
(deftest job-test
- (testing "Job route"
+ (testing "Job route PUT"
(let [response (-> (request :put "/job")
- (json-body {:id "895e9b31-5690-486e-b8dd-5c2345e056f6"
- :type "bills_request"
+ (json-body {:id "650d3df1-9eed-4070-9751-2f8504bcf909"
+ :type "bills_question"
:urgent false})
app)]
+ (is (= 201 (:status response))))
+ (let [response (-> (request :put "/agent")
+ (json-body {:id "1e0d939d-494b-48d2-9247-b5ae207a519a"
+ :type "bills_question"
+ :urgent false})
+ app)]
+ (is (= 400 (:status response)))))
+
+ (testing "Job route POST"
+ (let [response (-> (request :post "/job")
+ (json-body {:agent_id "644be0ce-035d-48cb-867e-8e6de2714a8d"})
+ app)]
(is (= 200 (:status response))))
(let [response (-> (request :post "/job")
- (json-body {:agent_id "8ab86c18-3fae-4804-bfd9-c3d6e8f66260"})
+ (json-body {:agent_id "933e0f19-08f8-4976-ad9f-f5fc4bf9047e"})
app)]
- (is (= 400 (:status response))))))
-
-(deftest queue-test
- (testing "Queue route"
+ (is (= 404 (:status response)))))
+ (testing "Job route GET"
(let [response (app (request :get "/job"))]
(is (= 200 (:status response))))))
-
-(deftest invalid-test
- (testing "not-found route"
- (let [response (app (request :get "/invalid"))]
- (is (= 404 (:status response))))))