[FIX #1668] Prevent UI keys from propagating to account model.
The ```:account-update``` event was being passed the key ```update-status?``` which has nothing to do with an account as represented in the db. This resulted in a spec failure when this key was detected on an attempt to save changes. I've sanitized this event by pulling out the three account keys, ```[:name :photo-path :status]``` that are relevant to ```profile``` and ensuring that only they get passed to ```:account-update```. Profile updates now work as expected. Add tests covering profile events Fix the runner
This commit is contained in:
parent
00ee672c33
commit
6fa9040def
|
@ -8,6 +8,8 @@
|
||||||
[status-im.utils.image-processing :refer [img->base64]]
|
[status-im.utils.image-processing :refer [img->base64]]
|
||||||
[taoensso.timbre :as log]))
|
[taoensso.timbre :as log]))
|
||||||
|
|
||||||
|
(def account-profile-keys [:name :photo-path :status])
|
||||||
|
|
||||||
(reg-fx
|
(reg-fx
|
||||||
:open-image-picker
|
:open-image-picker
|
||||||
;; the image picker is only used here for now, this effect can be use in other scenarios as well
|
;; the image picker is only used here for now, this effect can be use in other scenarios as well
|
||||||
|
@ -40,8 +42,9 @@
|
||||||
:my-profile/edit
|
:my-profile/edit
|
||||||
(fn [{:keys [db]} [_ edit-type edit-value]]
|
(fn [{:keys [db]} [_ edit-type edit-value]]
|
||||||
(let [current-account-id (:accounts/current-account-id db)
|
(let [current-account-id (:accounts/current-account-id db)
|
||||||
current-account (select-keys (get-in db [:accounts/accounts current-account-id])
|
current-account (-> db
|
||||||
[:name :photo-path :status])
|
(get-in [:accounts/accounts current-account-id])
|
||||||
|
(select-keys account-profile-keys))
|
||||||
new-db (-> db
|
new-db (-> db
|
||||||
(update-in [:my-profile/edit] merge current-account)
|
(update-in [:my-profile/edit] merge current-account)
|
||||||
(assoc-in [:my-profile/edit :edit-status?] (= edit-type :status true)))]
|
(assoc-in [:my-profile/edit :edit-status?] (= edit-type :status true)))]
|
||||||
|
@ -75,4 +78,4 @@
|
||||||
(fn [{:keys [db]} _]
|
(fn [{:keys [db]} _]
|
||||||
(let [{:keys [:my-profile/edit]} db]
|
(let [{:keys [:my-profile/edit]} db]
|
||||||
{:dispatch-n [[:check-status-change (:status edit)]
|
{:dispatch-n [[:check-status-change (:status edit)]
|
||||||
[:account-update edit]]})))
|
[:account-update (select-keys edit account-profile-keys)]]})))
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
(ns status-im.test.profile.events
|
||||||
|
(:require [cljs.test :refer [deftest is testing]]
|
||||||
|
reagent.core
|
||||||
|
[re-frame.core :as rf]
|
||||||
|
[day8.re-frame.test :refer [run-test-sync]]
|
||||||
|
status-im.ui.screens.db
|
||||||
|
[status-im.ui.screens.events :as events]
|
||||||
|
[status-im.ui.screens.profile.events :as profile-events]
|
||||||
|
[status-im.ui.screens.accounts.events :as account-events]))
|
||||||
|
|
||||||
|
(def new-account
|
||||||
|
{:address "c296367a939e0957500a25ca89b70bd64b03004e"
|
||||||
|
:signed-up? true
|
||||||
|
:name "Disloyal Trusting Rainbowfish"
|
||||||
|
:updates-private-key "3849071831f581f5e2a4f095a53e0a697144b32ea6de9e92cc08936f2efa40d2f1702bdb131356df0930a3a0d301221f2b5"
|
||||||
|
:updates-public-key "38453ecc298b8b35de00c85d3217f00aa7040a7d3053dbbf6831d03c750df40b27977906692b3b5d6fec8134706b2bf65900c61130047488520cb60080a59b118cb281f3aaf65ba704c7efde8f9357d2b22fe8110b38a4dd714c1c9e108a8b067fe"
|
||||||
|
:photo-path "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAMAAAC7IEhfAAADAFBMVEXw8PDYjLoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKUMBsXBa1BAAAAAASUVORK5CYII="
|
||||||
|
:status "the future starts today, not tomorrow"
|
||||||
|
:public-key "0x04f5722fba79eb36d73263417531007f43d13af76c6233573a8e3e60f667710611feba0785d751b50609bfc0b7cef35448875c5392c0a91948c95798a0ce600847"})
|
||||||
|
|
||||||
|
|
||||||
|
(defn test-fixtures []
|
||||||
|
(rf/reg-fx ::events/init-store #())
|
||||||
|
(rf/reg-fx ::account-events/save-account #())
|
||||||
|
(rf/reg-fx :check-status-change #()))
|
||||||
|
|
||||||
|
(deftest profile-edit-events
|
||||||
|
(run-test-sync
|
||||||
|
(test-fixtures)
|
||||||
|
(let [accounts (rf/subscribe [:get-accounts])
|
||||||
|
address (:address new-account)
|
||||||
|
new-status "It's a new status!"]
|
||||||
|
(rf/dispatch [:initialize-db])
|
||||||
|
(rf/dispatch [:add-account new-account])
|
||||||
|
(rf/dispatch [:set-current-account address])
|
||||||
|
(testing "Setting status"
|
||||||
|
(is (= (:status new-account) (-> @accounts
|
||||||
|
(get address)
|
||||||
|
:status)))
|
||||||
|
(rf/dispatch [:my-profile/update-status new-status])
|
||||||
|
(is (= new-status (-> @accounts
|
||||||
|
(get address)
|
||||||
|
:status))))
|
||||||
|
(testing "Setting phone number"
|
||||||
|
(is (nil? (-> @accounts
|
||||||
|
(get address)
|
||||||
|
:phone)))
|
||||||
|
(rf/dispatch [:set-in [:my-profile/edit :edit-status?] true])
|
||||||
|
(rf/dispatch [:set-in [:my-profile/edit :name] "It's my new name"])
|
||||||
|
(rf/dispatch [:my-profile/save-changes])
|
||||||
|
(is (= "It's my new name" (-> @accounts
|
||||||
|
(get address)
|
||||||
|
:name)))))))
|
|
@ -2,6 +2,7 @@
|
||||||
(:require [doo.runner :refer-macros [doo-tests]]
|
(:require [doo.runner :refer-macros [doo-tests]]
|
||||||
[status-im.test.contacts.events]
|
[status-im.test.contacts.events]
|
||||||
[status-im.test.accounts.events]
|
[status-im.test.accounts.events]
|
||||||
|
[status-im.test.profile.events]
|
||||||
[status-im.test.chat.models.input]
|
[status-im.test.chat.models.input]
|
||||||
[status-im.test.components.main-tabs]
|
[status-im.test.components.main-tabs]
|
||||||
[status-im.test.handlers]
|
[status-im.test.handlers]
|
||||||
|
@ -23,6 +24,7 @@
|
||||||
(doo-tests
|
(doo-tests
|
||||||
'status-im.test.accounts.events
|
'status-im.test.accounts.events
|
||||||
'status-im.test.contacts.events
|
'status-im.test.contacts.events
|
||||||
|
'status-im.test.profile.events
|
||||||
'status-im.test.chat.models.input
|
'status-im.test.chat.models.input
|
||||||
'status-im.test.components.main-tabs
|
'status-im.test.components.main-tabs
|
||||||
'status-im.test.handlers
|
'status-im.test.handlers
|
||||||
|
|
Loading…
Reference in New Issue