Fix and uncomment tests in contacts.events and utils.pre-receiver

I have uncommented the two namespaces:

contacts.events was mainly an issue with schema validation
and a few features not covered by tests.

the tests in pre-receiver were actually passing, the issue was a
test suite in wallet.events which was run asychronously by re-frame
which meant the http request in the fx was actually being fired.

Signed-off-by: Oskar Thoren <ot@oskarthoren.com>
This commit is contained in:
Andrea Maria Piana 2018-01-12 08:24:27 +00:00 committed by Oskar Thoren
parent 86be7071a0
commit c8ef43fb67
No known key found for this signature in database
GPG Key ID: 5128AB0637CD85AF
3 changed files with 124 additions and 137 deletions

View File

@ -16,54 +16,26 @@
:address nil :address nil
:name "Browse" :name "Browse"
:global-command :command { 247 { "browse" {:description "Launch the browser"
{ :bot "browse"
:description "Launch the browser" :color "#ffa500"
:sequential-params false :name "global"
:color "#ffa500" :params
:name "global" {:0 {:name "url"
:params :type "text"
{ :placeholder "URL"}}
:0 :icon nil
{ :title "Browser"
:name "url" :has-handler false
:type "text" :fullscreen true
:placeholder "URL"}} :suggestions-trigger "on-change"}}}
:icon nil
:title "Browser"
:has-handler false
:fullscreen true
:suggestions-trigger "on-change"}
:dapp-url nil :dapp-url nil
:dapp-hash nil :dapp-hash nil
:commands
{
:location
{
:description "Share your location"
:sequential-params true
:color nil
:name "location"
:params
{
:0
{
:name "address"
:type "text"
:placeholder "address"}}
:icon nil
:title "Location"
:has-handler false
:fullscreen true
:owner-id "browse"
:suggestions-trigger "on-change"}}
:photo-path nil :photo-path nil
:description "browser contact"
:debug? false :debug? false
:status nil :status nil
:bot-url "local://browse-bot" :bot-url "local://browse-bot"
:responses {}
:pending? false :pending? false
:whisper-identity "browse" :whisper-identity "browse"
:last-online 0 :last-online 0
@ -72,27 +44,6 @@
:private-key nil :private-key nil
:public-key nil}) :public-key nil})
(def browse-global-commands
{:browse
{
:description "Launch the browser"
:bot "browse"
:color "#ffa500"
:name "global"
:params
[
{
:name "url"
:placeholder "URL"
:type "text"}]
:type :command
:title "Browser"
:sequential-params false
:icon nil
:has-handler false
:fullscreen true
:suggestions-trigger "on-change"}})
(def test-contact-group (def test-contact-group
{:group-id "1501682106404-685e041e-38e7-593e-b42c-fb4cabd7faa4" {:group-id "1501682106404-685e041e-38e7-593e-b42c-fb4cabd7faa4"
:name "Test" :name "Test"
@ -118,24 +69,45 @@
{:identity "Commiteth"}] {:identity "Commiteth"}]
:pending? false}) :pending? false})
(def wallet-contact (def demo-bot-contact
{:address nil {:address nil
:name "Wallet" :name "Demo bot"
:global-command nil :description nil
:hide-contact? false
:dapp-hash nil :dapp-hash nil
:photo-path "icon_wallet_avatar" :photo-path nil
:dapp-url nil :dapp-url nil
:bot-url nil :bot-url "local://demo-bot"
:whisper-identity "wallet" :whisper-identity "demo-bot"
:dapp? true
:pending? false
:unremovable? false
:public-key nil})
(def browse-default-contact
{:address nil
:name "Browse"
:description nil
:hide-contact? true
:dapp-hash nil
:photo-path nil
:dapp-url nil
:bot-url "local://browse-bot"
:whisper-identity "browse"
:pending? false
:dapp? true :dapp? true
:pending? true
:unremovable? true :unremovable? true
:public-key nil}) :public-key nil})
(def contacts-browse-wallet (def console-contact
{"browse" browse-contact-from-realm-db {:whisper-identity "console"
"wallet" wallet-contact}) :name "Console"
:photo-path "console"
:dapp? true
:unremovable? true
:bot-url "local://console-bot"
:status "intro-status"
:pending? false})
(defn test-fixtures [] (defn test-fixtures []
(rf/reg-fx ::events/init-store #()) (rf/reg-fx ::events/init-store #())
@ -157,6 +129,11 @@
(fn [coeffects _] (fn [coeffects _]
(assoc coeffects :all-contacts [browse-contact-from-realm-db]))) (assoc coeffects :all-contacts [browse-contact-from-realm-db])))
(rf/reg-cofx
:get-local-storage-data
(fn [cofx]
(assoc cofx :get-local-storage-data (constantly nil))))
(rf/reg-cofx (rf/reg-cofx
::group-events/get-all-contact-groups ::group-events/get-all-contact-groups
(fn [coeffects _] (fn [coeffects _]
@ -166,10 +143,9 @@
(rf/reg-cofx (rf/reg-cofx
::contacts-events/get-default-contacts-and-groups ::contacts-events/get-default-contacts-and-groups
(fn [coeffects _] (fn [coeffects _]
(assoc coeffects :default-contacts (update (select-keys js-res/default-contacts [:wallet]) (assoc coeffects
:wallet :default-contacts (select-keys js-res/default-contacts [:browse :demo-bot])
dissoc :add-chat? :bot-url) :default-groups (select-keys js-res/default-contact-groups [:dapps])))))
:default-groups (select-keys js-res/default-contact-groups [:dapps])))))
(deftest contacts-events (deftest contacts-events
"load-contacts "load-contacts
@ -183,7 +159,6 @@
add-contact-handler (add-pending-contact, status-im.contacts.events/add-new-contact add-contact-handler (add-pending-contact, status-im.contacts.events/add-new-contact
status-im.contacts.events/send-contact-request ;TODO :discoveries-send-portions) status-im.contacts.events/send-contact-request ;TODO :discoveries-send-portions)
create-new-contact-group create-new-contact-group
set-contact-group-name set-contact-group-name
save-contact-group-order save-contact-group-order
@ -199,19 +174,16 @@
(rf/dispatch [:initialize-db]) (rf/dispatch [:initialize-db])
(let [contacts (rf/subscribe [:get-contacts]) (let [contacts (rf/subscribe [:get-contacts])
global-commands (rf/subscribe [:get :global-commands])
contact-groups (rf/subscribe [:get-contact-groups])] contact-groups (rf/subscribe [:get-contact-groups])]
(testing ":load-contacts event" (testing ":load-contacts event"
;;Assert the initial state ;;Assert the initial state
(is (and (map? @contacts) (empty? @contacts))) (is (and (map? @contacts) (empty? @contacts)))
(is (nil? @global-commands))
(rf/dispatch [:load-contacts]) (rf/dispatch [:load-contacts])
(is (= {"browse" browse-contact-from-realm-db} @contacts)) (is (= {"browse" browse-contact-from-realm-db} @contacts)))
(is (= browse-global-commands @global-commands)))
(testing ":load-contact-groups event" (testing ":load-contact-groups event"
@ -240,10 +212,17 @@
(:group-id test-contact-group) test-contact-group} (:group-id test-contact-group) test-contact-group}
@contact-groups)) @contact-groups))
(is (= contacts-browse-wallet (testing "it adds a default contact"
@contacts))) (is (= demo-bot-contact (get @contacts "demo-bot"))))
(testing "it replaces existing contacts"
(is (= browse-default-contact (get @contacts "browse"))))
(testing "it adds the console bot"
(is (= console-contact (get @contacts "console"))))
(testing "it does not add any other contact"
(is (= 3 (count (keys @contacts))))))
(let [new-contact-public-key "0x048f7d5d4bda298447bbb5b021a34832509bd1a8dbe4e06f9b7223d00a59b6dc14f6e142b21d3220ceb3155a6d8f40ec115cd96394d3cc7c55055b433a1758dc74" (let [new-contact-public-key "0x048f7d5d4bda298447bbb5b021a34832509bd1a8dbe4e06f9b7223d00a59b6dc14f6e142b21d3220ceb3155a6d8f40ec115cd96394d3cc7c55055b433a1758dc74"
new-contact-address "5392ccb49f2e9fef8b8068b3e3b5ba6c020a9aca" new-contact-address "5392ccb49f2e9fef8b8068b3e3b5ba6c020a9aca"
@ -265,10 +244,14 @@
(rf/dispatch [:add-contact-handler new-contact-public-key]) (rf/dispatch [:add-contact-handler new-contact-public-key])
(is (= new-contact (assoc @contact :photo-path "" :name ""))) (testing "it returns the new contact from the contact-by-identity sub"
(is (= new-contact (assoc @contact :photo-path "" :name ""))))
(is (= (assoc contacts-browse-wallet new-contact-public-key new-contact) (testing "it adds the new contact to the list of contacts"
(update @contacts new-contact-public-key assoc :photo-path "" :name "")))) (is (= new-contact
(-> @contacts
(get new-contact-public-key)
(assoc :photo-path "" :name ""))))))
(testing ":contact-request-received event" (testing ":contact-request-received event"
@ -279,23 +262,24 @@
;;TODO :update-chat! ;;TODO :update-chat!
(rf/reg-event-db :update-chat! (fn [db _] db)) (rf/reg-event-db :update-chat! (fn [db _] db))
(let [recieved-contact {:name "test" (let [received-contact {:name "test"
:profile-image "" :profile-image ""
:address new-contact-address :address new-contact-address
:status "test status" :status "test status"
:fcm-token "0xwhatever"} :fcm-token "0xwhatever"}
recieved-contact' (merge new-contact received-contact' (merge new-contact
(dissoc recieved-contact :profile-image) (dissoc received-contact :profile-image)
{:public-key new-contact-public-key {:public-key new-contact-public-key
:private-key ""})] :private-key ""})]
(rf/dispatch [:contact-request-received {:from new-contact-public-key (rf/dispatch [:contact-request-received {:from new-contact-public-key
:payload {:contact recieved-contact :payload {:contact received-contact
:keypair {:public new-contact-public-key :keypair {:public new-contact-public-key
:private ""}}}]) :private ""}}}])
(is (= (assoc contacts-browse-wallet new-contact-public-key recieved-contact') (testing "it adds the new contact to the list of contacts"
@contacts)) (is (= received-contact'
(get @contacts new-contact-public-key))))
(testing ":contact-update-received event" (testing ":contact-update-received event"
@ -304,9 +288,10 @@
;; :update-contact! ;; :update-contact!
;;TODO :update-chat! ;;TODO :update-chat!
(let [timestamp (datetime/now-ms) (let [timestamp (datetime/now-ms)
recieved-contact'' (assoc recieved-contact' :last-updated timestamp received-contact'' (assoc received-contact'
:status "new status" :last-updated timestamp
:name "new name")] :status "new status"
:name "new name")]
(rf/dispatch [:contact-update-received {:from new-contact-public-key (rf/dispatch [:contact-update-received {:from new-contact-public-key
:payload {:content {:profile {:profile-image "" :payload {:content {:profile {:profile-image ""
@ -314,8 +299,9 @@
:name "new name"}} :name "new name"}}
:timestamp timestamp}}]) :timestamp timestamp}}])
(is (= (assoc contacts-browse-wallet new-contact-public-key recieved-contact'') (testing "it updates the contact and set the :last-updated key"
@contacts)) (is (= received-contact''
(get @contacts new-contact-public-key))))
(testing ":hide-contact event" (testing ":hide-contact event"
@ -327,9 +313,9 @@
(rf/dispatch [:hide-contact @contact]) (rf/dispatch [:hide-contact @contact])
(is (= (assoc contacts-browse-wallet new-contact-public-key (assoc recieved-contact'' (testing "it sets the pending? flag to true"
:pending? true)) (is (= (assoc received-contact'' :pending? true)
@contacts))) (get @contacts new-contact-public-key)))))
(testing ":add-contact-handler event - :add-pending-contact" (testing ":add-contact-handler event - :add-pending-contact"
@ -343,22 +329,22 @@
(rf/dispatch [:add-contact-handler new-contact-public-key]) (rf/dispatch [:add-contact-handler new-contact-public-key])
(is (= (assoc contacts-browse-wallet new-contact-public-key (assoc recieved-contact'' (testing "it sets the pending? flag to false"
:pending? false)) (is (= (assoc received-contact'' :pending? false)
@contacts))) (get @contacts new-contact-public-key)))))
(testing ":create-new-contact-group event" (testing ":create-new-contact-group event"
(let [new-group-name "new group"] (let [new-group-name "new group"]
(rf/dispatch [:select-contact new-contact-public-key]) (rf/dispatch [:select-contact new-contact-public-key])
(rf/dispatch [:select-contact "wallet"]) (rf/dispatch [:select-contact "demo-bot"])
(rf/dispatch [:select-contact "browse"]) (rf/dispatch [:select-contact "browse"])
(rf/dispatch [:deselect-contact "browse"]) (rf/dispatch [:deselect-contact "browse"])
(rf/dispatch [:create-new-contact-group new-group-name]) (rf/dispatch [:create-new-contact-group new-group-name])
(rf/dispatch [:deselect-contact "wallet"]) (rf/dispatch [:deselect-contact "demo-bot"])
(rf/dispatch [:deselect-contact new-contact-public-key]) (rf/dispatch [:deselect-contact new-contact-public-key])
(let [new-group-id (->> @contact-groups (let [new-group-id (->> @contact-groups
@ -371,7 +357,7 @@
:order 2 :order 2
:timestamp 0 :timestamp 0
:contacts [{:identity new-contact-public-key} :contacts [{:identity new-contact-public-key}
{:identity "wallet"}]} {:identity "demo-bot"}]}
groups-with-new-group {new-group-id new-group groups-with-new-group {new-group-id new-group
"dapps" dapps-contact-group "dapps" dapps-contact-group
(:group-id test-contact-group) test-contact-group}] (:group-id test-contact-group) test-contact-group}]
@ -385,8 +371,9 @@
(testing ":set-contact-group-name event" (testing ":set-contact-group-name event"
(rf/reg-event-db ::prepare-group-name (rf/reg-event-db ::prepare-group-name
(fn [db _] (assoc db :new-chat-name "new group name" (fn [db _] (assoc db
:group/contact-group-id new-group-id))) :new-chat-name "new group name"
:group/contact-group-id new-group-id)))
(rf/dispatch [::prepare-group-name]) (rf/dispatch [::prepare-group-name])
(rf/dispatch [:set-contact-group-name]) (rf/dispatch [:set-contact-group-name])
@ -402,10 +389,10 @@
(rf/reg-event-db ::prepare-groups-order (rf/reg-event-db ::prepare-groups-order
(fn [db _] (fn [db _]
(assoc db :group/groups-order (assoc db :group/groups-order
(->> (vals (:group/contact-groups db)) (->> (vals (:group/contact-groups db))
(remove :pending?) (remove :pending?)
(sort-by :order >) (sort-by :order >)
(map :group-id))))) (map :group-id)))))
(rf/dispatch [::prepare-groups-order]) (rf/dispatch [::prepare-groups-order])
(rf/dispatch [:change-contact-group-order 1 0]) (rf/dispatch [:change-contact-group-order 1 0])
@ -420,7 +407,7 @@
(rf/dispatch [:deselect-contact "browse"]) (rf/dispatch [:deselect-contact "browse"])
(is (= (update groups-with-new-group'' new-group-id assoc :contacts [{:identity new-contact-public-key} (is (= (update groups-with-new-group'' new-group-id assoc :contacts [{:identity new-contact-public-key}
{:identity "wallet"} {:identity "demo-bot"}
{:identity "browse"}]) {:identity "browse"}])
@contact-groups))) @contact-groups)))
@ -436,7 +423,7 @@
(rf/dispatch [:add-contacts-to-group new-group-id ["browse"]]) (rf/dispatch [:add-contacts-to-group new-group-id ["browse"]])
(is (= (update groups-with-new-group'' new-group-id assoc :contacts [{:identity new-contact-public-key} (is (= (update groups-with-new-group'' new-group-id assoc :contacts [{:identity new-contact-public-key}
{:identity "wallet"} {:identity "demo-bot"}
{:identity "browse"}]) {:identity "browse"}])
@contact-groups)) @contact-groups))

View File

@ -35,7 +35,7 @@
'status-im.test.utils.async 'status-im.test.utils.async
'status-im.test.chat.events 'status-im.test.chat.events
'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.profile.events
'status-im.test.wallet.events 'status-im.test.wallet.events
'status-im.test.data-store.realm.core 'status-im.test.data-store.realm.core
@ -47,7 +47,7 @@
'status-im.test.utils.utils 'status-im.test.utils.utils
'status-im.test.utils.money 'status-im.test.utils.money
'status-im.test.utils.clocks 'status-im.test.utils.clocks
;;'status-im.test.utils.pre-receiver 'status-im.test.utils.pre-receiver
'status-im.test.utils.ethereum.eip681 'status-im.test.utils.ethereum.eip681
'status-im.test.utils.ethereum.core 'status-im.test.utils.ethereum.core
'status-im.test.utils.random 'status-im.test.utils.random

View File

@ -13,21 +13,21 @@
update-prices-fail update-prices-fail
clear-error" clear-error"
(run-test-sync (run-test-sync
(re-frame/reg-fx ::events/init-store #()) (re-frame/reg-fx ::events/init-store #())
(re-frame/reg-fx :get-prices #()) (re-frame/reg-fx :get-prices #())
(re-frame/reg-fx :get-balance #()) (re-frame/reg-fx :get-balance #())
(re-frame/dispatch [:initialize-db]) (re-frame/dispatch [:initialize-db])
(let [error (re-frame/subscribe [:wallet/error-message?]) (let [error (re-frame/subscribe [:wallet/error-message?])
message "failed balance update"] message "failed balance update"]
(re-frame/dispatch [:update-balance-fail message]) (re-frame/dispatch [:update-balance-fail message])
(is (= message @error))) (is (= message @error)))
(let [error (re-frame/subscribe [:wallet/error-message?])] (let [error (re-frame/subscribe [:wallet/error-message?])]
(re-frame/dispatch [:update-wallet]) (re-frame/dispatch [:update-wallet])
(is (nil? @error))) (is (nil? @error)))
(let [error (re-frame/subscribe [:wallet/error-message?]) (let [error (re-frame/subscribe [:wallet/error-message?])
message "failed price update"] message "failed price update"]
(re-frame/dispatch [:update-prices-fail message]) (re-frame/dispatch [:update-prices-fail message])
(is (= message @error)))) (is (= message @error)))
(let [error (re-frame/subscribe [:wallet/error-message?])] (let [error (re-frame/subscribe [:wallet/error-message?])]
(re-frame/dispatch [:update-wallet]) (re-frame/dispatch [:update-wallet])
(is (nil? @error)))) (is (nil? @error)))))