From f55b9febe8974f861e2179baddaf9d48fa73552c Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Thu, 22 Feb 2018 00:38:26 -0300 Subject: A better swagger documentation and a better routing test --- test/clj/queue_api/test/db/core_test.clj | 20 ++++++---- test/clj/queue_api/test/handler.clj | 64 ++++++++++++++++++++++---------- 2 files changed, 57 insertions(+), 27 deletions(-) (limited to 'test') 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)))))) -- cgit v1.2.3