Improve test failure readability (#18049)

Problem: failed equality checks as in "(is (= expected actual))" will give a
single, long line of output that for anything but the simplest data structures
is unreadable by humans, and the output doesn't give a useful diff.

Solution: use library https://github.com/nubank/matcher-combinators and its test
directive "match?" which will pinpoint where two data structures differ. Then,
instead of "(is (= ...", use "(is (match? expected actual)". It works
beautifully.

The library offers other nice matchers, but the majority of the time match? is
sufficient.

Can we use another test runner like Kaocha? kaocha-cljs2
(https://github.com/lambdaisland/kaocha-cljs2) would be able to print better
test errors out of the box, among other features, but I have no clue if it would
work well or at all in our stack (in theory yes, but it's a larger piece of
work).
This commit is contained in:
Icaro Motta 2023-12-05 17:20:54 -03:00 committed by GitHub
parent 6b612588c4
commit 563f1c588d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 335 additions and 277 deletions

View File

@ -62,7 +62,15 @@
;; https://github.com/borkdude/clj-kondo/issues/867 ;; https://github.com/borkdude/clj-kondo/issues/867
:unresolved-symbol {:exclude [PersistentPriorityMap.EMPTY :unresolved-symbol {:exclude [PersistentPriorityMap.EMPTY
number number
status-im.test-helpers/restore-app-db]} status-im.test-helpers/restore-app-db
;; When the namespace
;; matcher-combinators.test is loaded, it
;; extends cljs.test/is macro with
;; directives `match?` and
;; `thrown-match?`.
match?
thrown-match?]}
:unresolved-var {:level :error} :unresolved-var {:level :error}
:unsorted-required-namespaces {:level :error} :unsorted-required-namespaces {:level :error}
:unused-alias {:level :warning} :unused-alias {:level :warning}

View File

@ -641,6 +641,26 @@ keywords and concatenating them into a single string.
``` ```
### Tests ### Tests
#### Prefer `match?` over `=` when comparing data structures
Prefer the `match?` directive over `=` when comparing data structures, otherwise
when the check fails the output can be too difficult to read. `match?` is
defined by library https://github.com/nubank/matcher-combinators.
```clojure
;; bad
(deftest some-test
(let [expected {...}
actual {...}]
(is (= expected actual))))
;; good
(deftest some-test
(let [expected {...}
actual {...}]
(is (match? expected actual))))
```
#### Subscription tests #### Subscription tests
Test [layer-3 subscriptions](https://day8.github.io/re-frame/subscriptions/) by Test [layer-3 subscriptions](https://day8.github.io/re-frame/subscriptions/) by

View File

@ -602,6 +602,15 @@
} }
}, },
{
"path": "nubank/matcher-combinators/3.8.8/matcher-combinators-3.8.8",
"host": "https://repo.clojars.org",
"jar": {
"sha1": "4c94bd510f0c18a20191e46dd6becedebc640bbd",
"sha256": "0wpla2hx0s4mda58ndyd8938zmnz1gyhgfr6pzfphy27xfbvsssl"
}
},
{ {
"path": "org/apache/ant/ant/1.10.11/ant-1.10.11", "path": "org/apache/ant/ant/1.10.11/ant-1.10.11",
"host": "https://repo1.maven.org/maven2", "host": "https://repo1.maven.org/maven2",
@ -746,6 +755,15 @@
} }
}, },
{
"path": "org/clojure/math.combinatorics/0.2.0/math.combinatorics-0.2.0",
"host": "https://repo1.maven.org/maven2",
"jar": {
"sha1": "aa95d25ea98bfe1152ea540f6e58a303c8cacc86",
"sha256": "0qvdsr5ryjmrpz622ivpyq5aayn42y4bk531vbasyj2yj7gcg35h"
}
},
{ {
"path": "org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218", "path": "org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218",
"host": "https://repo1.maven.org/maven2", "host": "https://repo1.maven.org/maven2",

View File

@ -65,6 +65,7 @@ net/cgrand/macrovich/0.2.1/macrovich-0.2.1.jar
net/java/dev/jna/jna/5.12.1/jna-5.12.1.jar net/java/dev/jna/jna/5.12.1/jna-5.12.1.jar
nrepl/bencode/1.1.0/bencode-1.1.0.jar nrepl/bencode/1.1.0/bencode-1.1.0.jar
nrepl/nrepl/1.0.0/nrepl-1.0.0.jar nrepl/nrepl/1.0.0/nrepl-1.0.0.jar
nubank/matcher-combinators/3.8.8/matcher-combinators-3.8.8.jar
org/apache/ant/ant/1.10.11/ant-1.10.11.jar org/apache/ant/ant/1.10.11/ant-1.10.11.jar
org/apache/ant/ant-launcher/1.10.11/ant-launcher-1.10.11.jar org/apache/ant/ant-launcher/1.10.11/ant-launcher-1.10.11.jar
org/babashka/sci/0.7.38/sci-0.7.38.jar org/babashka/sci/0.7.38/sci-0.7.38.jar
@ -81,6 +82,7 @@ org/clojure/data.json/2.4.0/data.json-2.4.0.jar
org/clojure/data.priority-map/1.1.0/data.priority-map-1.1.0.jar org/clojure/data.priority-map/1.1.0/data.priority-map-1.1.0.jar
org/clojure/google-closure-library/0.0-20230227-c7c0a541/google-closure-library-0.0-20230227-c7c0a541.jar org/clojure/google-closure-library/0.0-20230227-c7c0a541/google-closure-library-0.0-20230227-c7c0a541.jar
org/clojure/google-closure-library-third-party/0.0-20230227-c7c0a541/google-closure-library-third-party-0.0-20230227-c7c0a541.jar org/clojure/google-closure-library-third-party/0.0-20230227-c7c0a541/google-closure-library-third-party-0.0-20230227-c7c0a541.jar
org/clojure/math.combinatorics/0.2.0/math.combinatorics-0.2.0.jar
org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.jar org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.jar
org/clojure/test.check/1.1.1/test.check-1.1.1.jar org/clojure/test.check/1.1.1/test.check-1.1.1.jar
org/clojure/tools.analyzer/1.1.0/tools.analyzer-1.1.0.jar org/clojure/tools.analyzer/1.1.0/tools.analyzer-1.1.0.jar

View File

@ -17,6 +17,7 @@
[cider/piggieback "0.4.1"] [cider/piggieback "0.4.1"]
[org.slf4j/slf4j-nop "2.0.9"] [org.slf4j/slf4j-nop "2.0.9"]
[re-frisk-remote "1.6.0"] [re-frisk-remote "1.6.0"]
[nubank/matcher-combinators "3.8.8"]
;; Use the same version specified in the Nix dependency. ;; Use the same version specified in the Nix dependency.
[clj-kondo/clj-kondo "2023.09.07"] [clj-kondo/clj-kondo "2023.09.07"]

View File

@ -1,6 +1,7 @@
(ns status-im2.contexts.add-new-contact.events-test (ns status-im2.contexts.add-new-contact.events-test
(:require (:require
[cljs.test :refer-macros [deftest are]] [cljs.test :refer-macros [deftest are]]
matcher-combinators.test
[status-im2.contexts.add-new-contact.events :as events])) [status-im2.contexts.add-new-contact.events :as events]))
(def user-ukey (def user-ukey
@ -18,10 +19,10 @@
;;; unit tests (no app-db involved) ;;; unit tests (no app-db involved)
(deftest validate-contact-test (deftest validate-contact-test
(are [i e] (= (events/validate-contact (events/init-contact (are [i e] (match? (events/validate-contact (events/init-contact
{:user-public-key user-ukey {:user-public-key user-ukey
:input i})) :input i}))
(events/init-contact e)) (events/init-contact e))
"" {:user-public-key user-ukey "" {:user-public-key user-ukey
:input "" :input ""
@ -90,7 +91,7 @@
(deftest set-new-identity-test (deftest set-new-identity-test
(with-redefs [events/dispatcher (fn [& args] args)] (with-redefs [events/dispatcher (fn [& args] args)]
(are [i edb] (= (events/set-new-identity {:db db} i nil) edb) (are [i edb] (match? (events/set-new-identity {:db db} i nil) edb)
"" {:db db} "" {:db db}

View File

@ -1,6 +1,7 @@
(ns status-im2.contexts.chat.composer.link-preview.events-test (ns status-im2.contexts.chat.composer.link-preview.events-test
(:require (:require
[cljs.test :refer [deftest is testing]] [cljs.test :refer [deftest is testing]]
matcher-combinators.test
[status-im2.contexts.chat.composer.link-preview.events :as events])) [status-im2.contexts.chat.composer.link-preview.events :as events]))
(def url-github "https://github.com") (def url-github "https://github.com")
@ -20,17 +21,17 @@
(let [cofx {:db {:chat/link-previews {:unfurled {} (let [cofx {:db {:chat/link-previews {:unfurled {}
:cache {} :cache {}
:request-id "123"}}}] :request-id "123"}}}]
(is (= {:db {:chat/link-previews {:cache {}}}} (is (match? {:db {:chat/link-previews {:cache {}}}}
(events/unfurl-urls cofx " "))))) (events/unfurl-urls cofx " ")))))
(testing "fetches parsed URLs" (testing "fetches parsed URLs"
(let [cofx {:db {:chat/link-previews {:unfurled {} (let [cofx {:db {:chat/link-previews {:unfurled {}
:cache {} :cache {}
:request-id "123"}}}] :request-id "123"}}}]
(is (= {:json-rpc/call [{:method "wakuext_getTextURLs" (is (match? {:json-rpc/call [{:method "wakuext_getTextURLs"
:params [url-github]}]} :params [url-github]}]}
(remove-rpc-callbacks (remove-rpc-callbacks
(events/unfurl-urls cofx url-github))))))) (events/unfurl-urls cofx url-github)))))))
(deftest unfurl-parsed-urls-test (deftest unfurl-parsed-urls-test
(with-redefs [events/new-request-id (constantly request-id)] (with-redefs [events/new-request-id (constantly request-id)]
@ -38,30 +39,30 @@
(let [cofx {:db {:chat/link-previews (let [cofx {:db {:chat/link-previews
{:cache {} {:cache {}
:unfurled []}}}] :unfurled []}}}]
(is (= {:db {:chat/link-previews (is (match? {:db {:chat/link-previews
{:request-id request-id {:request-id request-id
:cache {} :cache {}
:unfurled [{:url url-github :loading? true} :unfurled [{:url url-github :loading? true}
{:url url-gitlab :loading? true}]}} {:url url-gitlab :loading? true}]}}
:json-rpc/call [{:method "wakuext_unfurlURLs" :json-rpc/call [{:method "wakuext_unfurlURLs"
:params [[url-github url-gitlab]]}]} :params [[url-github url-gitlab]]}]}
(remove-rpc-callbacks (remove-rpc-callbacks
(events/unfurl-parsed-urls cofx [url-github url-gitlab])))))) (events/unfurl-parsed-urls cofx [url-github url-gitlab]))))))
(testing "nothing unfurled, 1 cached URL and the other stale" (testing "nothing unfurled, 1 cached URL and the other stale"
(let [cache {url-github preview-github} (let [cache {url-github preview-github}
cofx {:db {:chat/link-previews cofx {:db {:chat/link-previews
{:cache cache {:cache cache
:unfurled []}}}] :unfurled []}}}]
(is (= {:db {:chat/link-previews (is (match? {:db {:chat/link-previews
{:request-id request-id {:request-id request-id
:cache cache :cache cache
:unfurled [preview-github :unfurled [preview-github
{:url url-gitlab :loading? true}]}} {:url url-gitlab :loading? true}]}}
:json-rpc/call [{:method "wakuext_unfurlURLs" :json-rpc/call [{:method "wakuext_unfurlURLs"
:params [[url-gitlab]]}]} :params [[url-gitlab]]}]}
(remove-rpc-callbacks (remove-rpc-callbacks
(events/unfurl-parsed-urls cofx [url-github url-gitlab])))))) (events/unfurl-parsed-urls cofx [url-github url-gitlab]))))))
(testing "does nothing when the URLs are identical to the last cleared ones" (testing "does nothing when the URLs are identical to the last cleared ones"
(let [cofx {:db {:chat/link-previews (let [cofx {:db {:chat/link-previews
@ -75,24 +76,24 @@
cofx {:db {:chat/link-previews cofx {:db {:chat/link-previews
{:cache cache {:cache cache
:unfurled [preview-github]}}}] :unfurled [preview-github]}}}]
(is (= {:db {:chat/link-previews (is (match? {:db {:chat/link-previews
{:request-id request-id {:request-id request-id
:cache cache :cache cache
:unfurled []}}} :unfurled []}}}
(remove-rpc-callbacks (remove-rpc-callbacks
(events/unfurl-parsed-urls cofx [])))))) (events/unfurl-parsed-urls cofx []))))))
(testing "2 unfurled, 2 cached URLs" (testing "2 unfurled, 2 cached URLs"
(let [cache {url-github preview-github url-gitlab preview-gitlab} (let [cache {url-github preview-github url-gitlab preview-gitlab}
cofx {:db {:chat/link-previews cofx {:db {:chat/link-previews
{:cache cache {:cache cache
:unfurled [preview-github preview-gitlab]}}}] :unfurled [preview-github preview-gitlab]}}}]
(is (= {:db {:chat/link-previews (is (match? {:db {:chat/link-previews
{:request-id request-id {:request-id request-id
:cache cache :cache cache
:unfurled [preview-github preview-gitlab]}}} :unfurled [preview-github preview-gitlab]}}}
(remove-rpc-callbacks (remove-rpc-callbacks
(events/unfurl-parsed-urls cofx [url-github url-gitlab])))))) (events/unfurl-parsed-urls cofx [url-github url-gitlab]))))))
(testing "1 unfurled, 1 successful in the cache, 1 failed in the cache" (testing "1 unfurled, 1 successful in the cache, 1 failed in the cache"
(let [cache {url-github preview-github (let [cache {url-github preview-github
@ -100,25 +101,25 @@
cofx {:db {:chat/link-previews cofx {:db {:chat/link-previews
{:cache cache {:cache cache
:unfurled [preview-github]}}}] :unfurled [preview-github]}}}]
(is (= {:db {:chat/link-previews (is (match? {:db {:chat/link-previews
{:request-id request-id {:request-id request-id
:cache cache :cache cache
:unfurled [preview-github]}}} :unfurled [preview-github]}}}
(events/unfurl-parsed-urls cofx [url-github url-gitlab]))))) (events/unfurl-parsed-urls cofx [url-github url-gitlab])))))
(testing "nothing unfurled, 1 failed in the cache" (testing "nothing unfurled, 1 failed in the cache"
(let [cache {url-gitlab (assoc preview-gitlab :failed? true)} (let [cache {url-gitlab (assoc preview-gitlab :failed? true)}
cofx {:db {:chat/link-previews cofx {:db {:chat/link-previews
{:cache cache {:cache cache
:unfurled []}}}] :unfurled []}}}]
(is (= {:db {:chat/link-previews (is (match? {:db {:chat/link-previews
{:request-id request-id {:request-id request-id
:cache cache :cache cache
:unfurled [{:url url-github :loading? true}]}} :unfurled [{:url url-github :loading? true}]}}
:json-rpc/call [{:method "wakuext_unfurlURLs" :json-rpc/call [{:method "wakuext_unfurlURLs"
:params [[url-github]]}]} :params [[url-github]]}]}
(remove-rpc-callbacks (remove-rpc-callbacks
(events/unfurl-parsed-urls cofx [url-github url-gitlab])))))) (events/unfurl-parsed-urls cofx [url-github url-gitlab]))))))
(testing "empties unfurled collection when there are no valid previews" (testing "empties unfurled collection when there are no valid previews"
(let [unknown-url "https://github.abcdef" (let [unknown-url "https://github.abcdef"
@ -127,12 +128,12 @@
cofx {:db {:chat/link-previews cofx {:db {:chat/link-previews
{:cache cache {:cache cache
:unfurled [preview-github]}}}] :unfurled [preview-github]}}}]
(is (= {:db {:chat/link-previews (is (match? {:db {:chat/link-previews
{:request-id request-id {:request-id request-id
:cache cache :cache cache
:unfurled []}}} :unfurled []}}}
(remove-rpc-callbacks (remove-rpc-callbacks
(events/unfurl-parsed-urls cofx [unknown-url])))))))) (events/unfurl-parsed-urls cofx [unknown-url]))))))))
(deftest unfurl-parsed-urls-success-test (deftest unfurl-parsed-urls-success-test
(testing "does nothing if the success request-id is different than the current one" (testing "does nothing if the success request-id is different than the current one"
@ -152,12 +153,12 @@
cofx cofx
request-id request-id
{:linkPreviews [preview-gitlab]})] {:linkPreviews [preview-gitlab]})]
(is (= {:chat/link-previews (is (match? {:chat/link-previews
{:request-id request-id {:request-id request-id
:unfurled [preview-github preview-gitlab] :unfurled [preview-github preview-gitlab]
:cache {url-github preview-github :cache {url-github preview-github
url-gitlab preview-gitlab}}} url-gitlab preview-gitlab}}}
db)))) db))))
(testing "identify and write failed preview in the cache" (testing "identify and write failed preview in the cache"
(let [preview-youtube {:url "https://youtube.com" :thumbnail nil} (let [preview-youtube {:url "https://youtube.com" :thumbnail nil}
@ -172,13 +173,13 @@
request-id request-id
{:linkPreviews [preview-github {:linkPreviews [preview-github
preview-youtube]})] preview-youtube]})]
(is (= {:chat/link-previews (is (match? {:chat/link-previews
{:request-id request-id {:request-id request-id
:unfurled [preview-github preview-youtube] :unfurled [preview-github preview-youtube]
:cache {(:url preview-youtube) preview-youtube :cache {(:url preview-youtube) preview-youtube
url-github preview-github url-github preview-github
url-gitlab {:url "https://gitlab.com" :failed? true}}}} url-gitlab {:url "https://gitlab.com" :failed? true}}}}
db))))) db)))))
(deftest clear-link-previews-test (deftest clear-link-previews-test
(let [cache {url-github preview-github} (let [cache {url-github preview-github}
@ -186,22 +187,22 @@
{:db {:chat/link-previews {:unfurled [preview-github] {:db {:chat/link-previews {:unfurled [preview-github]
:request-id request-id :request-id request-id
:cache cache}}})] :cache cache}}})]
(is (= {:db {:chat/link-previews {:cache cache (is (match? {:db {:chat/link-previews {:cache cache
:cleared #{url-github}}}} :cleared #{url-github}}}}
effects)))) effects))))
(deftest reset-unfurled-test (deftest reset-unfurled-test
(let [cache {url-github preview-github}] (let [cache {url-github preview-github}]
(is (= {:db {:chat/link-previews {:cache cache}}} (is (match? {:db {:chat/link-previews {:cache cache}}}
(events/reset-unfurled (events/reset-unfurled
{:db {:chat/link-previews {:unfurled [preview-github] {:db {:chat/link-previews {:unfurled [preview-github]
:request-id request-id :request-id request-id
:cleared #{url-github} :cleared #{url-github}
:cache cache}}}))))) :cache cache}}})))))
(deftest reset-all-test (deftest reset-all-test
(is (= {:db {:non-related-key :some-value}} (is (match? {:db {:non-related-key :some-value}}
(events/reset-all (events/reset-all
{:db {:non-related-key :some-value {:db {:non-related-key :some-value
:chat/link-previews {:request-id request-id :chat/link-previews {:request-id request-id
:any-other-key "farewell"}}})))) :any-other-key "farewell"}}}))))

View File

@ -1,6 +1,7 @@
(ns status-im2.contexts.communities.discover.events-test (ns status-im2.contexts.communities.discover.events-test
(:require (:require
[cljs.test :refer-macros [deftest are]] [cljs.test :refer-macros [deftest are]]
matcher-combinators.test
[status-im2.contexts.communities.discover.events :as events])) [status-im2.contexts.communities.discover.events :as events]))
(deftest rename-contract-community-key-test (deftest rename-contract-community-key-test
@ -13,7 +14,7 @@
:3f9e77b8-97c7 "3f9e77b8-97c7")) :3f9e77b8-97c7 "3f9e77b8-97c7"))
(deftest rename-contract-community-keys-test (deftest rename-contract-community-keys-test
(are [i e] (= (events/rename-contract-community-keys i) e) (are [i e] (match? (events/rename-contract-community-keys i) e)
{:contractCommunities {:contractCommunities
["0x032aa2439b14eb2caaf724223951da89de1530fbfa5d5a639b93b82cd5341713fd" ["0x032aa2439b14eb2caaf724223951da89de1530fbfa5d5a639b93b82cd5341713fd"

View File

@ -1,5 +1,6 @@
(ns status-im2.contexts.communities.overview.events-test (ns status-im2.contexts.communities.overview.events-test
(:require [cljs.test :refer [deftest is]] (:require [cljs.test :refer [deftest is]]
matcher-combinators.test
[native-module.core :as native-module] [native-module.core :as native-module]
[status-im2.contexts.communities.overview.events :as sut])) [status-im2.contexts.communities.overview.events :as sut]))
@ -14,10 +15,10 @@
:params [account-pub-key community-id []] :params [account-pub-key community-id []]
:on-success [:communities/sign-data community-id password] :on-success [:communities/sign-data community-id password]
:on-error [:communities/requested-to-join-error community-id]}]]]}] :on-error [:communities/requested-to-join-error community-id]}]]]}]
(is (= expected (is (match? expected
(sut/request-to-join cofx (sut/request-to-join cofx
[{:community-id community-id [{:community-id community-id
:password password}]))))) :password password}])))))
(deftest sign-data-test (deftest sign-data-test
(let [cofx {:db {}} (let [cofx {:db {}}
@ -32,8 +33,8 @@
:on-success [:communities/request-to-join-with-signatures :on-success [:communities/request-to-join-with-signatures
community-id addresses-to-reveal] community-id addresses-to-reveal]
:on-error [:communities/requested-to-join-error community-id]}]]]}] :on-error [:communities/requested-to-join-error community-id]}]]]}]
(is (= expected (is (match? expected
(sut/sign-data cofx [community-id password sign-params]))))) (sut/sign-data cofx [community-id password sign-params])))))
(deftest request-to-join-with-signatures-test (deftest request-to-join-with-signatures-test
(let [cofx {:db {}} (let [cofx {:db {}}
@ -49,5 +50,6 @@
:on-success [:communities/requested-to-join] :on-success [:communities/requested-to-join]
:on-error [:communities/requested-to-join-error :on-error [:communities/requested-to-join-error
community-id]}]]]}] community-id]}]]]}]
(is (= expected (is (match? expected
(sut/request-to-join-with-signatures cofx [community-id addresses-to-reveal signatures]))))) (sut/request-to-join-with-signatures cofx
[community-id addresses-to-reveal signatures])))))

View File

@ -1,6 +1,7 @@
(ns status-im2.contexts.shell.activity-center.events-test (ns status-im2.contexts.shell.activity-center.events-test
(:require (:require
[cljs.test :refer [deftest is testing]] [cljs.test :refer [deftest is testing]]
matcher-combinators.test
[status-im2.constants :as constants] [status-im2.constants :as constants]
[status-im2.contexts.shell.activity-center.events :as events] [status-im2.contexts.shell.activity-center.events :as events]
[status-im2.contexts.shell.activity-center.notification-types :as types] [status-im2.contexts.shell.activity-center.notification-types :as types]
@ -14,18 +15,18 @@
(deftest open-activity-center-test (deftest open-activity-center-test
(testing "opens the activity center with default filters" (testing "opens the activity center with default filters"
(is (= {:db {} (is (match? {:db {}
:fx [[:dispatch [:open-modal :activity-center {}]] :fx [[:dispatch [:open-modal :activity-center {}]]
[:dispatch-later [{:ms 1000 :dispatch [:activity-center/mark-as-seen]}]]]} [:dispatch-later [{:ms 1000 :dispatch [:activity-center/mark-as-seen]}]]]}
(events/open-activity-center {:db {}} [nil])))) (events/open-activity-center {:db {}} [nil]))))
(testing "opens the activity center with filters enabled" (testing "opens the activity center with filters enabled"
(is (= {:db {:activity-center {:filter {:status :unread :type types/contact-request}}} (is (match? {:db {:activity-center {:filter {:status :unread :type types/contact-request}}}
:fx [[:dispatch [:open-modal :activity-center {}]] :fx [[:dispatch [:open-modal :activity-center {}]]
[:dispatch-later [{:ms 1000 :dispatch [:activity-center/mark-as-seen]}]]]} [:dispatch-later [{:ms 1000 :dispatch [:activity-center/mark-as-seen]}]]]}
(events/open-activity-center {:db {}} (events/open-activity-center {:db {}}
[{:filter-type types/contact-request [{:filter-type types/contact-request
:filter-status :unread}]))))) :filter-status :unread}])))))
(deftest process-notification-failure-test (deftest process-notification-failure-test
(testing "logs and returns nil" (testing "logs and returns nil"
@ -34,11 +35,11 @@
notification-id notification-id
:some-action-name :some-action-name
:some-error))) :some-error)))
(is (= {:args ["Failed to :some-action-name" (is (match? {:args ["Failed to :some-action-name"
{:notification-id notification-id {:notification-id notification-id
:error :some-error}] :error :some-error}]
:level :warn} :level :warn}
(last @h/logs))))) (last @h/logs)))))
;;;; Mark as read/unread ;;;; Mark as read/unread
@ -53,13 +54,13 @@
(testing "dispatches RPC call" (testing "dispatches RPC call"
(let [notif {:id "0x1" :read false :type types/one-to-one-chat} (let [notif {:id "0x1" :read false :type types/one-to-one-chat}
cofx {:db {:activity-center {:notifications [notif]}}}] cofx {:db {:activity-center {:notifications [notif]}}}]
(is (= {:json-rpc/call (is (match? {:json-rpc/call
[{:method "wakuext_markActivityCenterNotificationsRead" [{:method "wakuext_markActivityCenterNotificationsRead"
:params [[(:id notif)]] :params [[(:id notif)]]
:on-success [:activity-center.notifications/mark-as-read-success notif] :on-success [:activity-center.notifications/mark-as-read-success notif]
:on-error [:activity-center/process-notification-failure (:id notif) :on-error [:activity-center/process-notification-failure (:id notif)
:notification/mark-as-read]}]} :notification/mark-as-read]}]}
(events/mark-as-read cofx (:id notif))))))) (events/mark-as-read cofx (:id notif)))))))
(deftest mark-as-read-success-test (deftest mark-as-read-success-test
(let [f-args (atom []) (let [f-args (atom [])
@ -70,8 +71,8 @@
(reset! f-args args) (reset! f-args args)
:result)] :result)]
(is (= :result (events/mark-as-read-success cofx notif))) (is (= :result (events/mark-as-read-success cofx notif)))
(is (= [cofx [(assoc notif :read true)]] (is (match? [cofx [(assoc notif :read true)]]
@f-args))))) @f-args)))))
(deftest mark-as-unread-test (deftest mark-as-unread-test
(testing "does nothing if the notification ID cannot be found in the app db" (testing "does nothing if the notification ID cannot be found in the app db"
@ -84,13 +85,13 @@
(testing "dispatches RPC call" (testing "dispatches RPC call"
(let [notif {:id "0x1" :read true :type types/one-to-one-chat} (let [notif {:id "0x1" :read true :type types/one-to-one-chat}
cofx {:db {:activity-center {:notifications [notif]}}}] cofx {:db {:activity-center {:notifications [notif]}}}]
(is (= {:json-rpc/call (is (match? {:json-rpc/call
[{:method "wakuext_markActivityCenterNotificationsUnread" [{:method "wakuext_markActivityCenterNotificationsUnread"
:params [[(:id notif)]] :params [[(:id notif)]]
:on-success [:activity-center.notifications/mark-as-unread-success notif] :on-success [:activity-center.notifications/mark-as-unread-success notif]
:on-error [:activity-center/process-notification-failure (:id notif) :on-error [:activity-center/process-notification-failure (:id notif)
:notification/mark-as-unread]}]} :notification/mark-as-unread]}]}
(events/mark-as-unread cofx (:id notif))))))) (events/mark-as-unread cofx (:id notif)))))))
(deftest mark-as-unread-success-test (deftest mark-as-unread-success-test
(let [f-args (atom []) (let [f-args (atom [])
@ -101,19 +102,19 @@
(reset! f-args args) (reset! f-args args)
:reconciliation-result)] :reconciliation-result)]
(is (= :reconciliation-result (events/mark-as-unread-success cofx notif))) (is (= :reconciliation-result (events/mark-as-unread-success cofx notif)))
(is (= [cofx [(assoc notif :read false)]] (is (match? [cofx [(assoc notif :read false)]]
@f-args))))) @f-args)))))
;;;; Acceptance/dismissal ;;;; Acceptance/dismissal
(deftest accept-notification-test (deftest accept-notification-test
(is (= {:json-rpc/call (is (match? {:json-rpc/call
[{:method "wakuext_acceptActivityCenterNotifications" [{:method "wakuext_acceptActivityCenterNotifications"
:params [[notification-id]] :params [[notification-id]]
:on-success [:activity-center.notifications/accept-success notification-id] :on-success [:activity-center.notifications/accept-success notification-id]
:on-error [:activity-center/process-notification-failure notification-id :on-error [:activity-center/process-notification-failure notification-id
:notification/accept]}]} :notification/accept]}]}
(events/accept-notification {:db {}} notification-id)))) (events/accept-notification {:db {}} notification-id))))
(deftest accept-notification-success-test (deftest accept-notification-success-test
(testing "does nothing if the notification ID cannot be found in the app db" (testing "does nothing if the notification ID cannot be found in the app db"
@ -129,18 +130,18 @@
notif-2-accepted (assoc notif-2 :accepted true :read true) notif-2-accepted (assoc notif-2 :accepted true :read true)
cofx {:db {:activity-center {:filter {:type types/no-type :status :all} cofx {:db {:activity-center {:filter {:type types/no-type :status :all}
:notifications [notif-2 notif-1]}}}] :notifications [notif-2 notif-1]}}}]
(is (= {:fx [[:dispatch [:chat/ensure-chats []]] (is (match? {:fx [[:dispatch [:chat/ensure-chats []]]
[:dispatch [:activity-center.notifications/reconcile [notif-2-accepted]]]]} [:dispatch [:activity-center.notifications/reconcile [notif-2-accepted]]]]}
(events/accept-notification-success cofx [(:id notif-2) nil])))))) (events/accept-notification-success cofx [(:id notif-2) nil]))))))
(deftest dismiss-notification-test (deftest dismiss-notification-test
(is (= {:json-rpc/call (is (match? {:json-rpc/call
[{:method "wakuext_dismissActivityCenterNotifications" [{:method "wakuext_dismissActivityCenterNotifications"
:params [[notification-id]] :params [[notification-id]]
:on-success [:activity-center.notifications/dismiss-success notification-id] :on-success [:activity-center.notifications/dismiss-success notification-id]
:on-error [:activity-center/process-notification-failure notification-id :on-error [:activity-center/process-notification-failure notification-id
:notification/dismiss]}]} :notification/dismiss]}]}
(events/dismiss-notification {:db {}} notification-id)))) (events/dismiss-notification {:db {}} notification-id))))
(deftest dismiss-notification-success-test (deftest dismiss-notification-success-test
(testing "does nothing if the notification ID cannot be found in the app db" (testing "does nothing if the notification ID cannot be found in the app db"
@ -156,11 +157,11 @@
notif-2-dismissed (assoc notif-2 :dismissed true :read true) notif-2-dismissed (assoc notif-2 :dismissed true :read true)
cofx {:db {:activity-center {:filter {:type types/no-type :status :all} cofx {:db {:activity-center {:filter {:type types/no-type :status :all}
:notifications [notif-2 notif-1]}}}] :notifications [notif-2 notif-1]}}}]
(is (= {:db {:activity-center {:filter {:type 0 :status :all} (is (match? {:db {:activity-center {:filter {:type 0 :status :all}
:notifications [notif-2-dismissed notif-1]}} :notifications [notif-2-dismissed notif-1]}}
:dispatch-n [[:activity-center.notifications/fetch-unread-count] :dispatch-n [[:activity-center.notifications/fetch-unread-count]
[:activity-center.notifications/fetch-pending-contact-requests]]} [:activity-center.notifications/fetch-pending-contact-requests]]}
(events/dismiss-notification-success cofx (:id notif-2))))))) (events/dismiss-notification-success cofx (:id notif-2)))))))
;;;; Contact verification ;;;; Contact verification
@ -208,41 +209,41 @@
:type types/contact-verification}) :type types/contact-verification})
(deftest contact-verification-decline-test (deftest contact-verification-decline-test
(is (= {:json-rpc/call (is (match? {:json-rpc/call
[{:method "wakuext_declineContactVerificationRequest" [{:method "wakuext_declineContactVerificationRequest"
:params [notification-id] :params [notification-id]
:on-success [:activity-center/reconcile-notifications-from-response] :on-success [:activity-center/reconcile-notifications-from-response]
:on-error [:activity-center/process-notification-failure notification-id :on-error [:activity-center/process-notification-failure notification-id
:contact-verification/decline]}]} :contact-verification/decline]}]}
(events/contact-verification-decline {:db {}} notification-id)))) (events/contact-verification-decline {:db {}} notification-id))))
(deftest contact-verification-reply-test (deftest contact-verification-reply-test
(let [reply "The answer is 42"] (let [reply "The answer is 42"]
(is (= {:json-rpc/call (is (match? {:json-rpc/call
[{:method "wakuext_acceptContactVerificationRequest" [{:method "wakuext_acceptContactVerificationRequest"
:params [notification-id reply] :params [notification-id reply]
:on-success [:activity-center/reconcile-notifications-from-response] :on-success [:activity-center/reconcile-notifications-from-response]
:on-error [:activity-center/process-notification-failure notification-id :on-error [:activity-center/process-notification-failure notification-id
:contact-verification/reply]}]} :contact-verification/reply]}]}
(events/contact-verification-reply {:db {}} notification-id reply))))) (events/contact-verification-reply {:db {}} notification-id reply)))))
(deftest contact-verification-mark-as-trusted-test (deftest contact-verification-mark-as-trusted-test
(is (= {:json-rpc/call (is (match? {:json-rpc/call
[{:method "wakuext_verifiedTrusted" [{:method "wakuext_verifiedTrusted"
:params [{:id notification-id}] :params [{:id notification-id}]
:on-success [:activity-center/reconcile-notifications-from-response] :on-success [:activity-center/reconcile-notifications-from-response]
:on-error [:activity-center/process-notification-failure notification-id :on-error [:activity-center/process-notification-failure notification-id
:contact-verification/mark-as-trusted]}]} :contact-verification/mark-as-trusted]}]}
(events/contact-verification-mark-as-trusted {:db {}} notification-id)))) (events/contact-verification-mark-as-trusted {:db {}} notification-id))))
(deftest contact-verification-mark-as-untrustworthy-test (deftest contact-verification-mark-as-untrustworthy-test
(is (= {:json-rpc/call (is (match? {:json-rpc/call
[{:method "wakuext_verifiedUntrustworthy" [{:method "wakuext_verifiedUntrustworthy"
:params [{:id notification-id}] :params [{:id notification-id}]
:on-success [:activity-center/reconcile-notifications-from-response] :on-success [:activity-center/reconcile-notifications-from-response]
:on-error [:activity-center/process-notification-failure notification-id :on-error [:activity-center/process-notification-failure notification-id
:contact-verification/mark-as-untrustworthy]}]} :contact-verification/mark-as-untrustworthy]}]}
(events/contact-verification-mark-as-untrustworthy {:db {}} notification-id)))) (events/contact-verification-mark-as-untrustworthy {:db {}} notification-id))))
;;;; Notification reconciliation ;;;; Notification reconciliation
@ -256,17 +257,17 @@
cofx {:db {:activity-center cofx {:db {:activity-center
{:filter {:type types/no-type :status :all} {:filter {:type types/no-type :status :all}
:notifications [notif-2 notif-1]}}}] :notifications [notif-2 notif-1]}}}]
(is (= {:db {:activity-center (is (match? {:db {:activity-center
{:filter {:type types/no-type :status :all} {:filter {:type types/no-type :status :all}
:notifications [new-notif-4 new-notif-3 new-notif-2]}} :notifications [new-notif-4 new-notif-3 new-notif-2]}}
:dispatch-n [[:activity-center.notifications/fetch-unread-count] :dispatch-n [[:activity-center.notifications/fetch-unread-count]
[:activity-center.notifications/fetch-pending-contact-requests]]} [:activity-center.notifications/fetch-pending-contact-requests]]}
(events/notifications-reconcile (events/notifications-reconcile
cofx cofx
[(assoc notif-1 :deleted true) ; will be removed [(assoc notif-1 :deleted true) ; will be removed
new-notif-2 new-notif-2
new-notif-3 new-notif-3
new-notif-4]))))) new-notif-4])))))
(testing "All tab + Unread filter" (testing "All tab + Unread filter"
(let [notif-1 {:id "0x1" :read false :type types/one-to-one-chat} (let [notif-1 {:id "0x1" :read false :type types/one-to-one-chat}
@ -278,18 +279,18 @@
cofx {:db {:activity-center cofx {:db {:activity-center
{:filter {:type types/no-type :status :unread} {:filter {:type types/no-type :status :unread}
:notifications [notif-5 notif-2 notif-1]}}}] :notifications [notif-5 notif-2 notif-1]}}}]
(is (= {:db {:activity-center (is (match? {:db {:activity-center
{:filter {:type types/no-type :status :unread} {:filter {:type types/no-type :status :unread}
:notifications [new-notif-3 notif-1]}} :notifications [new-notif-3 notif-1]}}
:dispatch-n [[:activity-center.notifications/fetch-unread-count] :dispatch-n [[:activity-center.notifications/fetch-unread-count]
[:activity-center.notifications/fetch-pending-contact-requests]]} [:activity-center.notifications/fetch-pending-contact-requests]]}
(events/notifications-reconcile (events/notifications-reconcile
cofx cofx
[new-notif-2 ; will be removed because it's read [new-notif-2 ; will be removed because it's read
new-notif-3 ; will be inserted new-notif-3 ; will be inserted
new-notif-4 ; will be ignored because it's read new-notif-4 ; will be ignored because it's read
(assoc notif-5 :deleted true) ; will be removed (assoc notif-5 :deleted true) ; will be removed
]))))) ])))))
(testing "Contact request tab + All filter" (testing "Contact request tab + All filter"
(let [notif-1 {:id "0x1" :read true :type types/contact-request} (let [notif-1 {:id "0x1" :read true :type types/contact-request}
@ -301,18 +302,18 @@
cofx {:db {:activity-center cofx {:db {:activity-center
{:filter {:type types/contact-request :status :all} {:filter {:type types/contact-request :status :all}
:notifications [notif-5 notif-2 notif-1]}}}] :notifications [notif-5 notif-2 notif-1]}}}]
(is (= {:db {:activity-center (is (match? {:db {:activity-center
{:filter {:type types/contact-request :status :all} {:filter {:type types/contact-request :status :all}
:notifications [new-notif-3 new-notif-2 notif-1]}} :notifications [new-notif-3 new-notif-2 notif-1]}}
:dispatch-n [[:activity-center.notifications/fetch-unread-count] :dispatch-n [[:activity-center.notifications/fetch-unread-count]
[:activity-center.notifications/fetch-pending-contact-requests]]} [:activity-center.notifications/fetch-pending-contact-requests]]}
(events/notifications-reconcile (events/notifications-reconcile
cofx cofx
[new-notif-2 ; will be updated [new-notif-2 ; will be updated
new-notif-3 ; will be inserted new-notif-3 ; will be inserted
new-notif-4 ; will be ignored because it's not a contact request new-notif-4 ; will be ignored because it's not a contact request
(assoc notif-5 :deleted true) ; will be removed (assoc notif-5 :deleted true) ; will be removed
]))))) ])))))
(testing "Contact request tab + Unread filter" (testing "Contact request tab + Unread filter"
(let [notif-1 {:id "0x1" :read false :type types/contact-request} (let [notif-1 {:id "0x1" :read false :type types/contact-request}
@ -326,20 +327,20 @@
{:filter {:type types/contact-request {:filter {:type types/contact-request
:status :unread} :status :unread}
:notifications [notif-6 notif-2 notif-1]}}}] :notifications [notif-6 notif-2 notif-1]}}}]
(is (= {:db {:activity-center (is (match? {:db {:activity-center
{:filter {:type types/contact-request {:filter {:type types/contact-request
:status :unread} :status :unread}
:notifications [new-notif-3 notif-1]}} :notifications [new-notif-3 notif-1]}}
:dispatch-n [[:activity-center.notifications/fetch-unread-count] :dispatch-n [[:activity-center.notifications/fetch-unread-count]
[:activity-center.notifications/fetch-pending-contact-requests]]} [:activity-center.notifications/fetch-pending-contact-requests]]}
(events/notifications-reconcile (events/notifications-reconcile
cofx cofx
[new-notif-2 ; will be removed because it's read [new-notif-2 ; will be removed because it's read
new-notif-3 ; will be inserted new-notif-3 ; will be inserted
new-notif-4 ; will be ignored because it's read new-notif-4 ; will be ignored because it's read
new-notif-5 ; will be ignored because it's not a contact request new-notif-5 ; will be ignored because it's not a contact request
(assoc notif-6 :deleted true) ; will be removed (assoc notif-6 :deleted true) ; will be removed
]))))) ])))))
;; Sorting by timestamp and ID is compatible with what the backend does when ;; Sorting by timestamp and ID is compatible with what the backend does when
;; returning paginated results. ;; returning paginated results.
@ -354,15 +355,15 @@
cofx {:db {:activity-center cofx {:db {:activity-center
{:notifications [notif-1 notif-3 notif-4 notif-2 {:notifications [notif-1 notif-3 notif-4 notif-2
notif-5]}}}] notif-5]}}}]
(is (= {:db {:activity-center (is (match? {:db {:activity-center
{:notifications [notif-5 {:notifications [notif-5
new-notif-4 new-notif-4
notif-3 notif-3
notif-2 notif-2
new-notif-1]}} new-notif-1]}}
:dispatch-n [[:activity-center.notifications/fetch-unread-count] :dispatch-n [[:activity-center.notifications/fetch-unread-count]
[:activity-center.notifications/fetch-pending-contact-requests]]} [:activity-center.notifications/fetch-pending-contact-requests]]}
(events/notifications-reconcile cofx [new-notif-1 new-notif-4])))))) (events/notifications-reconcile cofx [new-notif-1 new-notif-4]))))))
(deftest remove-pending-contact-request-test (deftest remove-pending-contact-request-test
(testing "removes notification from all related filter types and status" (testing "removes notification from all related filter types and status"
@ -376,26 +377,27 @@
notif-2 ; will be removed notif-2 ; will be removed
notif-1 ; will be ignored because it's not from the same author notif-1 ; will be ignored because it's not from the same author
]}}}] ]}}}]
(is (= {:db {:activity-center {:notifications [notif-3 notif-1]}}} (is (match? {:db {:activity-center {:notifications [notif-3 notif-1]}}}
(events/notifications-remove-pending-contact-request cofx author)))))) (events/notifications-remove-pending-contact-request cofx author))))))
;;;; Notifications fetching and pagination ;;;; Notifications fetching and pagination
(deftest notifications-fetch-first-page-test (deftest notifications-fetch-first-page-test
(testing "fetches first page" (testing "fetches first page"
(let [cofx {:db {}}] (let [cofx {:db {}}]
(is (= {:db {:activity-center {:filter {:type types/one-to-one-chat (is (match? {:db {:activity-center {:filter {:type types/one-to-one-chat
:status :unread} :status :unread}
:loading? true}} :loading? true}}
:json-rpc/call [{:method "wakuext_activityCenterNotifications" :json-rpc/call [{:method "wakuext_activityCenterNotifications"
:params [{:cursor "" :params [{:cursor ""
:limit (:notifications-per-page events/defaults) :limit (:notifications-per-page
:activityTypes [types/one-to-one-chat] events/defaults)
:readType events/read-type-unread}] :activityTypes [types/one-to-one-chat]
:on-success [:activity-center.notifications/fetch-success true] :readType events/read-type-unread}]
:on-error [:activity-center.notifications/fetch-error :on-success [:activity-center.notifications/fetch-success true]
types/one-to-one-chat :unread]}]} :on-error [:activity-center.notifications/fetch-error
(events/notifications-fetch-first-page cofx {:filter-type types/one-to-one-chat})))))) types/one-to-one-chat :unread]}]}
(events/notifications-fetch-first-page cofx {:filter-type types/one-to-one-chat}))))))
(deftest notifications-fetch-next-next-page-test (deftest notifications-fetch-next-next-page-test
(testing "does not fetch next page when pagination cursor reached the end" (testing "does not fetch next page when pagination cursor reached the end"
@ -413,12 +415,12 @@
(reset! f-args args) (reset! f-args args)
:result)] :result)]
(is (= :result (events/notifications-fetch-next-page cofx))) (is (= :result (events/notifications-fetch-next-page cofx)))
(is (= [cofx (is (match? [cofx
{:cursor cursor {:cursor cursor
:filter-type types/one-to-one-chat :filter-type types/one-to-one-chat
:filter-status :unread :filter-status :unread
:reset-data? false}] :reset-data? false}]
@f-args)))))) @f-args))))))
(deftest notifications-fetch-error-test (deftest notifications-fetch-error-test
(testing "resets loading state" (testing "resets loading state"
@ -427,23 +429,23 @@
:filter {:status :unread :filter {:status :unread
:type types/one-to-one-chat} :type types/one-to-one-chat}
:cursor ""}}}] :cursor ""}}}]
(is (= {:db {:activity-center {:filter {:status :unread (is (match? {:db {:activity-center {:filter {:status :unread
:type types/one-to-one-chat} :type types/one-to-one-chat}
:cursor ""}}} :cursor ""}}}
(events/notifications-fetch-error cofx :dummy-error)))))) (events/notifications-fetch-error cofx :dummy-error))))))
(deftest seen-state-test (deftest seen-state-test
(testing "update seen state" (testing "update seen state"
(is (= {:db {:activity-center {:seen? true}}} (is (match? {:db {:activity-center {:seen? true}}}
(events/reconcile-seen-state {:db {}} true)))) (events/reconcile-seen-state {:db {}} true))))
(testing "update seen state when the user is on other screen" (testing "update seen state when the user is on other screen"
(is (= {:db {:view-id :chats-stack (is (match? {:db {:view-id :chats-stack
:activity-center {:seen? false}}} :activity-center {:seen? false}}}
(events/reconcile-seen-state {:db {:view-id :chats-stack}} false)))) (events/reconcile-seen-state {:db {:view-id :chats-stack}} false))))
(testing "update seen state when the user is on activity center" (testing "update seen state when the user is on activity center"
(is (= {:db {:view-id :activity-center (is (match? {:db {:view-id :activity-center
:activity-center {:seen? false}} :activity-center {:seen? false}}
:dispatch [:activity-center/mark-as-seen]} :dispatch [:activity-center/mark-as-seen]}
(events/reconcile-seen-state {:db {:view-id :activity-center}} false))))) (events/reconcile-seen-state {:db {:view-id :activity-center}} false)))))

View File

@ -1,6 +1,7 @@
(ns status-im2.contexts.wallet.events-test (ns status-im2.contexts.wallet.events-test
(:require (:require
[cljs.test :refer-macros [deftest is testing]] [cljs.test :refer-macros [deftest is testing]]
matcher-combinators.test
[status-im2.contexts.wallet.events :as events])) [status-im2.contexts.wallet.events :as events]))
(def address "0x2f88d65f3cb52605a54a833ae118fb1363acccd2") (def address "0x2f88d65f3cb52605a54a833ae118fb1363acccd2")
@ -11,7 +12,7 @@
(let [expected-db {:wallet/scanned-address address} (let [expected-db {:wallet/scanned-address address}
effects (events/scan-address-success {:db db} address) effects (events/scan-address-success {:db db} address)
result-db (:db effects)] result-db (:db effects)]
(is (= result-db expected-db)))))) (is (match? result-db expected-db))))))
(deftest clean-scanned-address (deftest clean-scanned-address
(let [db {:wallet/scanned-address address}] (let [db {:wallet/scanned-address address}]
@ -19,7 +20,7 @@
(let [expected-db {} (let [expected-db {}
effects (events/clean-scanned-address {:db db}) effects (events/clean-scanned-address {:db db})
result-db (:db effects)] result-db (:db effects)]
(is (= result-db expected-db)))))) (is (match? result-db expected-db))))))
(deftest store-collectibles (deftest store-collectibles
(testing "(displayable-collectible?) helper function" (testing "(displayable-collectible?) helper function"
@ -34,7 +35,8 @@
[false {:collectible-data {:image-url nil :animation-url ""}}] [false {:collectible-data {:image-url nil :animation-url ""}}]
[false {:collectible-data {:image-url "" :animation-url ""}}]]] [false {:collectible-data {:image-url "" :animation-url ""}}]]]
(doseq [[result collection] expected-results] (doseq [[result collection] expected-results]
(is (= result (events/displayable-collectible? collection)))))) (is (match? result (events/displayable-collectible? collection))))))
(testing "save-collectibles-request-details" (testing "save-collectibles-request-details"
(let [db {:wallet {}} (let [db {:wallet {}}
collectibles [{:collectible-data {:image-url "https://..." :animation-url "https://..."}} collectibles [{:collectible-data {:image-url "https://..." :animation-url "https://..."}}
@ -46,7 +48,7 @@
{:image-url "" :animation-url "https://..."}}]}} {:image-url "" :animation-url "https://..."}}]}}
effects (events/store-collectibles {:db db} [collectibles]) effects (events/store-collectibles {:db db} [collectibles])
result-db (:db effects)] result-db (:db effects)]
(is (= result-db expected-db))))) (is (match? result-db expected-db)))))
(deftest clear-stored-collectibles (deftest clear-stored-collectibles
(let [db {:wallet {:collectibles [{:id 1} {:id 2}]}}] (let [db {:wallet {:collectibles [{:id 1} {:id 2}]}}]
@ -54,7 +56,7 @@
(let [expected-db {:wallet {}} (let [expected-db {:wallet {}}
effects (events/clear-stored-collectibles {:db db}) effects (events/clear-stored-collectibles {:db db})
result-db (:db effects)] result-db (:db effects)]
(is (= result-db expected-db)))))) (is (match? result-db expected-db))))))
(deftest store-last-collectible-details (deftest store-last-collectible-details
(testing "store-last-collectible-details" (testing "store-last-collectible-details"
@ -65,4 +67,4 @@
:image-url "https://..."}}} :image-url "https://..."}}}
effects (events/store-last-collectible-details {:db db} [last-collectible]) effects (events/store-last-collectible-details {:db db} [last-collectible])
result-db (:db effects)] result-db (:db effects)]
(is (= result-db expected-db))))) (is (match? result-db expected-db)))))