🎉 Add tests for webhooks rpc and logger

This commit is contained in:
Andrey Antukh 2022-12-12 08:31:48 +01:00
parent 21abd98b95
commit f2b60261f8
5 changed files with 183 additions and 11 deletions

View file

@ -12,8 +12,6 @@
[app.storage :as sto]
[backend-tests.helpers :as th]
[clojure.test :as t]
[datoteka.fs :as fs]
[datoteka.io :as io]
[mockery.core :refer [with-mocks]]))
(t/use-fixtures :once th/state-init)
@ -52,7 +50,6 @@
(t/is (= (:mtype params) (:mtype result)))
(vreset! whook result))))
(th/reset-mock! http-mock)
(t/testing "update webhook 1 (success)"
@ -144,3 +141,41 @@
(t/is (= (:code error-data) :object-not-found)))))
)))
(t/deftest webhooks-quotes
(with-mocks [http-mock {:target 'app.http.client/req!
:return {:status 200}}]
(let [prof (th/create-profile* 1 {:is-active true})
team-id (:default-team-id prof)
params {::th/type :create-webhook
:profile-id (:id prof)
:team-id team-id
:uri "http://example.com"
:mtype "application/json"}
out1 (th/command! params)
out2 (th/command! params)
out3 (th/command! params)
out4 (th/command! params)
out5 (th/command! params)
out6 (th/command! params)
out7 (th/command! params)
out8 (th/command! params)
out9 (th/command! params)]
(t/is (= 8 (:call-count @http-mock)))
(t/is (nil? (:error out1)))
(t/is (nil? (:error out2)))
(t/is (nil? (:error out3)))
(t/is (nil? (:error out4)))
(t/is (nil? (:error out5)))
(t/is (nil? (:error out6)))
(t/is (nil? (:error out7)))
(t/is (nil? (:error out8)))
(let [error (:error out9)
error-data (ex-data error)]
(t/is (th/ex-info? error))
(t/is (= (:type error-data) :restriction))
(t/is (= (:code error-data) :webhooks-quote-reached))))))