From e418e0fa247eeec0e17671a04f3c1bc8c4da07e9 Mon Sep 17 00:00:00 2001 From: Bruno do Nascimento Maciel Date: Fri, 22 Nov 2024 20:42:41 -0300 Subject: [PATCH] add integration test retract-menu-test --- test/integration/aux/http.clj | 19 +++++++++++++++++++ test/integration/menu_test.clj | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/test/integration/aux/http.clj b/test/integration/aux/http.clj index 7b634bf..c14f157 100644 --- a/test/integration/aux/http.clj +++ b/test/integration/aux/http.clj @@ -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)})) diff --git a/test/integration/menu_test.clj b/test/integration/menu_test.clj index 6fcf8af..d05db05 100644 --- a/test/integration/menu_test.clj +++ b/test/integration/menu_test.clj @@ -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])) @@ -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)))