Unit tests for mark seen functionality
This commit is contained in:
parent
221e6fd2b7
commit
be113ab8a4
|
@ -205,7 +205,7 @@
|
|||
(transport.message/send (protocol/map->MessagesSeen {:message-ids message-ids}) chat-id cofx)))
|
||||
|
||||
;; TODO (janherich) - ressurect `constants/system` messages for group chats in the future
|
||||
(defn- mark-messages-seen
|
||||
(defn mark-messages-seen
|
||||
[chat-id {:keys [db] :as cofx}]
|
||||
(when-let [all-unviewed-ids (seq (get-in db [:chats chat-id :unviewed-messages]))]
|
||||
(let [me (:current-public-key db)
|
||||
|
|
|
@ -7,17 +7,45 @@
|
|||
[status-im.chat.console :as console-chat]
|
||||
[status-im.chat.events :as chat-events]))
|
||||
|
||||
(def contact
|
||||
{:address "c296367a939e0957500a25ca89b70bd64b03004e"
|
||||
:whisper-identity "0x04f5722fba79eb36d73263417531007f43d13af76c6233573a8e3e60f667710611feba0785d751b50609bfc0b7cef35448875c5392c0a91948c95798a0ce600847"
|
||||
:name "testuser"
|
||||
:photo-path "contacts://testuser"
|
||||
:dapp? false})
|
||||
(def test-db
|
||||
{:current-public-key "me"
|
||||
:chats {const/console-chat-id console-chat/chat
|
||||
"status" {:public? true
|
||||
:unviewed-messages #{"6" "5" "4" "3" "2" "1"}
|
||||
:message-statuses {"6" {"me" {:message-id "6"
|
||||
:chat-id "status"
|
||||
:whisper-identity "me"
|
||||
:status :received}}
|
||||
"5" {"me" {:message-id "5"
|
||||
:chat-id "status"
|
||||
:whisper-identity "me"
|
||||
:status :received}}
|
||||
"4" {"me" {:message-id "4"
|
||||
:chat-id "status"
|
||||
:whisper-identity "me"
|
||||
:status :received}}}}
|
||||
"opened" {:unviewed-messages #{}
|
||||
:message-statuses {"1" {"me" {:message-id "1"
|
||||
:chat-id "opened"
|
||||
:whisper-identity "me"
|
||||
:status :seen}}}}
|
||||
"1-1" {:unviewed-messages #{"6" "5" "4" "3" "2" "1"}
|
||||
:message-statuses {"6" {"me" {:message-id "6"
|
||||
:chat-id "status"
|
||||
:whisper-identity "me"
|
||||
:status :received}}
|
||||
"5" {"me" {:message-id "5"
|
||||
:chat-id "status"
|
||||
:whisper-identity "me"
|
||||
:status :received}}
|
||||
"4" {"me" {:message-id "4"
|
||||
:chat-id "status"
|
||||
:whisper-identity "me"
|
||||
:status :received}}}}}})
|
||||
|
||||
(deftest init-console-chat
|
||||
(testing "initialising console if console is already added to chats, should not modify anything"
|
||||
(let [db {:chats {const/console-chat-id console-chat/chat}}
|
||||
fx (chat-events/init-console-chat {:db db})]
|
||||
(let [fx (chat-events/init-console-chat {:db test-db})]
|
||||
(is (not fx))))
|
||||
|
||||
(testing "initialising console without existing account and console chat not initialisated"
|
||||
|
@ -35,3 +63,23 @@
|
|||
(:chat-id console-chat/chat)))
|
||||
(is (= (:current-chat-id db)
|
||||
const/console-chat-id)))))
|
||||
|
||||
(deftest mark-messages-seen
|
||||
(testing "Marking messages seen correctly marks loaded messages as seen and updates absolute unviewed set"
|
||||
(let [fx (chat-events/mark-messages-seen "status" {:db test-db})
|
||||
me (:current-public-key test-db)]
|
||||
(is (= '(:seen :seen :seen)
|
||||
(map (fn [[_ v]]
|
||||
(get-in v [me :status]))
|
||||
(get-in fx [:db :chats "status" :message-statuses]))))
|
||||
(is (= 1 (count (:data-store/tx fx))))
|
||||
(is (= nil (:shh/post fx))) ;; for public chats, no confirmation is sent out
|
||||
(is (= #{"3" "2" "1"} (get-in fx [:db :chats "status" :unviewed-messages])))))
|
||||
|
||||
(testing "With empty unviewed set, no effects are produced"
|
||||
(is (= nil (chat-events/mark-messages-seen "opened" {:db test-db}))))
|
||||
|
||||
(testing "For 1-1 chat, we send seen messages confirmation to the recipient as well"
|
||||
(is (= #{"4" "5" "6"}
|
||||
(set (get-in (chat-events/mark-messages-seen "1-1" {:db test-db})
|
||||
[:shh/post 0 :message :payload :message-ids]))))))
|
||||
|
|
Loading…
Reference in New Issue