Browse Source

test(rtc): add apply-remote-remove-ops-test

rcmerci 1 year ago
parent
commit
6840f3fca0
1 changed files with 56 additions and 1 deletions
  1. 56 1
      src/test/frontend/worker/rtc/rtc_fns_test.cljs

+ 56 - 1
src/test/frontend/worker/rtc/rtc_fns_test.cljs

@@ -197,7 +197,7 @@
               :transact-opts {:repo test-helper/test-db
                               :conn conn}}
         date-formatter (common-config/get-date-formatter (worker-state/get-config test-helper/test-db))
-        page-name "apply-remote-move-ops-test"
+        page-name "apply-remote-update-ops-test"
         [page-uuid
          uuid1-client uuid2-client
          uuid1-remote] (repeatedly random-uuid)]
@@ -279,3 +279,58 @@
 
   (state/set-current-repo! nil)
   (test-helper/destroy-test-db!))
+
+(deftest apply-remote-remove-ops-test
+  (state/set-current-repo! test-helper/test-db)
+  (test-helper/reset-test-db!)
+  (let [conn (conn/get-db test-helper/test-db false)
+        repo test-helper/test-db
+        opts {:persist-op? false
+              :transact-opts {:repo test-helper/test-db
+                              :conn conn}}
+        date-formatter (common-config/get-date-formatter (worker-state/get-config test-helper/test-db))
+        page-name "apply-remote-remove-ops-test"
+        [page-uuid
+         uuid1-client uuid2-client
+         uuid1-not-exist] (repeatedly random-uuid)]
+    (page-handler/create! page-name {:redirect? false :create-first-block? false :uuid page-uuid})
+    (outliner-tx/transact!
+     opts
+     (outliner-core/insert-blocks!
+      test-helper/test-db
+      conn
+      [{:block/uuid uuid1-client :block/content "uuid1-client"
+        :block/left [:block/uuid page-uuid]
+        :block/parent [:block/uuid page-uuid]}
+       {:block/uuid uuid2-client :block/content "uuid2-client"
+        :block/left [:block/uuid uuid1-client]
+        :block/parent [:block/uuid page-uuid]}]
+      (d/pull @conn '[*] [:block/name page-name])
+      {:sibling? true :keep-uuid? true}))
+    (testing "apply-remote-remove-ops-test1"
+      (let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
+                          :affected-blocks
+                          {uuid1-client {:op :remove
+                                         :block-uuid uuid1-not-exist}}}
+            remove-ops (vals
+                        (:remove-ops-map
+                         (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
+        (is (rtc-const/data-from-ws-validator data-from-ws))
+        (rtc-core/apply-remote-remove-ops repo conn date-formatter remove-ops)
+        (let [page-blocks (ldb/get-page-blocks @conn page-name {})]
+          (is (= #{uuid1-client uuid2-client} (set (map :block/uuid page-blocks)))))))
+    (testing "apply-remote-remove-ops-test2"
+      (let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
+                          :affected-blocks
+                          {uuid1-client {:op :remove
+                                         :block-uuid uuid1-client}}}
+            remove-ops (vals
+                        (:remove-ops-map
+                         (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
+        (is (rtc-const/data-from-ws-validator data-from-ws))
+        (rtc-core/apply-remote-remove-ops repo conn date-formatter remove-ops)
+        (let [page-blocks (ldb/get-page-blocks @conn page-name {})]
+          (is (= #{uuid2-client} (set (map :block/uuid page-blocks))))))))
+
+  (state/set-current-repo! nil)
+  (test-helper/destroy-test-db!))