This commit is contained in:
Andrés Moya 2026-07-23 12:47:30 +02:00
parent 6db9d2d880
commit c80a94d9a3
2 changed files with 48 additions and 0 deletions

View File

@ -470,6 +470,15 @@
[file-data tokens-source]
(assoc file-data :tokens-source tokens-source))
(defn tokens-source?
"Returns true if the given id is the current tokens source of the file-data.
When no tokens-source is set, the file's own id is considered the source."
[file-data id]
(assert (uuid? id) "expected valid uuid")
(let [source (or (:tokens-source file-data)
(:id file-data))]
(= source id)))
(defn get-tokens-lib
[file-data]
(:tokens-lib file-data))

View File

@ -283,6 +283,45 @@
file-data' (cfo/set-tokens-source file-data source-id)]
(t/is (= source-id (:tokens-source file-data'))))))
(t/deftest test-tokens-source?
(t/testing "file-data has no tokens-source, asking for the same id as file-data returns true"
(let [file (thf/sample-file :file1)
file-data (:data file)]
(t/is (true? (cfo/tokens-source? file-data (:id file-data))))))
(t/testing "file-data has no tokens-source, asking for any other uuid returns false"
(let [file (thf/sample-file :file1)
file-data (:data file)]
(t/is (false? (cfo/tokens-source? file-data (uuid/next))))))
(t/testing "file-data has tokens-source equal to its own id, asking for the same id as file-data returns true"
(let [file (thf/sample-file :file1)
file-data (cfo/set-tokens-source (:data file) (:id (:data file)))]
(t/is (true? (cfo/tokens-source? file-data (:id file-data))))))
(t/testing "file-data has tokens-source equal to its own id, asking for any other uuid returns false"
(let [file (thf/sample-file :file1)
file-data (cfo/set-tokens-source (:data file) (:id (:data file)))]
(t/is (false? (cfo/tokens-source? file-data (uuid/next))))))
(t/testing "file-data has a new uuid as tokens-source, asking for the same id as file-data returns false"
(let [source-id (thi/new-id! :tokens-source)
file (thf/sample-file :file1)
file-data (cfo/set-tokens-source (:data file) source-id)]
(t/is (false? (cfo/tokens-source? file-data (:id file-data))))))
(t/testing "file-data has a new uuid as tokens-source, asking for the same id as the tokens-source returns true"
(let [source-id (thi/new-id! :tokens-source)
file (thf/sample-file :file1)
file-data (cfo/set-tokens-source (:data file) source-id)]
(t/is (true? (cfo/tokens-source? file-data source-id)))))
(t/testing "file-data has a new uuid as tokens-source, asking for any other uuid returns false"
(let [source-id (thi/new-id! :tokens-source)
file (thf/sample-file :file1)
file-data (cfo/set-tokens-source (:data file) source-id)]
(t/is (false? (cfo/tokens-source? file-data (uuid/next)))))))
(t/deftest test-get-tokens-status
(t/testing "returns tokens-status from file data"
(let [tokens-status (ctos/make-tokens-status)