mirror of
https://github.com/penpot/penpot.git
synced 2025-12-12 06:24:17 +01:00
🔥 Remove duplicated functions from file tests namespace
This commit is contained in:
@@ -142,126 +142,112 @@
|
|||||||
(t/is (= 0 (count result))))))))
|
(t/is (= 0 (count result))))))))
|
||||||
|
|
||||||
(t/deftest file-gc-with-fragments
|
(t/deftest file-gc-with-fragments
|
||||||
(letfn [(update-file! [& {:keys [profile-id file-id changes revn] :or {revn 0}}]
|
(let [profile (th/create-profile* 1)
|
||||||
(let [params {::th/type :update-file
|
file (th/create-file* 1 {:profile-id (:id profile)
|
||||||
::rpc/profile-id profile-id
|
:project-id (:default-project-id profile)
|
||||||
:id file-id
|
:is-shared false})
|
||||||
:session-id (uuid/random)
|
|
||||||
:revn revn
|
|
||||||
:vern 0
|
|
||||||
:features cfeat/supported-features
|
|
||||||
:changes changes}
|
|
||||||
out (th/command! params)]
|
|
||||||
;; (th/print-result! out)
|
|
||||||
(t/is (nil? (:error out)))
|
|
||||||
(:result out)))]
|
|
||||||
|
|
||||||
(let [profile (th/create-profile* 1)
|
page-id (uuid/random)
|
||||||
file (th/create-file* 1 {:profile-id (:id profile)
|
shape-id (uuid/random)]
|
||||||
:project-id (:default-project-id profile)
|
|
||||||
:is-shared false})
|
|
||||||
|
|
||||||
page-id (uuid/random)
|
;; Preventive file-gc
|
||||||
shape-id (uuid/random)]
|
(t/is (true? (th/run-task! :file-gc {:file-id (:id file) :revn (:revn file)})))
|
||||||
|
|
||||||
;; Preventive file-gc
|
;; Check the number of fragments before adding the page
|
||||||
(t/is (true? (th/run-task! :file-gc {:file-id (:id file) :revn (:revn file)})))
|
(let [rows (th/db-query :file-data {:file-id (:id file) :type "fragment"})]
|
||||||
|
(t/is (= 2 (count rows))))
|
||||||
|
|
||||||
;; Check the number of fragments before adding the page
|
;; Add page
|
||||||
(let [rows (th/db-query :file-data {:file-id (:id file) :type "fragment"})]
|
(update-file!
|
||||||
(t/is (= 2 (count rows))))
|
:file-id (:id file)
|
||||||
|
:profile-id (:id profile)
|
||||||
|
:revn 0
|
||||||
|
:vern 0
|
||||||
|
:changes
|
||||||
|
[{:type :add-page
|
||||||
|
:name "test"
|
||||||
|
:id page-id}])
|
||||||
|
|
||||||
;; Add page
|
;; Check the number of fragments before adding the page
|
||||||
(update-file!
|
(let [rows (th/db-query :file-data {:file-id (:id file) :type "fragment"})]
|
||||||
:file-id (:id file)
|
(t/is (= 3 (count rows))))
|
||||||
:profile-id (:id profile)
|
|
||||||
:revn 0
|
|
||||||
:vern 0
|
|
||||||
:changes
|
|
||||||
[{:type :add-page
|
|
||||||
:name "test"
|
|
||||||
:id page-id}])
|
|
||||||
|
|
||||||
;; Check the number of fragments before adding the page
|
;; The file-gc should mark for remove unused fragments
|
||||||
(let [rows (th/db-query :file-data {:file-id (:id file) :type "fragment"})]
|
(t/is (true? (th/run-task! :file-gc {:file-id (:id file)})))
|
||||||
(t/is (= 3 (count rows))))
|
|
||||||
|
|
||||||
;; The file-gc should mark for remove unused fragments
|
;; Check the number of fragments
|
||||||
(t/is (true? (th/run-task! :file-gc {:file-id (:id file)})))
|
(let [rows (th/db-query :file-data {:file-id (:id file) :type "fragment"})]
|
||||||
|
(t/is (= 5 (count rows)))
|
||||||
|
(t/is (= 3 (count (filterv :deleted-at rows)))))
|
||||||
|
|
||||||
;; Check the number of fragments
|
;; The objects-gc should remove unused fragments
|
||||||
(let [rows (th/db-query :file-data {:file-id (:id file) :type "fragment"})]
|
(let [res (th/run-task! :objects-gc {})]
|
||||||
(t/is (= 5 (count rows)))
|
(t/is (= 3 (:processed res))))
|
||||||
(t/is (= 3 (count (filterv :deleted-at rows)))))
|
|
||||||
|
|
||||||
;; The objects-gc should remove unused fragments
|
;; Check the number of fragments
|
||||||
(let [res (th/run-task! :objects-gc {})]
|
(let [rows (th/db-query :file-data {:file-id (:id file) :type "fragment"})]
|
||||||
(t/is (= 3 (:processed res))))
|
(t/is (= 2 (count rows))))
|
||||||
|
|
||||||
;; Check the number of fragments
|
;; Add shape to page that should add a new fragment
|
||||||
(let [rows (th/db-query :file-data {:file-id (:id file) :type "fragment"})]
|
(update-file!
|
||||||
(t/is (= 2 (count rows))))
|
:file-id (:id file)
|
||||||
|
:profile-id (:id profile)
|
||||||
|
:revn 0
|
||||||
|
:vern 0
|
||||||
|
:changes
|
||||||
|
[{:type :add-obj
|
||||||
|
:page-id page-id
|
||||||
|
:id shape-id
|
||||||
|
:parent-id uuid/zero
|
||||||
|
:frame-id uuid/zero
|
||||||
|
:components-v2 true
|
||||||
|
:obj (cts/setup-shape
|
||||||
|
{:id shape-id
|
||||||
|
:name "image"
|
||||||
|
:frame-id uuid/zero
|
||||||
|
:parent-id uuid/zero
|
||||||
|
:type :rect})}])
|
||||||
|
|
||||||
;; Add shape to page that should add a new fragment
|
;; Check the number of fragments
|
||||||
(update-file!
|
(let [rows (th/db-query :file-data {:file-id (:id file) :type "fragment"})]
|
||||||
:file-id (:id file)
|
(t/is (= 3 (count rows))))
|
||||||
:profile-id (:id profile)
|
|
||||||
:revn 0
|
|
||||||
:vern 0
|
|
||||||
:changes
|
|
||||||
[{:type :add-obj
|
|
||||||
:page-id page-id
|
|
||||||
:id shape-id
|
|
||||||
:parent-id uuid/zero
|
|
||||||
:frame-id uuid/zero
|
|
||||||
:components-v2 true
|
|
||||||
:obj (cts/setup-shape
|
|
||||||
{:id shape-id
|
|
||||||
:name "image"
|
|
||||||
:frame-id uuid/zero
|
|
||||||
:parent-id uuid/zero
|
|
||||||
:type :rect})}])
|
|
||||||
|
|
||||||
;; Check the number of fragments
|
;; The file-gc should mark for remove unused fragments
|
||||||
(let [rows (th/db-query :file-data {:file-id (:id file) :type "fragment"})]
|
(t/is (true? (th/run-task! :file-gc {:file-id (:id file)})))
|
||||||
(t/is (= 3 (count rows))))
|
|
||||||
|
|
||||||
;; The file-gc should mark for remove unused fragments
|
;; The objects-gc should remove unused fragments
|
||||||
(t/is (true? (th/run-task! :file-gc {:file-id (:id file)})))
|
(let [res (th/run-task! :objects-gc {})]
|
||||||
|
(t/is (= 3 (:processed res))))
|
||||||
|
|
||||||
;; The objects-gc should remove unused fragments
|
;; Check the number of fragments;
|
||||||
(let [res (th/run-task! :objects-gc {})]
|
(let [rows (th/db-query :file-data {:file-id (:id file)
|
||||||
(t/is (= 3 (:processed res))))
|
:type "fragment"
|
||||||
|
:deleted-at nil})]
|
||||||
|
(t/is (= 2 (count rows))))
|
||||||
|
|
||||||
;; Check the number of fragments;
|
;; Lets proceed to delete all changes
|
||||||
(let [rows (th/db-query :file-data {:file-id (:id file)
|
(th/db-delete! :file-change {:file-id (:id file)})
|
||||||
:type "fragment"
|
(th/db-delete! :file-data {:file-id (:id file) :type "snapshot"})
|
||||||
:deleted-at nil})]
|
|
||||||
(t/is (= 2 (count rows))))
|
|
||||||
|
|
||||||
;; Lets proceed to delete all changes
|
(th/db-update! :file
|
||||||
(th/db-delete! :file-change {:file-id (:id file)})
|
{:has-media-trimmed false}
|
||||||
(th/db-delete! :file-data {:file-id (:id file) :type "snapshot"})
|
{:id (:id file)})
|
||||||
|
|
||||||
(th/db-update! :file
|
;; The file-gc should remove fragments related to changes
|
||||||
{:has-media-trimmed false}
|
;; snapshots previously deleted.
|
||||||
{:id (:id file)})
|
(t/is (true? (th/run-task! :file-gc {:file-id (:id file)})))
|
||||||
|
|
||||||
;; The file-gc should remove fragments related to changes
|
;; Check the number of fragments;
|
||||||
;; snapshots previously deleted.
|
(let [rows (th/db-query :file-data {:file-id (:id file) :type "fragment"})]
|
||||||
(t/is (true? (th/run-task! :file-gc {:file-id (:id file)})))
|
;; (pp/pprint rows)
|
||||||
|
(t/is (= 4 (count rows)))
|
||||||
|
(t/is (= 2 (count (remove :deleted-at rows)))))
|
||||||
|
|
||||||
;; Check the number of fragments;
|
(let [res (th/run-task! :objects-gc {})]
|
||||||
(let [rows (th/db-query :file-data {:file-id (:id file) :type "fragment"})]
|
(t/is (= 2 (:processed res))))
|
||||||
;; (pp/pprint rows)
|
|
||||||
(t/is (= 4 (count rows)))
|
|
||||||
(t/is (= 2 (count (remove :deleted-at rows)))))
|
|
||||||
|
|
||||||
(let [res (th/run-task! :objects-gc {})]
|
(let [rows (th/db-query :file-data {:file-id (:id file) :type "fragment"})]
|
||||||
(t/is (= 2 (:processed res))))
|
(t/is (= 2 (count rows))))))
|
||||||
|
|
||||||
(let [rows (th/db-query :file-data {:file-id (:id file) :type "fragment"})]
|
|
||||||
(t/is (= 2 (count rows)))))))
|
|
||||||
|
|
||||||
(t/deftest file-gc-with-thumbnails
|
(t/deftest file-gc-with-thumbnails
|
||||||
(letfn [(add-file-media-object [& {:keys [profile-id file-id]}]
|
(letfn [(add-file-media-object [& {:keys [profile-id file-id]}]
|
||||||
@@ -279,20 +265,6 @@
|
|||||||
|
|
||||||
;; (th/print-result! out)
|
;; (th/print-result! out)
|
||||||
(t/is (nil? (:error out)))
|
(t/is (nil? (:error out)))
|
||||||
(:result out)))
|
|
||||||
|
|
||||||
(update-file! [& {:keys [profile-id file-id changes revn] :or {revn 0}}]
|
|
||||||
(let [params {::th/type :update-file
|
|
||||||
::rpc/profile-id profile-id
|
|
||||||
:id file-id
|
|
||||||
:session-id (uuid/random)
|
|
||||||
:revn revn
|
|
||||||
:vern 0
|
|
||||||
:features cfeat/supported-features
|
|
||||||
:changes changes}
|
|
||||||
out (th/command! params)]
|
|
||||||
;; (th/print-result! out)
|
|
||||||
(t/is (nil? (:error out)))
|
|
||||||
(:result out)))]
|
(:result out)))]
|
||||||
|
|
||||||
(let [storage (:app.storage/storage th/*system*)
|
(let [storage (:app.storage/storage th/*system*)
|
||||||
|
|||||||
Reference in New Issue
Block a user