mirror of
https://github.com/penpot/penpot.git
synced 2025-08-06 14:08:22 +02:00
📎 Fix tests
This commit is contained in:
parent
738cf6407c
commit
9b5a321a62
1 changed files with 49 additions and 53 deletions
|
@ -166,6 +166,7 @@
|
||||||
(t/deftest accept-invitation-tokens
|
(t/deftest accept-invitation-tokens
|
||||||
(let [profile1 (th/create-profile* 1 {:is-active true})
|
(let [profile1 (th/create-profile* 1 {:is-active true})
|
||||||
profile2 (th/create-profile* 2 {:is-active true})
|
profile2 (th/create-profile* 2 {:is-active true})
|
||||||
|
profile3 (th/create-profile* 3 {:is-active true})
|
||||||
|
|
||||||
team (th/create-team* 1 {:profile-id (:id profile1)})
|
team (th/create-team* 1 {:profile-id (:id profile1)})
|
||||||
|
|
||||||
|
@ -181,25 +182,29 @@
|
||||||
:member-email (:email profile2)
|
:member-email (:email profile2)
|
||||||
:member-id (:id profile2)})]
|
:member-id (:id profile2)})]
|
||||||
|
|
||||||
;; --- Verify token as anonymous user
|
(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")})
|
||||||
|
|
||||||
(db/insert! pool :team-invitation
|
(let [data {::th/type :verify-token :token token}
|
||||||
{:team-id (:id team)
|
out (th/command! data)]
|
||||||
:email-to (:email profile2)
|
;; (th/print-result! out)
|
||||||
:role "editor"
|
(t/is (th/success? out))
|
||||||
:valid-until (dt/in-future "48h")})
|
|
||||||
|
|
||||||
(let [data {::th/type :verify-token :token token}
|
(let [result (:result out)]
|
||||||
out (th/command! data)]
|
(t/is (contains? result :invitation-token))
|
||||||
;; (th/print-result! out)
|
(t/is (contains? result :iss))
|
||||||
(t/is (th/success? out))
|
(t/is (contains? result :redirect-to))
|
||||||
(let [result (:result out)]
|
(t/is (contains? result :state))
|
||||||
(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 (= :pending (:state result)))
|
||||||
(t/is (= 2 (count rows)))))
|
(t/is (= :auth-login (:redirect-to result))))
|
||||||
|
|
||||||
|
(let [rows (db/query pool :team-profile-rel {:team-id (:id team)})]
|
||||||
|
(t/is (= 1 (count rows))))))
|
||||||
|
|
||||||
;; Clean members
|
;; Clean members
|
||||||
(db/delete! pool :team-profile-rel
|
(db/delete! pool :team-profile-rel
|
||||||
|
@ -207,46 +212,37 @@
|
||||||
:profile-id (:id profile2)})
|
:profile-id (:id profile2)})
|
||||||
|
|
||||||
|
|
||||||
;; --- Verify token as logged-in user
|
(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))))
|
||||||
|
|
||||||
(db/insert! pool :team-invitation
|
(let [rows (db/query pool :team-profile-rel {:team-id (:id team)})]
|
||||||
{:team-id (:id team)
|
(t/is (= 2 (count rows))))))
|
||||||
:email-to (:email profile2)
|
|
||||||
:role "editor"
|
|
||||||
:valid-until (dt/in-future "48h")})
|
|
||||||
|
|
||||||
(let [data {::th/type :verify-token
|
(t/testing "Verify token as logged-in wrong user"
|
||||||
::rpc/profile-id (:id profile2)
|
(db/insert! pool :team-invitation
|
||||||
:token token}
|
{:team-id (:id team)
|
||||||
out (th/command! data)]
|
:email-to (:email profile3)
|
||||||
;; (th/print-result! out)
|
:role "editor"
|
||||||
(t/is (th/success? out))
|
:valid-until (dt/in-future "48h")})
|
||||||
(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)})]
|
(let [data {::th/type :verify-token
|
||||||
(t/is (= 2 (count rows)))))
|
::rpc/profile-id (:id profile1)
|
||||||
|
:token token}
|
||||||
|
out (th/command! data)]
|
||||||
;; --- Verify token as logged-in wrong user
|
;; (th/print-result! out)
|
||||||
|
(t/is (not (th/success? out)))
|
||||||
(db/insert! pool :team-invitation
|
(let [edata (-> out :error ex-data)]
|
||||||
{:team-id (:id team)
|
(t/is (= :validation (:type edata)))
|
||||||
:email-to (:email profile2)
|
(t/is (= :invalid-token (:code edata))))))
|
||||||
: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)))
|
|
||||||
(t/is (= :invalid-token (:code edata)))))
|
|
||||||
|
|
||||||
)))
|
)))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue