accounts tests

This commit is contained in:
Andrey Shovkoplyas 2017-08-21 17:13:40 +03:00 committed by Roman Volosovskyi
parent 92f3f9a4c5
commit 2ff20eb830
3 changed files with 129 additions and 13 deletions

View File

@ -0,0 +1,107 @@
(ns status-im.test.accounts.events
(:require [cljs.test :refer-macros [deftest is testing]]
reagent.core
[re-frame.core :as rf]
[day8.re-frame.test :refer-macros [run-test-sync]]
status-im.ui.screens.db
status-im.ui.screens.subs
[status-im.ui.screens.events :as events]
[status-im.ui.screens.accounts.events :as account-events]))
(def account-from-realm
{:last-updated 1502965625859
:address "f8fa50a736618badf21c9d0e9a7605a2b268789b"
:email nil
:signed-up? true
:phone nil
:name "Sleepy Serene Leopardseal"
:updates-private-key "3849320857de8efe1e1ec57e08e92ed2bce196cb8763756ae4e6e7e011c1d857de0a115b3dc7eff066afe75a8794ea9905b"
:updates-public-key "384975d68aec6426faacf8b4ba2c55d5a84b70a8a26eb616e06e9c9e63f95dfdf1c1c165773e1cdca2d198a0bc5386d8a6f2079414e073b4730c8f4745292a6cdfb3fa28143ad5937128643c6addf356b66962376dc8b12274d9abfb2e1c6447ac3"
:photo-path "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAMAAAC7IEhfAAADAFBMVEXw8PCM2JYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAmBECiQccq18AAAAASUVORK5CYII="
:debug? false
:status "be the hero of your own journey"
:network "testnet"
:public-key "0x049b3a8c04f2c5bccda91c1f5e6434ae72957e93a31c0301b4563eda1d6ce419f63c503ebaee143115f96c1f04f232a7a22ca0454e9ee3d579ad1f870315b151d0"})
(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,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAMAAAC7IEhfAAADAFBMVEXw8PDYjLoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKUMBsXBa1BAAAAAASUVORK5CYII="
: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 ::account-events/broadcast-account-update #())
(rf/reg-fx ::account-events/send-keys-update #())
(rf/reg-cofx
:get-new-keypair!
(fn [coeffects _]
(assoc coeffects :keypair {:public "new public"
:private "new private"})))
(rf/reg-cofx
::account-events/get-all-accounts
(fn [coeffects _]
(assoc coeffects :all-accounts [account-from-realm]))))
(deftest accounts-events
"load-accounts
add-account
account-update
account-update-keys"
(run-test-sync
(test-fixtures)
(rf/dispatch [:initialize-db])
(let [accounts (rf/subscribe [:get-accounts])]
(testing ":load-accounts event"
;;Assert the initial state
(is (and (map? @accounts) (empty? @accounts)))
(rf/dispatch [:load-accounts])
(is (= {(:address account-from-realm) account-from-realm} @accounts)))
(testing ":add-account event"
(let [new-account' (assoc new-account :network "testnet")]
(rf/dispatch [:add-account new-account])
(is (= {(:address account-from-realm) account-from-realm
(:address new-account) new-account'} @accounts))
(testing ":account-update event"
(let [new-account'' (assoc new-account'
:status "new status"
:name "new name")]
(rf/dispatch [:set-current-account (:address new-account)])
(rf/dispatch [:account-update {:status "new status" :name "new name"}])
(is (= {(:address account-from-realm) account-from-realm
(:address new-account) new-account''}
(update @accounts (:address new-account) dissoc :last-updated)))
(testing ":account-update-keys event"
(rf/dispatch [:account-update-keys])
(is (= {(:address account-from-realm) account-from-realm
(:address new-account) (assoc new-account''
:updates-private-key "new private"
:updates-public-key "new public")}
(update @accounts (:address new-account) dissoc :last-updated)))))))))))

View File

@ -1,4 +1,4 @@
(ns status-im.test.contacts.handlers
(ns status-im.test.contacts.events
(:require [cljs.test :refer-macros [deftest is testing]]
reagent.core
[re-frame.core :as rf]
@ -183,9 +183,15 @@
hide-contact (update-contact ;TODO :account-update-keys)
add-contact-handler (add-pending-contact, status-im.contacts.events/add-new-contact
status-im.contacts.events/send-contact-request ;TODO :discoveries-send-portions)
create-new-contact-group
set-contact-group-name
save-contact-group-order"
save-contact-group-order
add-selected-contacts-to-group
remove-contact-from-group
add-contacts-to-group
delete-contact-group"
(run-test-sync

View File

@ -1,6 +1,7 @@
(ns status-im.test.runner
(:require [doo.runner :refer-macros [doo-tests]]
[status-im.test.contacts.handlers]
[status-im.test.contacts.events]
[status-im.test.accounts.events]
[status-im.test.chat.models.input]
[status-im.test.components.main-tabs]
[status-im.test.handlers]
@ -19,7 +20,9 @@
(set! goog.DEBUG false)
(doo-tests 'status-im.test.contacts.handlers
(doo-tests
'status-im.test.accounts.events
'status-im.test.contacts.events
'status-im.test.chat.models.input
'status-im.test.components.main-tabs
'status-im.test.handlers