Skip to content

Commit

Permalink
add integration test retract-menu-test
Browse files Browse the repository at this point in the history
  • Loading branch information
macielti committed Nov 22, 2024
1 parent 1bb742b commit e418e0f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/integration/aux/http.clj
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,22 @@
"Authorization" (str "Bearer " token)})]
{:status status
:body (json/decode body true)}))

(defn retract-menu
[menu-id
token
service-fn]
(let [{:keys [body status]} (test/response-for service-fn
:delete (str "/api/menus/" menu-id)
:headers {"Content-Type" "application/json"
"Authorization" (str "Bearer " token)})]
{:status status
:body (json/decode body true)}))

(defn fetch-all-menus
[service-fn]
(let [{:keys [body status]} (test/response-for service-fn
:get "/api/menus"
:headers {"Content-Type" "application/json"})]
{:status status
:body (json/decode body true)}))
34 changes: 34 additions & 0 deletions test/integration/menu_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
[aux.http :as http]
[clj-uuid]
[clojure.test :refer [is testing]]
[common-test-clj.helpers.schema :as helpers.schema]
[fixtures.menu]
[integrant.core :as ig]
[matcher-combinators.test :refer [match?]]
[rango-graalvm.wire.in.menu :as wire.in.menu]
[schema.test :as s]
[service-component.core :as component.service]))

Expand All @@ -28,3 +30,35 @@
(http/fetch-one-menu menu-id service-fn))))

(ig/halt! system)))

(s/deftest retract-menu-test
(let [system (ig/init components/config-test)
service-fn (-> system ::component.service/service :io.pedestal.http/service-fn)
token (-> (http/authenticate-admin {:customer {:username "admin" :password "da3bf409"}} service-fn)
:body :token)
{menu-id :id} (-> (http/create-menu {:menu fixtures.menu/wire-in-menu} token service-fn) :body :menu)
_ (http/create-menu {:menu (helpers.schema/generate wire.in.menu/Menu {:reference-date "2024-02-01"})} token service-fn)]

(testing "Admin is authenticated"
(is (string? token)))

(testing "Menu was created"
(is (clj-uuid/uuid-string? menu-id)))

(testing "Created two menus"
(is (match? {:status 200
:body {:menus [{:id menu-id}
{:id clj-uuid/uuid-string?}]}}
(http/fetch-all-menus service-fn))))

(testing "Retract menu"
(is (match? {:status 200
:body {}}
(http/retract-menu menu-id token service-fn))))

(testing "Only one menu left"
(is (match? {:status 200
:body {:menus [{:id clj-uuid/uuid-string?}]}}
(http/fetch-all-menus service-fn))))

(ig/halt! system)))

0 comments on commit e418e0f

Please sign in to comment.