|
|
@@ -1,19 +1,22 @@
|
|
|
(ns frontend.handler.plugin-config-test
|
|
|
- (:require [clojure.test :refer [is use-fixtures testing deftest]]
|
|
|
- [frontend.test.helper :as test-helper :include-macros true :refer [deftest-async]]
|
|
|
- [frontend.test.node-helper :as test-node-helper]
|
|
|
- [frontend.test.node-fixtures :as node-fixtures]
|
|
|
- [frontend.handler.plugin-config :as plugin-config-handler]
|
|
|
- [frontend.handler.global-config :as global-config-handler]
|
|
|
- [frontend.schema.handler.plugin-config :as plugin-config-schema]
|
|
|
- ["fs" :as fs-node]
|
|
|
+ (:require ["fs" :as fs-node]
|
|
|
+ ["fs/promises" :as fsp]
|
|
|
["path" :as node-path]
|
|
|
[clojure.edn :as edn]
|
|
|
- [malli.generator :as mg]
|
|
|
- [promesa.core :as p]
|
|
|
[clojure.string :as string]
|
|
|
- [frontend.handler.notification :as notification]))
|
|
|
+ [clojure.test :refer [is use-fixtures testing deftest]]
|
|
|
+ [frontend.fs :as fs]
|
|
|
+ [frontend.handler.global-config :as global-config-handler]
|
|
|
+ [frontend.handler.notification :as notification]
|
|
|
+ [frontend.handler.plugin-config :as plugin-config-handler]
|
|
|
+ [frontend.schema.handler.plugin-config :as plugin-config-schema]
|
|
|
+ [frontend.test.helper :as test-helper :include-macros true :refer [deftest-async]]
|
|
|
+ [frontend.test.node-fixtures :as node-fixtures]
|
|
|
+ [frontend.test.node-helper :as test-node-helper]
|
|
|
+ [malli.generator :as mg]
|
|
|
+ [promesa.core :as p]))
|
|
|
|
|
|
+;; For tests that call fs/readFile
|
|
|
(use-fixtures :once node-fixtures/redef-get-fs)
|
|
|
|
|
|
(defn- create-global-config-dir
|
|
|
@@ -37,13 +40,14 @@
|
|
|
body (pr-str (mg/generate plugin-config-schema/Plugins-edn {:size 10}))]
|
|
|
(fs-node/writeFileSync (plugin-config-handler/plugin-config-path) body)
|
|
|
|
|
|
- (->
|
|
|
- (p/do!
|
|
|
- (plugin-config-handler/add-or-update-plugin plugin-to-add)
|
|
|
- (is (= (dissoc plugin-to-add :id)
|
|
|
- (:foo (edn/read-string (str (fs-node/readFileSync (plugin-config-handler/plugin-config-path))))))))
|
|
|
+ (p/with-redefs [fs/write-file! fsp/writeFile]
|
|
|
+ (->
|
|
|
+ (p/do!
|
|
|
+ (plugin-config-handler/add-or-update-plugin plugin-to-add)
|
|
|
+ (is (= (dissoc plugin-to-add :id)
|
|
|
+ (:foo (edn/read-string (str (fs-node/readFileSync (plugin-config-handler/plugin-config-path))))))))
|
|
|
|
|
|
- (p/finally #(delete-global-config-dir dir)))))
|
|
|
+ (p/finally #(delete-global-config-dir dir))))))
|
|
|
|
|
|
(deftest-async remove-plugin
|
|
|
(let [dir (create-global-config-dir)
|
|
|
@@ -53,14 +57,15 @@
|
|
|
some-plugin-id (first (keys plugins))]
|
|
|
(fs-node/writeFileSync (plugin-config-handler/plugin-config-path) (pr-str plugins))
|
|
|
|
|
|
- (->
|
|
|
- (p/do!
|
|
|
- (plugin-config-handler/remove-plugin some-plugin-id)
|
|
|
- (is (= nil
|
|
|
- (get (edn/read-string (str (fs-node/readFileSync (plugin-config-handler/plugin-config-path))))
|
|
|
- some-plugin-id))))
|
|
|
+ (p/with-redefs [fs/write-file! fsp/writeFile]
|
|
|
+ (->
|
|
|
+ (p/do!
|
|
|
+ (plugin-config-handler/remove-plugin some-plugin-id)
|
|
|
+ (is (= nil
|
|
|
+ (get (edn/read-string (str (fs-node/readFileSync (plugin-config-handler/plugin-config-path))))
|
|
|
+ some-plugin-id))))
|
|
|
|
|
|
- (p/finally #(delete-global-config-dir dir)))))
|
|
|
+ (p/finally #(delete-global-config-dir dir))))))
|
|
|
|
|
|
(deftest-async open-replace-plugins-modal-malformed-edn
|
|
|
(let [dir (create-global-config-dir)
|