added validation
This commit is contained in:
@@ -32,54 +32,64 @@
|
||||
(is (seqable? (:transaction-rules result))))))
|
||||
|
||||
(deftest upsert-transaction-rule
|
||||
(testing "it should add rules"
|
||||
(let [{:strs [vendor-id account-id]} (-> (d/connect uri)
|
||||
(d/transact
|
||||
[{:vendor/name "Bryce's Meat Co"
|
||||
:db/id "vendor-id"}
|
||||
{:account/name "hello"
|
||||
:db/id "account-id"}])
|
||||
deref
|
||||
:tempids)
|
||||
q (v/graphql-query {:venia/operation {:operation/type :mutation
|
||||
:operation/name "UpsertTransactionRule"}
|
||||
:venia/queries [{:query/data (sut/->graphql [:upsert-transaction-rule
|
||||
{:transaction-rule {:description "123"
|
||||
:vendor-id vendor-id
|
||||
:accounts [{:account-id account-id
|
||||
:percentage "0.5"
|
||||
:location "B"}
|
||||
{:account-id account-id
|
||||
:percentage "0.5"
|
||||
:location "A"}]}}
|
||||
[:id :description
|
||||
[:vendor [:name]]
|
||||
[:accounts [:id :percentage [:account [:name]]]]]])}]})
|
||||
result (-> (sut/query nil q)
|
||||
:data
|
||||
:upsert-transaction-rule)]
|
||||
|
||||
(is (= "123" (:description result)))
|
||||
(is (= "Bryce's Meat Co" (-> result :vendor :name)))
|
||||
(is (= "hello" (-> result :accounts (get 0) :account :name )))
|
||||
(is (:id result))
|
||||
(testing "it should delete removed rules"
|
||||
(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 vendor-id
|
||||
:accounts [{:id (-> result :accounts (get 0) :id)
|
||||
:account-id account-id
|
||||
:percentage "1.0"
|
||||
:location "B"}]}}
|
||||
[[:accounts [:id :percentage [:account [:name]]]]]])}]})
|
||||
result (-> (sut/query nil q)
|
||||
:data
|
||||
:upsert-transaction-rule)]
|
||||
(let [{:strs [vendor-id account-id]} (-> (d/connect uri)
|
||||
(d/transact
|
||||
[{:vendor/name "Bryce's Meat Co"
|
||||
:db/id "vendor-id"}
|
||||
{:account/name "hello"
|
||||
:db/id "account-id"}])
|
||||
deref
|
||||
:tempids)]
|
||||
(testing "it should reject rules that don't add up to 100%"
|
||||
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
|
||||
:operation/name "UpsertTransactionRule"}
|
||||
:venia/queries [{:query/data (sut/->graphql [:upsert-transaction-rule
|
||||
{:transaction-rule {:accounts [{:account-id account-id
|
||||
:percentage "0.25"
|
||||
:location "B"}]}}
|
||||
[:id ]])}]})
|
||||
]
|
||||
(is (thrown? clojure.lang.ExceptionInfo (sut/query nil q)))))
|
||||
(testing "it should add rules"
|
||||
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
|
||||
:operation/name "UpsertTransactionRule"}
|
||||
:venia/queries [{:query/data (sut/->graphql [:upsert-transaction-rule
|
||||
{:transaction-rule {:description "123"
|
||||
:vendor-id vendor-id
|
||||
:accounts [{:account-id account-id
|
||||
:percentage "0.5"
|
||||
:location "B"}
|
||||
{:account-id account-id
|
||||
:percentage "0.5"
|
||||
:location "A"}]}}
|
||||
[:id :description
|
||||
[:vendor [:name]]
|
||||
[:accounts [:id :percentage [:account [:name]]]]]])}]})
|
||||
result (-> (sut/query nil q)
|
||||
:data
|
||||
:upsert-transaction-rule)]
|
||||
|
||||
(is (= "123" (:description result)))
|
||||
(is (= "Bryce's Meat Co" (-> result :vendor :name)))
|
||||
(is (= "hello" (-> result :accounts (get 0) :account :name )))
|
||||
(is (:id result))
|
||||
(testing "it should delete removed rules"
|
||||
(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 vendor-id
|
||||
:accounts [{:id (-> result :accounts (get 0) :id)
|
||||
:account-id account-id
|
||||
:percentage "1.0"
|
||||
:location "B"}]}}
|
||||
[[:accounts [:id :percentage [:account [:name]]]]]])}]})
|
||||
result (-> (sut/query nil q)
|
||||
:data
|
||||
:upsert-transaction-rule)]
|
||||
|
||||
(is (= 1 (count (:accounts result)))))))))
|
||||
(is (= 1 (count (:accounts result))))))))))
|
||||
|
||||
(deftest test-transaction-rule
|
||||
(testing "it should match rules"
|
||||
|
||||
Reference in New Issue
Block a user