This commit is contained in:
Andrés Moya 2026-07-23 11:51:13 +02:00
parent fdb5970165
commit 6db9d2d880
2 changed files with 17 additions and 16 deletions

View File

@ -14,7 +14,6 @@
[app.common.types.tokens-lib :as ctob]
[app.common.types.tokens-status :as ctos]
[app.common.uuid :as uuid]
[clojure.datafy :refer [datafy]]
[clojure.test :as t]))
;; Helper functions
@ -235,25 +234,25 @@
(t/is (ctos/tokens-status? (:tokens-status file-data')))))
(t/testing "ensure-tokens-lib should not add a tokens-lib if there is a tokens-source"
(let [tokens-source (uuid/next)
(let [source-id (uuid/next)
tokens-status (ctos/make-tokens-status)
file (-> (thf/sample-file :file1)
(assoc-in [:data :tokens-source] tokens-source)
(assoc-in [:data :tokens-source] source-id)
(assoc-in [:data :tokens-status] tokens-status))
file-data (ctf/file-data file)
file-data' (cfo/ensure-tokens-lib file-data)]
(t/is (not (contains? file-data' :tokens-lib)))
(t/is (= tokens-source (:tokens-source file-data')))
(t/is (= source-id (:tokens-source file-data')))
(t/is (= tokens-status (:tokens-status file-data')))))
(t/testing "ensure-tokens-lib should not add a tokens-lib if there is a tokens-source, but should add a tokens-status if it's missing"
(let [tokens-source (uuid/next)
(let [source-id (uuid/next)
file (-> (thf/sample-file :file1)
(assoc-in [:data :tokens-source] tokens-source))
(assoc-in [:data :tokens-source] source-id))
file-data (ctf/file-data file)
file-data' (cfo/ensure-tokens-lib file-data)]
(t/is (not (contains? file-data' :tokens-lib)))
(t/is (= tokens-source (:tokens-source file-data')))
(t/is (= source-id (:tokens-source file-data')))
(t/is (contains? file-data' :tokens-status))
(t/is (ctos/tokens-status? (:tokens-status file-data'))))))
@ -268,20 +267,21 @@
(t/deftest test-get-tokens-source
(t/testing "returns tokens-source from file data"
(let [file-id (thi/new-id! :tokens-source)
file-data {:tokens-source file-id}]
(t/is (= file-id (cfo/get-tokens-source file-data)))))
(let [source-id (thi/new-id! :tokens-source)
file (-> (thf/sample-file :file1)
(assoc-in [:data :tokens-source] source-id))]
(t/is (= source-id (cfo/get-tokens-source (:data file))))))
(t/testing "returns nil when no tokens-source"
(t/is (nil? (cfo/get-tokens-source {})))))
(t/is (nil? (cfo/get-tokens-source (thf/sample-file :file1))))))
(t/deftest test-set-tokens-source
(t/testing "sets tokens-source on file data"
(let [file-id (thi/new-id! :tokens-source)
file-data {:other :data}
file-data' (cfo/set-tokens-source file-data file-id)]
(t/is (= file-id (:tokens-source file-data')))
(t/is (= :data (:other file-data'))))))
(let [source-id (thi/new-id! :tokens-source)
file (thf/sample-file :file1)
file-data (:data file)
file-data' (cfo/set-tokens-source file-data source-id)]
(t/is (= source-id (:tokens-source file-data'))))))
(t/deftest test-get-tokens-status
(t/testing "returns tokens-status from file data"

View File

@ -38,6 +38,7 @@
([state file-id]
(dm/get-in state [:files file-id :data])))
;; TODO perhaps this is not necessary, lookup-tokens-lib should be enough
(defn lookup-tokens-source-data
[state]
(let [current-file-data (lookup-file-data state)