critical feature - you can now unset fields.
This commit is contained in:
@@ -30,7 +30,6 @@
|
|||||||
(update-in [:args] into (get-in query-part-2 [:args]))))
|
(update-in [:args] into (get-in query-part-2 [:args]))))
|
||||||
|
|
||||||
(defn remove-nils [m]
|
(defn remove-nils [m]
|
||||||
|
|
||||||
(let [result (reduce-kv
|
(let [result (reduce-kv
|
||||||
(fn [m k v]
|
(fn [m k v]
|
||||||
(if (not (nil? v))
|
(if (not (nil? v))
|
||||||
@@ -43,6 +42,25 @@
|
|||||||
result
|
result
|
||||||
nil)))
|
nil)))
|
||||||
|
|
||||||
|
(defn replace-nils-with-retract [updated original]
|
||||||
|
(let [result (reduce-kv
|
||||||
|
(fn [[m & retractions] k v]
|
||||||
|
(cond (and (nil? v)
|
||||||
|
(not (nil? (get original k))))
|
||||||
|
(into [m] (conj retractions [:db/retract (:db/id original) k (or (:db/id (get original k))
|
||||||
|
(get original k))]))
|
||||||
|
|
||||||
|
(nil? v)
|
||||||
|
(into [m] retractions)
|
||||||
|
|
||||||
|
:else
|
||||||
|
(into [(assoc m k v)] retractions)))
|
||||||
|
[{}]
|
||||||
|
updated)]
|
||||||
|
(if (seq result)
|
||||||
|
result
|
||||||
|
nil)))
|
||||||
|
|
||||||
|
|
||||||
(def vendor-schema
|
(def vendor-schema
|
||||||
[{:db/ident :vendor/original-id
|
[{:db/ident :vendor/original-id
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
(:require [auto-ap.datomic.transaction-rules :as tr]
|
(:require [auto-ap.datomic.transaction-rules :as tr]
|
||||||
[auto-ap.datomic.transactions :as t]
|
[auto-ap.datomic.transactions :as t]
|
||||||
[datomic.api :as d]
|
[datomic.api :as d]
|
||||||
[auto-ap.datomic :refer [remove-nils uri merge-query]]
|
[auto-ap.datomic :refer [remove-nils uri merge-query replace-nils-with-retract]]
|
||||||
[auto-ap.utils :refer [dollars=]]
|
[auto-ap.utils :refer [dollars=]]
|
||||||
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page snake->kebab]]
|
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page snake->kebab]]
|
||||||
[clj-time.coerce :as c]
|
[clj-time.coerce :as c]
|
||||||
@@ -59,23 +59,24 @@
|
|||||||
(nil? yodlee_merchant_id))
|
(nil? yodlee_merchant_id))
|
||||||
(let [error (str "You must provide a description or a yodlee merchant")]
|
(let [error (str "You must provide a description or a yodlee merchant")]
|
||||||
(throw (ex-info error {:validation-error error}))))
|
(throw (ex-info error {:validation-error error}))))
|
||||||
transaction [(remove-nils #:transaction-rule {:db/id (if id
|
transaction (replace-nils-with-retract #:transaction-rule {:db/id (if id
|
||||||
id
|
id
|
||||||
"transaction-rule")
|
"transaction-rule")
|
||||||
:description description
|
:description description
|
||||||
:note note
|
:note note
|
||||||
:client client_id
|
:client client_id
|
||||||
:bank-account bank_account_id
|
:bank-account bank_account_id
|
||||||
:yodlee-merchant yodlee_merchant_id
|
:yodlee-merchant yodlee_merchant_id
|
||||||
:amount-lte amount_lte
|
:amount-lte amount_lte
|
||||||
:amount-gte amount_gte
|
:amount-gte amount_gte
|
||||||
:vendor vendor_id
|
:vendor vendor_id
|
||||||
:transaction-approval-status
|
:transaction-approval-status
|
||||||
(some->> transaction_approval_status
|
(some->> transaction_approval_status
|
||||||
name
|
name
|
||||||
snake->kebab
|
snake->kebab
|
||||||
(keyword "transaction-approval-status"))
|
(keyword "transaction-approval-status"))
|
||||||
:accounts (map transaction-rule-account->entity accounts)})]
|
:accounts (map transaction-rule-account->entity accounts)}
|
||||||
|
existing-transaction)
|
||||||
|
|
||||||
_ (println transaction)
|
_ (println transaction)
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,8 @@
|
|||||||
:location "B"}]}}
|
:location "B"}]}}
|
||||||
[:id ]])}]})]
|
[:id ]])}]})]
|
||||||
(is (thrown? clojure.lang.ExceptionInfo (sut/query nil q)))))
|
(is (thrown? clojure.lang.ExceptionInfo (sut/query nil q)))))
|
||||||
|
|
||||||
|
|
||||||
(testing "It should reject rules that are missing both description and merchant"
|
(testing "It should reject rules that are missing both description and merchant"
|
||||||
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
|
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
|
||||||
:operation/name "UpsertTransactionRule"}
|
:operation/name "UpsertTransactionRule"}
|
||||||
@@ -90,6 +92,25 @@
|
|||||||
(is (= :approved (:transaction-approval-status result)))
|
(is (= :approved (:transaction-approval-status result)))
|
||||||
(is (= "hello" (-> result :accounts (get 0) :account :name )))
|
(is (= "hello" (-> result :accounts (get 0) :account :name )))
|
||||||
(is (:id result))
|
(is (:id result))
|
||||||
|
|
||||||
|
(testing "it should unset removed fields"
|
||||||
|
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
|
||||||
|
:operation/name "UpsertTransactionRule"}
|
||||||
|
:venia/queries [{:query/data (sut/->graphql [:upsert-transaction-rule
|
||||||
|
{:transaction-rule {:id (:id result)
|
||||||
|
:description "123"
|
||||||
|
:vendor-id nil
|
||||||
|
:accounts [{:id (-> result :accounts (get 0) :id)
|
||||||
|
:account-id account-id
|
||||||
|
:percentage "1.0"
|
||||||
|
:location "B"}]}}
|
||||||
|
[[:vendor [:name]]]])}]})
|
||||||
|
result (-> (sut/query nil q)
|
||||||
|
:data
|
||||||
|
:upsert-transaction-rule)]
|
||||||
|
|
||||||
|
(is (nil? (:vendor result)))))
|
||||||
|
|
||||||
(testing "it should delete removed rules"
|
(testing "it should delete removed rules"
|
||||||
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
|
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
|
||||||
:operation/name "UpsertTransactionRule"}
|
:operation/name "UpsertTransactionRule"}
|
||||||
|
|||||||
Reference in New Issue
Block a user