Skip to content

Commit

Permalink
[#18788] fix: add contract test
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsen-ghafouri committed Feb 19, 2024
1 parent c4ce400 commit 2cafec5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/status_im/contexts/profile/edit/bio/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
[utils.re-frame :as rf]))

(rf/reg-event-fx :profile/edit-profile-bio-success
(fn [_ [added?]]
{:fx [[:dispatch [:navigate-back]]
(fn [_ [{:keys [bio added?]}]]
{:fx [[:dispatch [:profile/save-local-profile-bio bio]]
[:dispatch [:navigate-back]]
[:dispatch
[:toasts/upsert
{:type :positive
Expand All @@ -14,13 +15,18 @@
(i18n/label :t/bio-added)
(i18n/label :t/bio-updated))}]]]}))

(rf/reg-event-fx :profile/save-local-profile-bio
(fn [{:keys [db]} [bio]]
{:db (assoc-in db [:profile/profile :bio] bio)}))

(defn edit-profile-bio
[{:keys [db]} [new-bio]]
(let [{:keys [bio]} (:profile/profile db)]
{:db (assoc-in db [:profile/profile :bio] new-bio)
:fx [[:json-rpc/call
{:fx [[:json-rpc/call
[{:method "wakuext_setBio"
:params [new-bio]
:on-success [:profile/edit-profile-bio-success (string/blank? bio)]}]]]}))
:on-success [:profile/edit-profile-bio-success
{:bio new-bio
:added? (string/blank? bio)}]}]]]}))

(rf/reg-event-fx :profile/edit-bio edit-profile-bio)
4 changes: 3 additions & 1 deletion src/status_im/contexts/profile/edit/bio/events_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
:fx [[:json-rpc/call
[{:method "wakuext_setBio"
:params [new-bio]
:on-success [:profile/edit-profile-bio-success false]}]]]}]
:on-success [:profile/edit-profile-bio-success
{:bio new-bio
:added? false}]}]]]}]
(is (match? expected
(sut/edit-profile-bio cofx [new-bio])))))
25 changes: 25 additions & 0 deletions src/tests/contract_test/profile_test.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(ns tests.contract-test.profile-test
(:require
[cljs.test :refer [deftest is]]
[day8.re-frame.test :as rf-test]
legacy.status-im.events
[legacy.status-im.multiaccounts.logout.core :as logout]
legacy.status-im.subs.root
status-im.events
status-im.navigation.core
status-im.subs.root
[test-helpers.integration :as h]
[tests.contract-test.utils :as contract-utils]))

(deftest profile-set-bio-contract
(h/log-headline :contract/wakuext_setBio)
(rf-test/run-test-async
(h/with-app-initialized
(h/with-account
(contract-utils/call-rpc-endpoint
{:rpc-endpoint "wakuext_setBio"
:params ["new bio"]
:on-error #(is (nil? %) "Set bio RPC call should have succeeded")})
(h/logout)
(rf-test/wait-for
[::logout/logout-method])))))

0 comments on commit 2cafec5

Please sign in to comment.