2021-02-11 11:57:41 -05:00
|
|
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
;;
|
2022-09-20 16:23:22 -05:00
|
|
|
;; Copyright (c) KALEIDOS INC
|
2021-02-11 11:57:41 -05:00
|
|
|
|
2022-11-08 04:40:19 -05:00
|
|
|
(ns backend-tests.rpc-team-test
|
2021-02-11 11:57:41 -05:00
|
|
|
(:require
|
2023-03-02 10:57:28 -05:00
|
|
|
[app.common.logging :as l]
|
2021-02-11 11:57:41 -05:00
|
|
|
[app.common.uuid :as uuid]
|
|
|
|
[app.db :as db]
|
|
|
|
[app.http :as http]
|
2022-12-21 05:53:56 -05:00
|
|
|
[app.rpc :as-alias rpc]
|
2021-02-11 11:57:41 -05:00
|
|
|
[app.storage :as sto]
|
2022-09-26 16:56:58 -05:00
|
|
|
[app.tokens :as tokens]
|
2021-06-07 09:51:09 -05:00
|
|
|
[app.util.time :as dt]
|
2022-12-21 05:53:56 -05:00
|
|
|
[backend-tests.helpers :as th]
|
2021-02-11 11:57:41 -05:00
|
|
|
[clojure.test :as t]
|
2021-05-28 06:50:42 -05:00
|
|
|
[datoteka.core :as fs]
|
|
|
|
[mockery.core :refer [with-mocks]]))
|
2021-02-11 11:57:41 -05:00
|
|
|
|
|
|
|
(t/use-fixtures :once th/state-init)
|
|
|
|
(t/use-fixtures :each th/database-reset)
|
|
|
|
|
2023-01-02 09:49:08 -05:00
|
|
|
(t/deftest create-team-invitations
|
2023-02-06 06:20:51 -05:00
|
|
|
(with-mocks [mock {:target 'app.email/send! :return nil}]
|
2021-02-11 11:57:41 -05:00
|
|
|
(let [profile1 (th/create-profile* 1 {:is-active true})
|
|
|
|
profile2 (th/create-profile* 2 {:is-active true})
|
|
|
|
profile3 (th/create-profile* 3 {:is-active true :is-muted true})
|
|
|
|
|
|
|
|
team (th/create-team* 1 {:profile-id (:id profile1)})
|
|
|
|
|
|
|
|
pool (:app.db/pool th/*system*)
|
2023-01-02 09:49:08 -05:00
|
|
|
data {::th/type :create-team-invitations
|
|
|
|
::rpc/profile-id (:id profile1)
|
2021-02-11 11:57:41 -05:00
|
|
|
:team-id (:id team)
|
2023-01-02 09:49:08 -05:00
|
|
|
:role :editor}]
|
2021-02-11 11:57:41 -05:00
|
|
|
|
|
|
|
;; invite external user without complaints
|
2023-07-10 09:56:34 -05:00
|
|
|
(let [data (assoc data :emails ["foo@bar.com"])
|
2023-01-02 09:49:08 -05:00
|
|
|
out (th/command! data)
|
2022-09-26 16:56:58 -05:00
|
|
|
;; retrieve the value from the database and check its content
|
2022-02-15 08:18:45 -05:00
|
|
|
invitation (db/exec-one!
|
2022-09-26 16:56:58 -05:00
|
|
|
th/*pool*
|
|
|
|
["select count(*) as num from team_invitation where team_id = ? and email_to = ?"
|
|
|
|
(:team-id data) "foo@bar.com"])]
|
2021-10-15 10:40:49 -05:00
|
|
|
|
|
|
|
;; (th/print-result! out)
|
2022-09-26 16:56:58 -05:00
|
|
|
(t/is (th/success? out))
|
2022-02-15 08:18:45 -05:00
|
|
|
(t/is (= 1 (:call-count (deref mock))))
|
|
|
|
(t/is (= 1 (:num invitation))))
|
|
|
|
|
2021-02-11 11:57:41 -05:00
|
|
|
;; invite internal user without complaints
|
|
|
|
(th/reset-mock! mock)
|
2023-07-10 09:56:34 -05:00
|
|
|
(let [data (assoc data :emails [(:email profile2)])
|
2023-01-02 09:49:08 -05:00
|
|
|
out (th/command! data)]
|
2022-09-26 16:56:58 -05:00
|
|
|
(t/is (th/success? out))
|
2021-02-11 11:57:41 -05:00
|
|
|
(t/is (= 1 (:call-count (deref mock)))))
|
|
|
|
|
|
|
|
;; invite user with complaint
|
|
|
|
(th/create-global-complaint-for pool {:type :complaint :email "foo@bar.com"})
|
|
|
|
(th/reset-mock! mock)
|
2023-07-10 09:56:34 -05:00
|
|
|
(let [data (assoc data :emails ["foo@bar.com"])
|
2023-01-02 09:49:08 -05:00
|
|
|
out (th/command! data)]
|
2022-09-26 16:56:58 -05:00
|
|
|
(t/is (th/success? out))
|
2021-02-11 11:57:41 -05:00
|
|
|
(t/is (= 1 (:call-count (deref mock)))))
|
|
|
|
|
2022-12-13 09:29:43 -05:00
|
|
|
;; get invitation token
|
|
|
|
(let [params {::th/type :get-team-invitation-token
|
2022-12-21 05:53:56 -05:00
|
|
|
::rpc/profile-id (:id profile1)
|
2022-12-13 09:29:43 -05:00
|
|
|
:team-id (:id team)
|
|
|
|
:email "foo@bar.com"}
|
|
|
|
out (th/command! params)]
|
|
|
|
(t/is (th/success? out))
|
|
|
|
(let [result (:result out)]
|
|
|
|
(contains? result :token)))
|
|
|
|
|
2021-02-11 11:57:41 -05:00
|
|
|
;; invite user with bounce
|
|
|
|
(th/reset-mock! mock)
|
2022-09-26 16:56:58 -05:00
|
|
|
|
2021-02-11 11:57:41 -05:00
|
|
|
(th/create-global-complaint-for pool {:type :bounce :email "foo@bar.com"})
|
2023-07-10 09:56:34 -05:00
|
|
|
(let [data (assoc data :emails ["foo@bar.com"])
|
2023-01-02 09:49:08 -05:00
|
|
|
out (th/command! data)]
|
2021-02-11 11:57:41 -05:00
|
|
|
|
2022-09-26 16:56:58 -05:00
|
|
|
(t/is (not (th/success? out)))
|
|
|
|
(t/is (= 0 (:call-count @mock)))
|
|
|
|
|
|
|
|
(let [edata (-> out :error ex-data)]
|
|
|
|
(t/is (= :validation (:type edata)))
|
|
|
|
(t/is (= :email-has-permanent-bounces (:code edata)))))
|
2021-02-11 11:57:41 -05:00
|
|
|
|
|
|
|
;; invite internal user that is muted
|
|
|
|
(th/reset-mock! mock)
|
2022-09-26 16:56:58 -05:00
|
|
|
|
2023-07-10 09:56:34 -05:00
|
|
|
(let [data (assoc data :emails [(:email profile3)])
|
2023-01-02 09:49:08 -05:00
|
|
|
out (th/command! data)]
|
2022-09-26 16:56:58 -05:00
|
|
|
|
|
|
|
(t/is (not (th/success? out)))
|
|
|
|
(t/is (= 0 (:call-count @mock)))
|
|
|
|
|
|
|
|
(let [edata (-> out :error ex-data)]
|
|
|
|
(t/is (= :validation (:type edata)))
|
2023-11-29 06:53:34 -05:00
|
|
|
(t/is (= :member-is-muted (:code edata))))))))
|
2022-09-26 16:56:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
(t/deftest invitation-tokens
|
2023-02-06 06:20:51 -05:00
|
|
|
(with-mocks [mock {:target 'app.email/send! :return nil}]
|
2022-09-26 16:56:58 -05:00
|
|
|
(let [profile1 (th/create-profile* 1 {:is-active true})
|
|
|
|
profile2 (th/create-profile* 2 {:is-active true})
|
|
|
|
|
|
|
|
team (th/create-team* 1 {:profile-id (:id profile1)})
|
|
|
|
|
|
|
|
sprops (:app.setup/props th/*system*)
|
|
|
|
pool (:app.db/pool th/*system*)]
|
|
|
|
|
|
|
|
;; Try to invite a not existing user
|
2023-01-02 09:49:08 -05:00
|
|
|
(let [data {::th/type :create-team-invitations
|
|
|
|
::rpc/profile-id (:id profile1)
|
2023-07-10 09:56:34 -05:00
|
|
|
:emails ["notexisting@example.com"]
|
2022-09-26 16:56:58 -05:00
|
|
|
:team-id (:id team)
|
2023-01-02 09:49:08 -05:00
|
|
|
:role :editor}
|
|
|
|
out (th/command! data)]
|
2022-09-26 16:56:58 -05:00
|
|
|
|
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (th/success? out))
|
|
|
|
(t/is (= 1 (:call-count @mock)))
|
2023-07-10 09:56:34 -05:00
|
|
|
(t/is (= 1 (-> out :result :total)))
|
2022-09-26 16:56:58 -05:00
|
|
|
|
2023-07-10 09:56:34 -05:00
|
|
|
(let [token (-> out :result :invitations first)
|
2022-09-26 16:56:58 -05:00
|
|
|
claims (tokens/decode sprops token)]
|
|
|
|
(t/is (= :team-invitation (:iss claims)))
|
|
|
|
(t/is (= (:id profile1) (:profile-id claims)))
|
|
|
|
(t/is (= :editor (:role claims)))
|
|
|
|
(t/is (= (:id team) (:team-id claims)))
|
2023-07-10 09:56:34 -05:00
|
|
|
(t/is (= (first (:emails data)) (:member-email claims)))
|
2022-09-26 16:56:58 -05:00
|
|
|
(t/is (nil? (:member-id claims)))))
|
|
|
|
|
|
|
|
(th/reset-mock! mock)
|
|
|
|
|
|
|
|
;; Try to invite existing user
|
2023-01-02 09:49:08 -05:00
|
|
|
(let [data {::th/type :create-team-invitations
|
|
|
|
::rpc/profile-id (:id profile1)
|
2023-07-10 09:56:34 -05:00
|
|
|
:emails [(:email profile2)]
|
2022-09-26 16:56:58 -05:00
|
|
|
:team-id (:id team)
|
2023-01-02 09:49:08 -05:00
|
|
|
:role :editor}
|
|
|
|
out (th/command! data)]
|
2022-09-26 16:56:58 -05:00
|
|
|
|
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (th/success? out))
|
|
|
|
(t/is (= 1 (:call-count @mock)))
|
2023-07-10 09:56:34 -05:00
|
|
|
(t/is (= 1 (-> out :result :total)))
|
2022-09-26 16:56:58 -05:00
|
|
|
|
2023-07-10 09:56:34 -05:00
|
|
|
(let [token (-> out :result :invitations first)
|
2022-09-26 16:56:58 -05:00
|
|
|
claims (tokens/decode sprops token)]
|
|
|
|
(t/is (= :team-invitation (:iss claims)))
|
|
|
|
(t/is (= (:id profile1) (:profile-id claims)))
|
|
|
|
(t/is (= :editor (:role claims)))
|
|
|
|
(t/is (= (:id team) (:team-id claims)))
|
2023-07-10 09:56:34 -05:00
|
|
|
(t/is (= (first (:emails data)) (:member-email claims)))
|
2023-11-29 06:53:34 -05:00
|
|
|
(t/is (= (:id profile2) (:member-id claims))))))))
|
2022-09-26 16:56:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
(t/deftest accept-invitation-tokens
|
|
|
|
(let [profile1 (th/create-profile* 1 {:is-active true})
|
|
|
|
profile2 (th/create-profile* 2 {:is-active true})
|
2023-02-25 04:24:41 -05:00
|
|
|
profile3 (th/create-profile* 3 {:is-active true})
|
2022-09-26 16:56:58 -05:00
|
|
|
|
|
|
|
team (th/create-team* 1 {:profile-id (:id profile1)})
|
2021-02-11 11:57:41 -05:00
|
|
|
|
2022-09-26 16:56:58 -05:00
|
|
|
sprops (:app.setup/props th/*system*)
|
|
|
|
pool (:app.db/pool th/*system*)]
|
|
|
|
|
|
|
|
(let [token (tokens/generate sprops
|
|
|
|
{:iss :team-invitation
|
|
|
|
:exp (dt/in-future "1h")
|
|
|
|
:profile-id (:id profile1)
|
|
|
|
:role :editor
|
|
|
|
:team-id (:id team)
|
|
|
|
:member-email (:email profile2)
|
|
|
|
:member-id (:id profile2)})]
|
|
|
|
|
2023-02-25 04:24:41 -05:00
|
|
|
(t/testing "Verify token as anonymous user"
|
|
|
|
(db/insert! pool :team-invitation
|
|
|
|
{:team-id (:id team)
|
|
|
|
:email-to (:email profile2)
|
|
|
|
:role "editor"
|
|
|
|
:valid-until (dt/in-future "48h")})
|
2022-09-26 16:56:58 -05:00
|
|
|
|
2023-02-25 04:24:41 -05:00
|
|
|
(let [data {::th/type :verify-token :token token}
|
|
|
|
out (th/command! data)]
|
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (th/success? out))
|
2022-09-26 16:56:58 -05:00
|
|
|
|
2023-02-25 04:24:41 -05:00
|
|
|
(let [result (:result out)]
|
|
|
|
(t/is (contains? result :invitation-token))
|
|
|
|
(t/is (contains? result :iss))
|
|
|
|
(t/is (contains? result :redirect-to))
|
|
|
|
(t/is (contains? result :state))
|
|
|
|
|
|
|
|
(t/is (= :pending (:state result)))
|
|
|
|
(t/is (= :auth-login (:redirect-to result))))
|
2022-09-26 16:56:58 -05:00
|
|
|
|
2023-02-25 04:24:41 -05:00
|
|
|
(let [rows (db/query pool :team-profile-rel {:team-id (:id team)})]
|
|
|
|
(t/is (= 1 (count rows))))))
|
2022-09-26 16:56:58 -05:00
|
|
|
|
|
|
|
;; Clean members
|
|
|
|
(db/delete! pool :team-profile-rel
|
|
|
|
{:team-id (:id team)
|
|
|
|
:profile-id (:id profile2)})
|
|
|
|
|
|
|
|
|
2023-02-25 04:24:41 -05:00
|
|
|
(t/testing "Verify token as logged-in user"
|
|
|
|
(let [data {::th/type :verify-token
|
|
|
|
::rpc/profile-id (:id profile2)
|
|
|
|
:token token}
|
|
|
|
out (th/command! data)]
|
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (th/success? out))
|
|
|
|
(let [result (:result out)]
|
|
|
|
(t/is (= :created (:state result)))
|
|
|
|
(t/is (= (:email profile2) (:member-email result)))
|
|
|
|
(t/is (= (:id profile2) (:member-id result))))
|
|
|
|
|
|
|
|
(let [rows (db/query pool :team-profile-rel {:team-id (:id team)})]
|
|
|
|
(t/is (= 2 (count rows))))))
|
|
|
|
|
|
|
|
(t/testing "Verify token as logged-in wrong user"
|
|
|
|
(db/insert! pool :team-invitation
|
|
|
|
{:team-id (:id team)
|
|
|
|
:email-to (:email profile3)
|
|
|
|
:role "editor"
|
|
|
|
:valid-until (dt/in-future "48h")})
|
|
|
|
|
|
|
|
(let [data {::th/type :verify-token
|
|
|
|
::rpc/profile-id (:id profile1)
|
|
|
|
:token token}
|
|
|
|
out (th/command! data)]
|
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (not (th/success? out)))
|
|
|
|
(let [edata (-> out :error ex-data)]
|
|
|
|
(t/is (= :validation (:type edata)))
|
2023-11-29 06:53:34 -05:00
|
|
|
(t/is (= :invalid-token (:code edata)))))))))
|
2021-02-11 11:57:41 -05:00
|
|
|
|
2023-01-02 09:49:08 -05:00
|
|
|
(t/deftest create-team-invitations-with-email-verification-disabled
|
2023-02-06 06:20:51 -05:00
|
|
|
(with-mocks [mock {:target 'app.email/send! :return nil}]
|
2022-09-14 05:39:20 -05:00
|
|
|
(let [profile1 (th/create-profile* 1 {:is-active true})
|
|
|
|
profile2 (th/create-profile* 2 {:is-active true})
|
|
|
|
profile3 (th/create-profile* 3 {:is-active true :is-muted true})
|
|
|
|
|
|
|
|
team (th/create-team* 1 {:profile-id (:id profile1)})
|
|
|
|
|
|
|
|
pool (:app.db/pool th/*system*)
|
2023-01-02 09:49:08 -05:00
|
|
|
data {::th/type :create-team-invitations
|
|
|
|
::rpc/profile-id (:id profile1)
|
2022-09-14 05:39:20 -05:00
|
|
|
:team-id (:id team)
|
2023-01-02 09:49:08 -05:00
|
|
|
:role :editor}]
|
2022-09-14 05:39:20 -05:00
|
|
|
|
|
|
|
;; invite internal user without complaints
|
|
|
|
(with-redefs [app.config/flags #{}]
|
|
|
|
(th/reset-mock! mock)
|
2023-07-10 09:56:34 -05:00
|
|
|
(let [data (assoc data :emails [(:email profile2)])
|
2023-01-02 09:49:08 -05:00
|
|
|
out (th/command! data)]
|
2022-09-26 16:56:58 -05:00
|
|
|
(t/is (th/success? out))
|
2022-09-14 05:39:20 -05:00
|
|
|
(t/is (= 0 (:call-count (deref mock)))))
|
|
|
|
|
|
|
|
(let [members (db/query pool :team-profile-rel
|
|
|
|
{:team-id (:id team)
|
|
|
|
:profile-id (:id profile2)})]
|
|
|
|
(t/is (= 1 (count members)))
|
|
|
|
(t/is (true? (-> members first :can-edit))))))))
|
|
|
|
|
2022-09-26 16:56:58 -05:00
|
|
|
(t/deftest team-deletion
|
|
|
|
(let [profile1 (th/create-profile* 1 {:is-active true})
|
2021-06-07 09:51:09 -05:00
|
|
|
team (th/create-team* 1 {:profile-id (:id profile1)})
|
|
|
|
pool (:app.db/pool th/*system*)
|
|
|
|
data {::th/type :delete-team
|
2023-01-02 09:49:08 -05:00
|
|
|
::rpc/profile-id (:id profile1)
|
|
|
|
:team-id (:id team)}]
|
2021-06-07 09:51:09 -05:00
|
|
|
|
|
|
|
;; team is not deleted because it does not meet all
|
|
|
|
;; conditions to be deleted.
|
2022-09-26 16:56:58 -05:00
|
|
|
(let [result (th/run-task! :objects-gc {:min-age (dt/duration 0)})]
|
2022-08-12 01:34:23 -05:00
|
|
|
(t/is (= 0 (:processed result))))
|
2021-06-07 09:51:09 -05:00
|
|
|
|
|
|
|
;; query the list of teams
|
2023-01-02 09:49:08 -05:00
|
|
|
(let [data {::th/type :get-teams
|
|
|
|
::rpc/profile-id (:id profile1)}
|
|
|
|
out (th/command! data)]
|
2021-06-07 09:51:09 -05:00
|
|
|
;; (th/print-result! out)
|
2022-09-26 16:56:58 -05:00
|
|
|
(t/is (th/success? out))
|
2021-06-07 09:51:09 -05:00
|
|
|
(let [result (:result out)]
|
|
|
|
(t/is (= 2 (count result)))
|
|
|
|
(t/is (= (:id team) (get-in result [1 :id])))
|
|
|
|
(t/is (= (:default-team-id profile1) (get-in result [0 :id])))))
|
|
|
|
|
|
|
|
;; Request team to be deleted
|
|
|
|
(let [params {::th/type :delete-team
|
2023-01-02 09:49:08 -05:00
|
|
|
::rpc/profile-id (:id profile1)
|
|
|
|
:id (:id team)}
|
|
|
|
out (th/command! params)]
|
2022-09-26 16:56:58 -05:00
|
|
|
(t/is (th/success? out)))
|
2021-06-07 09:51:09 -05:00
|
|
|
|
|
|
|
;; query the list of teams after soft deletion
|
2023-01-02 09:49:08 -05:00
|
|
|
(let [data {::th/type :get-teams
|
|
|
|
::rpc/profile-id (:id profile1)}
|
|
|
|
out (th/command! data)]
|
2021-06-07 09:51:09 -05:00
|
|
|
;; (th/print-result! out)
|
2022-09-26 16:56:58 -05:00
|
|
|
(t/is (th/success? out))
|
2021-06-07 09:51:09 -05:00
|
|
|
(let [result (:result out)]
|
|
|
|
(t/is (= 1 (count result)))
|
|
|
|
(t/is (= (:default-team-id profile1) (get-in result [0 :id])))))
|
|
|
|
|
|
|
|
;; run permanent deletion (should be noop)
|
2022-09-26 16:56:58 -05:00
|
|
|
(let [result (th/run-task! :objects-gc {:min-age (dt/duration {:minutes 1})})]
|
2022-08-12 01:34:23 -05:00
|
|
|
(t/is (= 0 (:processed result))))
|
2021-06-07 09:51:09 -05:00
|
|
|
|
2021-11-03 07:10:49 -05:00
|
|
|
;; query the list of projects after hard deletion
|
2023-04-24 13:18:14 -05:00
|
|
|
(let [data {::th/type :get-projects
|
|
|
|
::rpc/profile-id (:id profile1)
|
2023-01-02 09:49:08 -05:00
|
|
|
:team-id (:id team)}
|
2023-04-24 13:18:14 -05:00
|
|
|
out (th/command! data)]
|
2021-06-07 09:51:09 -05:00
|
|
|
;; (th/print-result! out)
|
2022-09-26 16:56:58 -05:00
|
|
|
(t/is (not (th/success? out)))
|
|
|
|
(let [edata (-> out :error ex-data)]
|
|
|
|
(t/is (= :not-found (:type edata)))))
|
2021-06-07 09:51:09 -05:00
|
|
|
|
|
|
|
;; run permanent deletion
|
2022-09-26 16:56:58 -05:00
|
|
|
(let [result (th/run-task! :objects-gc {:min-age (dt/duration 0)})]
|
2022-08-12 01:34:23 -05:00
|
|
|
(t/is (= 1 (:processed result))))
|
2021-06-07 09:51:09 -05:00
|
|
|
|
|
|
|
;; query the list of projects of a after hard deletion
|
2023-04-24 13:18:14 -05:00
|
|
|
(let [data {::th/type :get-projects
|
|
|
|
::rpc/profile-id (:id profile1)
|
2023-01-02 09:49:08 -05:00
|
|
|
:team-id (:id team)}
|
2023-04-24 13:18:14 -05:00
|
|
|
out (th/command! data)]
|
2021-06-07 09:51:09 -05:00
|
|
|
;; (th/print-result! out)
|
2021-02-11 11:57:41 -05:00
|
|
|
|
2022-09-26 16:56:58 -05:00
|
|
|
(t/is (not (th/success? out)))
|
|
|
|
(let [edata (-> out :error ex-data)]
|
2023-11-29 06:53:34 -05:00
|
|
|
(t/is (= :not-found (:type edata)))))))
|
2021-02-11 11:57:41 -05:00
|
|
|
|
2022-02-15 08:18:45 -05:00
|
|
|
(t/deftest query-team-invitations
|
2022-09-26 16:56:58 -05:00
|
|
|
(let [prof (th/create-profile* 1 {:is-active true})
|
|
|
|
team (th/create-team* 1 {:profile-id (:id prof)})
|
2023-01-02 09:49:08 -05:00
|
|
|
data {::th/type :get-team-invitations
|
|
|
|
::rpc/profile-id (:id prof)
|
2022-02-15 08:18:45 -05:00
|
|
|
:team-id (:id team)}]
|
|
|
|
|
2022-09-26 16:56:58 -05:00
|
|
|
;; insert an entry on the database with an enabled invitation
|
2022-02-15 08:18:45 -05:00
|
|
|
(db/insert! th/*pool* :team-invitation
|
2022-09-26 16:56:58 -05:00
|
|
|
{:team-id (:team-id data)
|
|
|
|
:email-to "test1@mail.com"
|
|
|
|
:role "editor"
|
|
|
|
:valid-until (dt/in-future "48h")})
|
2021-02-11 11:57:41 -05:00
|
|
|
|
2022-09-26 16:56:58 -05:00
|
|
|
;; insert an entry on the database with an expired invitation
|
2022-02-15 08:18:45 -05:00
|
|
|
(db/insert! th/*pool* :team-invitation
|
|
|
|
{:team-id (:team-id data)
|
|
|
|
:email-to "test2@mail.com"
|
|
|
|
:role "editor"
|
|
|
|
:valid-until (dt/in-past "48h")})
|
|
|
|
|
2023-01-02 09:49:08 -05:00
|
|
|
(let [out (th/command! data)]
|
2022-09-26 16:56:58 -05:00
|
|
|
(t/is (th/success? out))
|
2022-02-15 08:18:45 -05:00
|
|
|
(let [result (:result out)
|
2022-09-26 16:56:58 -05:00
|
|
|
one (first result)
|
|
|
|
two (second result)]
|
2022-02-15 08:18:45 -05:00
|
|
|
(t/is (= 2 (count result)))
|
|
|
|
(t/is (= "test1@mail.com" (:email one)))
|
|
|
|
(t/is (= "test2@mail.com" (:email two)))
|
|
|
|
(t/is (false? (:expired one)))
|
|
|
|
(t/is (true? (:expired two)))))))
|
|
|
|
|
|
|
|
(t/deftest update-team-invitation-role
|
2022-09-26 16:56:58 -05:00
|
|
|
(let [prof (th/create-profile* 1 {:is-active true})
|
|
|
|
team (th/create-team* 1 {:profile-id (:id prof)})
|
2022-02-15 08:18:45 -05:00
|
|
|
data {::th/type :update-team-invitation-role
|
2023-01-02 09:49:08 -05:00
|
|
|
::rpc/profile-id (:id prof)
|
2022-02-15 08:18:45 -05:00
|
|
|
:team-id (:id team)
|
|
|
|
:email "TEST1@mail.com"
|
|
|
|
:role :admin}]
|
|
|
|
|
2022-09-26 16:56:58 -05:00
|
|
|
;; insert an entry on the database with an invitation
|
2022-02-15 08:18:45 -05:00
|
|
|
(db/insert! th/*pool* :team-invitation
|
|
|
|
{:team-id (:team-id data)
|
|
|
|
:email-to "test1@mail.com"
|
|
|
|
:role "editor"
|
|
|
|
:valid-until (dt/in-future "48h")})
|
|
|
|
|
2023-01-02 09:49:08 -05:00
|
|
|
(let [out (th/command! data)
|
2022-09-26 16:56:58 -05:00
|
|
|
;; retrieve the value from the database and check its content
|
|
|
|
res (db/get* th/*pool* :team-invitation
|
|
|
|
{:team-id (:team-id data) :email-to "test1@mail.com"})]
|
|
|
|
(t/is (th/success? out))
|
2022-02-15 08:18:45 -05:00
|
|
|
(t/is (nil? (:result out)))
|
2022-09-26 16:56:58 -05:00
|
|
|
(t/is (= "admin" (:role res))))))
|
2022-02-17 05:57:25 -05:00
|
|
|
|
|
|
|
(t/deftest delete-team-invitation
|
2022-09-26 16:56:58 -05:00
|
|
|
(let [prof (th/create-profile* 1 {:is-active true})
|
|
|
|
team (th/create-team* 1 {:profile-id (:id prof)})
|
2022-02-17 05:57:25 -05:00
|
|
|
data {::th/type :delete-team-invitation
|
2023-01-02 09:49:08 -05:00
|
|
|
::rpc/profile-id (:id prof)
|
2022-02-17 05:57:25 -05:00
|
|
|
:team-id (:id team)
|
|
|
|
:email "TEST1@mail.com"}]
|
|
|
|
|
2022-09-26 16:56:58 -05:00
|
|
|
;; insert an entry on the database with an invitation
|
2022-02-17 05:57:25 -05:00
|
|
|
(db/insert! th/*pool* :team-invitation
|
|
|
|
{:team-id (:team-id data)
|
|
|
|
:email-to "test1@mail.com"
|
|
|
|
:role "editor"
|
|
|
|
:valid-until (dt/in-future "48h")})
|
|
|
|
|
2023-01-02 09:49:08 -05:00
|
|
|
(let [out (th/command! data)
|
2022-09-26 16:56:58 -05:00
|
|
|
;; retrieve the value from the database and check its content
|
|
|
|
res (db/get* th/*pool* :team-invitation
|
|
|
|
{:team-id (:team-id data) :email-to "test1@mail.com"})]
|
|
|
|
|
|
|
|
(t/is (th/success? out))
|
2022-02-17 05:57:25 -05:00
|
|
|
(t/is (nil? (:result out)))
|
2022-09-26 16:56:58 -05:00
|
|
|
(t/is (nil? res)))))
|