making tests pass again
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
(ns auto-ap.functional.test
|
||||
(:require [clojure.test :as t :refer :all]
|
||||
[etaoin.api :as e]
|
||||
[etaoin.keys :as k]
|
||||
[config.core :refer [env]]
|
||||
[clj-time.core :as time]
|
||||
[buddy.sign.jwt :as jwt]))
|
||||
|
||||
(def base-url "https://staging3.app.integreatconsult.com")
|
||||
(defn login-admin [driver]
|
||||
(let [jwt-token (jwt/sign {:user "Automated Tests"
|
||||
:exp (time/plus (time/now) (time/days 30))
|
||||
:user/role "admin"
|
||||
:user/name "Automated Tests"}
|
||||
(:jwt-secret env)
|
||||
{:alg :hs512})]
|
||||
(e/go driver (str base-url "/?jwt=" jwt-token))
|
||||
(e/wait-visible driver {:tag :h1
|
||||
:class "title"})))
|
||||
|
||||
(deftest create-invoice
|
||||
(testing "Creating a new invoice"
|
||||
(e/with-wait-timeout 10
|
||||
(e/with-firefox {} driver
|
||||
(login-admin driver)
|
||||
(e/click driver {:tag :a :fn/text "Invoices"})
|
||||
(e/wait-visible driver {:tag :h1
|
||||
:class "title"
|
||||
:fn/text "Unpaid Invoices"})))))
|
||||
|
||||
|
||||
(deftest edit-client
|
||||
(testing "Editing a client"
|
||||
(e/with-wait-timeout 10
|
||||
(e/with-firefox {} driver
|
||||
(login-admin driver)
|
||||
|
||||
(e/click driver {:tag :a :class "navbar-link login"})
|
||||
(e/click driver {:tag :a :fn/text "Administration"})
|
||||
|
||||
(e/wait-visible driver {:tag :h1
|
||||
:class "title"
|
||||
:fn/text "Admin"})
|
||||
(e/click driver {:tag :span :fn/text "Clients"})
|
||||
(e/wait-visible driver {:tag :h1
|
||||
:class "title"
|
||||
:fn/text "Clients"})
|
||||
(e/click driver {:tag :i :class "fa fa-pencil"})
|
||||
(e/wait-visible driver {:tag :button
|
||||
:fn/text "Save"})
|
||||
(e/click driver {:tag :button :fn/text "Save"})
|
||||
(e/wait-invisible driver {:tag :form})))))
|
||||
@@ -83,7 +83,10 @@
|
||||
result (sut/transaction->txs base-transaction
|
||||
(d/entity (d/db conn) bank-account-id)
|
||||
noop-rule)]
|
||||
(t/is (= [(assoc base-transaction :transaction/approval-status :transaction-approval-status/unapproved)]
|
||||
(t/is (= [(assoc base-transaction
|
||||
:transaction/approval-status :transaction-approval-status/unapproved
|
||||
:transaction/bank-account bank-account-id
|
||||
:transaction/client client-id)]
|
||||
result))))
|
||||
|
||||
(t/testing "Should match an uncleared check"
|
||||
@@ -113,6 +116,18 @@
|
||||
:payment/status :payment-status/cleared}
|
||||
(:transaction/payment transaction-result))))
|
||||
|
||||
|
||||
(t/testing "Should match a check that matches on amount if check number does not match"
|
||||
(let [[transaction-result] (sut/transaction->txs (assoc base-transaction
|
||||
:transaction/description-original "CHECK 12301"
|
||||
:transaction/amount -30.0)
|
||||
(d/entity (d/db conn ) bank-account-id)
|
||||
noop-rule)]
|
||||
|
||||
(t/is (= {:db/id payment-id
|
||||
:payment/status :payment-status/cleared}
|
||||
(:transaction/payment transaction-result)))))
|
||||
|
||||
(t/testing "Should not match an already matched check"
|
||||
@(d/transact (d/connect uri) [{:db/id payment-id :payment/status :payment-status/cleared}])
|
||||
(let [[result] (sut/transaction->txs (assoc base-transaction
|
||||
|
||||
@@ -39,11 +39,13 @@
|
||||
|
||||
(defn new-transaction [args]
|
||||
(merge {:transaction/amount 100.0
|
||||
:transaction/date #inst "2021-01-01"
|
||||
:transaction/id (.toString (java.util.UUID/randomUUID))}
|
||||
args))
|
||||
|
||||
(defn new-invoice [args]
|
||||
(merge {:invoice/total 100.0
|
||||
:invoice/date #inst "2021-01-01"
|
||||
:invoice/invoice-number (.toString (java.util.UUID/randomUUID))}
|
||||
args))
|
||||
|
||||
@@ -88,7 +90,7 @@
|
||||
(deftest ledger-page
|
||||
(testing "ledger"
|
||||
(testing "it should find ledger entries"
|
||||
(let [result (:ledger-page (:data (sut/query (admin-token) "{ ledger_page(client_id: null) { count, start, journal_entries { id } }}")))]
|
||||
(let [result (:ledger-page (:data (sut/query (admin-token) "{ ledger_page(filters: {client_id: null}) { count, start, journal_entries { id } }}")))]
|
||||
(is (int? (:count result)))
|
||||
(is (int? (:start result)))
|
||||
(is (seqable? (:journal-entries result)))))))
|
||||
@@ -97,7 +99,7 @@
|
||||
(deftest vendors
|
||||
(testing "vendors"
|
||||
(testing "it should find vendors"
|
||||
(let [result (:ledger-page (:data (sut/query (admin-token) "{ ledger_page(client_id: null) { count, start, journal_entries { id } }}")))]
|
||||
(let [result (:ledger-page (:data (sut/query (admin-token) "{ ledger_page(filters: {client_id: null}) { count, start, journal_entries { id } }}")))]
|
||||
(is (int? (:count result)))
|
||||
(is (int? (:start result)))
|
||||
(is (seqable? (:journal-entries result)))))))
|
||||
@@ -128,7 +130,7 @@
|
||||
:venia/queries [{:query/data (sut/->graphql [:upsert-transaction-rule
|
||||
{:transaction-rule {:accounts [{:account-id account-id
|
||||
:percentage "0.25"
|
||||
:location "B"}]}}
|
||||
:location "Shared"}]}}
|
||||
[:id ]])}]})]
|
||||
(is (thrown? clojure.lang.ExceptionInfo (sut/query (admin-token) q)))))
|
||||
|
||||
@@ -139,7 +141,7 @@
|
||||
:venia/queries [{:query/data (sut/->graphql [:upsert-transaction-rule
|
||||
{:transaction-rule {:accounts [{:account-id account-id
|
||||
:percentage "1.0"
|
||||
:location "B"}]}}
|
||||
:location "Shared"}]}}
|
||||
[:id ]])}]})]
|
||||
(is (thrown? clojure.lang.ExceptionInfo (sut/query (admin-token) q)))))
|
||||
(testing "it should add rules"
|
||||
@@ -152,10 +154,10 @@
|
||||
:transaction-approval-status :approved
|
||||
:accounts [{:account-id account-id
|
||||
:percentage "0.5"
|
||||
:location "B"}
|
||||
:location "Shared"}
|
||||
{:account-id account-id
|
||||
:percentage "0.5"
|
||||
:location "A"}]}}
|
||||
:location "Shared"}]}}
|
||||
[:id :description
|
||||
:transaction-approval-status
|
||||
[:vendor [:name]]
|
||||
@@ -182,7 +184,7 @@
|
||||
:accounts [{:id (-> result :accounts (get 0) :id)
|
||||
:account-id account-id
|
||||
:percentage "1.0"
|
||||
:location "B"}]}}
|
||||
:location "Shared"}]}}
|
||||
[[:vendor [:name]]]])}]})
|
||||
result (-> (sut/query (admin-token) q)
|
||||
:data
|
||||
@@ -200,7 +202,7 @@
|
||||
:accounts [{:id (-> result :accounts (get 0) :id)
|
||||
:account-id account-id
|
||||
:percentage "1.0"
|
||||
:location "B"}]}}
|
||||
:location "Shared"}]}}
|
||||
[[:accounts [:id :percentage [:account [:name]]]]]])}]})
|
||||
result (-> (sut/query (admin-token) q)
|
||||
:data
|
||||
@@ -208,22 +210,6 @@
|
||||
|
||||
(is (= 1 (count (:accounts result))))))))))
|
||||
|
||||
(deftest test-get-yodlee-merchants
|
||||
(testing "it should find yodlee merchants"
|
||||
@(d/transact (d/connect uri)
|
||||
[{:yodlee-merchant/name "Merchant 1"
|
||||
:yodlee-merchant/yodlee-id "123"}
|
||||
{:yodlee-merchant/name "Merchant 2"
|
||||
:yodlee-merchant/yodlee-id "456"}])
|
||||
|
||||
(is (= [{:name "Merchant 1" :yodlee-id "123"} {:name "Merchant 2" :yodlee-id "456"}]
|
||||
(-> (sut/query (admin-token) (v/graphql-query {:venia/operation {:operation/type :query
|
||||
:operation/name "GetYodleeMerchants"}
|
||||
:venia/queries [{:query/data (sut/->graphql [:yodlee-merchants
|
||||
[:yodlee-id :name]])}]}))
|
||||
:data
|
||||
:yodlee-merchants)))))
|
||||
|
||||
|
||||
(deftest test-transaction-rule
|
||||
(testing "it should match rules"
|
||||
@@ -236,7 +222,8 @@
|
||||
:bank-account/name "1"}
|
||||
|
||||
:transaction/amount 1.00
|
||||
:transaction/id "2019-01-05 matching-desc 1"}
|
||||
:transaction/id "2019-01-05 matching-desc 1"
|
||||
:db/id "a"}
|
||||
|
||||
{:transaction/description-original "nonmatching-desc"
|
||||
:transaction/client {:client/name "2"
|
||||
@@ -245,8 +232,11 @@
|
||||
:bank-account/name "2"}
|
||||
:transaction/date #inst "2019-01-15T23:23:00.000-08:00"
|
||||
:transaction/amount 2.00
|
||||
:transaction/id "2019-01-15 nonmatching-desc 2"}])
|
||||
{:strs [client-1 client-2 bank-account-1 bank-account-2]} (get-in matching-transaction [:tempids])
|
||||
:transaction/id "2019-01-15 nonmatching-desc 2"
|
||||
:db/id "b"}])
|
||||
{:strs [a b client-1 client-2 bank-account-1 bank-account-2]} (get-in matching-transaction [:tempids])
|
||||
a (str a)
|
||||
b (str b)
|
||||
|
||||
rule-test (fn [rule]
|
||||
(-> (sut/query (admin-token) (v/graphql-query {:venia/operation {:operation/type :query
|
||||
@@ -257,27 +247,27 @@
|
||||
:data
|
||||
:test-transaction-rule))]
|
||||
(testing "based on date "
|
||||
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 14 :dom-lte 16})))
|
||||
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 14})))
|
||||
(is (= (set [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}]) (set (rule-test {:dom-lte 15}))))
|
||||
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 15})))
|
||||
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 15 :dom-lte 15}))))
|
||||
(is (= [{:id b}] (rule-test {:dom-gte 14 :dom-lte 16})))
|
||||
(is (= [{:id b}] (rule-test {:dom-gte 14})))
|
||||
(is (= (set [{:id a} {:id b}]) (set (rule-test {:dom-lte 15}))))
|
||||
(is (= [{:id b}] (rule-test {:dom-gte 15})))
|
||||
(is (= [{:id b}] (rule-test {:dom-gte 15 :dom-lte 15}))))
|
||||
|
||||
(testing "based on description"
|
||||
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:description "^match"}))))
|
||||
(is (= [{:id a}] (rule-test {:description "^match"}))))
|
||||
|
||||
(testing "based on amount"
|
||||
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:amount-gte 1.0 :amount-lte 1.0})))
|
||||
(is (= (set [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}]) (set (rule-test {:amount-gte 1.0 }))) )
|
||||
(is (= (set [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}]) (set (rule-test {:amount-lte 2.0 }))) ))
|
||||
(is (= [{:id a}] (rule-test {:amount-gte 1.0 :amount-lte 1.0})))
|
||||
(is (= (set [{:id a} {:id b}]) (set (rule-test {:amount-gte 1.0 }))) )
|
||||
(is (= (set [{:id a} {:id b}]) (set (rule-test {:amount-lte 2.0 }))) ))
|
||||
|
||||
(testing "based on client"
|
||||
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:client-id client-1})))
|
||||
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:client-id client-2}))))
|
||||
(is (= [{:id a}] (rule-test {:client-id (str client-1)})))
|
||||
(is (= [{:id b}] (rule-test {:client-id (str client-2)}))))
|
||||
|
||||
(testing "based on bank account"
|
||||
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:bank-account-id bank-account-1})))
|
||||
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:bank-account-id bank-account-2})))))))
|
||||
(is (= [{:id a}] (rule-test {:bank-account-id (str bank-account-1)})))
|
||||
(is (= [{:id b}] (rule-test {:bank-account-id (str bank-account-2)})))))))
|
||||
|
||||
(deftest test-match-transaction-rule
|
||||
(testing "it should apply a rules"
|
||||
|
||||
Reference in New Issue
Block a user