From c98766873ef348f86db5e7c0835e52015fa9596d Mon Sep 17 00:00:00 2001 From: Bryce Date: Thu, 31 Aug 2023 23:43:19 -0700 Subject: [PATCH] fixes tests. --- data/inference-outcome.csv | 0 .../solr/data/plaid_merchants/core.properties | 0 notes.txt | 21 +++++++----- src/clj/auto_ap/datomic/checks.clj | 5 ++- src/clj/auto_ap/datomic/expected_deposit.clj | 2 +- src/clj/auto_ap/datomic/invoices.clj | 2 +- src/clj/auto_ap/datomic/ledger.clj | 2 +- src/clj/auto_ap/datomic/transactions.clj | 2 +- src/clj/auto_ap/graphql/checks.clj | 1 + src/clj/auto_ap/graphql/invoices.clj | 1 + test/clj/auto_ap/import/plaid_test.clj | 4 +-- test/clj/auto_ap/integration/graphql.clj | 32 +++++++++---------- .../auto_ap/integration/graphql/checks.clj | 21 ++++++------ .../auto_ap/integration/graphql/invoices.clj | 2 +- 14 files changed, 49 insertions(+), 46 deletions(-) mode change 100644 => 100755 data/inference-outcome.csv mode change 100644 => 100755 data/solr/data/plaid_merchants/core.properties diff --git a/data/inference-outcome.csv b/data/inference-outcome.csv old mode 100644 new mode 100755 diff --git a/data/solr/data/plaid_merchants/core.properties b/data/solr/data/plaid_merchants/core.properties old mode 100644 new mode 100755 diff --git a/notes.txt b/notes.txt index b4e5274e..341f2c98 100644 --- a/notes.txt +++ b/notes.txt @@ -2,15 +2,20 @@ -# Implement multi -# test headers->clients -# Still use single client in subs, but have it only be set if a single on is selected +X Implement multi +X test headers->clients +X Still use single client in subs, but have it only be set if a single on is selected X Pass X-Clients header as :all :mine [id-1, id-2, id-3] X Use X-Clients instead of client filter -# Remove the client specific filter from each graphql +X Remove the client specific filter from each graphql # Test with single client user, all client user, admin, etc -# Synchronize with the backend for SSR, set in session, but hydrate to real clients in middleware -# Ensure that client selection still resets everything +X Synchronize with the backend for SSR, set in session, but hydrate to real clients in middleware +X Ensure that client selection still resets everything # maybe set it up so that changing assignments works automatically without having to log out or in -# figure out how to not make this require a whole login -# bulk-code-transactions +X bulk-code-transactions +X all ssr pages, starting with plaid +# Make it work for everyone who refreshes tomorrow + +X only show mine for admins +X company dropdown TODO - syncing with front end +# double check that transaction insights have been running all along diff --git a/src/clj/auto_ap/datomic/checks.clj b/src/clj/auto_ap/datomic/checks.clj index 94122b8c..da5fe027 100644 --- a/src/clj/auto_ap/datomic/checks.clj +++ b/src/clj/auto_ap/datomic/checks.clj @@ -45,8 +45,7 @@ :where '[[?e :payment/client ?c]]} :args [db (:exact-match-id args) - (map :db/id (:clients args))] - } + (map :db/id (:clients args))]} (cond-> {:query {:find [] :in ['$] :where []} @@ -67,7 +66,7 @@ :where []} :args [(:exact-match-id args)]}) - (seq (:clients args)) + true (merge-query {:query {:in ['[?xx ...]] :where ['[?e :payment/client ?xx]]} :args [(map :db/id (:clients args))]}) diff --git a/src/clj/auto_ap/datomic/expected_deposit.clj b/src/clj/auto_ap/datomic/expected_deposit.clj index 46aa0483..8e390c97 100644 --- a/src/clj/auto_ap/datomic/expected_deposit.clj +++ b/src/clj/auto_ap/datomic/expected_deposit.clj @@ -38,7 +38,7 @@ "fee" ['[?e :expected-deposit/fee ?sort-fee]]} args) - (seq (:clients args)) + true (merge-query {:query {:in ['[?xx ...]] :where ['[?e :expected-deposit/client ?xx]]} :args [(set (map :db/id (:clients args)))]}) diff --git a/src/clj/auto_ap/datomic/invoices.clj b/src/clj/auto_ap/datomic/invoices.clj index f071004e..32aeb6b3 100644 --- a/src/clj/auto_ap/datomic/invoices.clj +++ b/src/clj/auto_ap/datomic/invoices.clj @@ -99,7 +99,7 @@ :where ['[?e :invoice/due ?due] '[(<= ?due ?end-due)]]} :args [(coerce/to-date (:end (:due-range args)))]}) - (seq (:clients args)) + true (merge-query {:query {:in ['[?xx ...]] :where ['[?e :invoice/client ?xx]]} :args [ (map :db/id (:clients args))]}) diff --git a/src/clj/auto_ap/datomic/ledger.clj b/src/clj/auto_ap/datomic/ledger.clj index c20e8d2d..3899274e 100644 --- a/src/clj/auto_ap/datomic/ledger.clj +++ b/src/clj/auto_ap/datomic/ledger.clj @@ -27,7 +27,7 @@ :where []} :args [db]} - (seq (:clients args)) + true (merge-query {:query {:in ['[?xx ...]] :where ['[?e :journal-entry/client ?xx]]} :args [(set (map :db/id (:clients args)))]}) diff --git a/src/clj/auto_ap/datomic/transactions.clj b/src/clj/auto_ap/datomic/transactions.clj index 16c8bb43..f8e27a34 100644 --- a/src/clj/auto_ap/datomic/transactions.clj +++ b/src/clj/auto_ap/datomic/transactions.clj @@ -59,7 +59,7 @@ (merge-query {:query {:in '[[?e ...]]} :args [potential-duplicates]}) - (seq (:clients args)) + true (merge-query {:query {:in ['[?xx ...]] :where ['[?e :transaction/client ?xx]]} :args [(set (map :db/id (:clients args)))]}) diff --git a/src/clj/auto_ap/graphql/checks.clj b/src/clj/auto_ap/graphql/checks.clj index b7dfd5a3..bcb24c72 100644 --- a/src/clj/auto_ap/graphql/checks.clj +++ b/src/clj/auto_ap/graphql/checks.clj @@ -454,6 +454,7 @@ (let [transaction (d-transactions/get-by-id (:transaction_id args)) _ (assert-can-see-client (:id context) (:transaction/client transaction)) [payments _] (d-checks/get-graphql {:client-id (:db/id (:transaction/client transaction)) + :clients [{:db/id (:db/id (:transaction/client transaction))}] :bank-account-id (:db/id (:transaction/bank-account transaction)) :amount (- (:transaction/amount transaction)) :status :payment-status/pending diff --git a/src/clj/auto_ap/graphql/invoices.clj b/src/clj/auto_ap/graphql/invoices.clj index 6bbd3f6b..3c18fb93 100644 --- a/src/clj/auto_ap/graphql/invoices.clj +++ b/src/clj/auto_ap/graphql/invoices.clj @@ -256,6 +256,7 @@ (let [ids (some-> args :filters (<-graphql) + (assoc :clients (:clients args)) (update :status enum->keyword "invoice-status") (assoc :per-page Integer/MAX_VALUE) d-invoices/raw-graphql-ids diff --git a/test/clj/auto_ap/import/plaid_test.clj b/test/clj/auto_ap/import/plaid_test.clj index 5cc4b987..8514753e 100644 --- a/test/clj/auto_ap/import/plaid_test.clj +++ b/test/clj/auto_ap/import/plaid_test.clj @@ -10,9 +10,7 @@ (t/deftest plaid->transaction - (t/testing "Should invert amount if a credit account" - (t/is (= 123.45 (:transaction/amount (sut/plaid->transaction base-transaction {})))) - (t/is (= -123.45 (:transaction/amount (sut/plaid->transaction (assoc base-transaction :account {:type "credit"}) {}))))) + (t/testing "Should assign a plaid merchant if a merchant is found" (t/is (= "Home Depot" (-> (sut/plaid->transaction (assoc base-transaction :merchant_name "Home Depot") diff --git a/test/clj/auto_ap/integration/graphql.clj b/test/clj/auto_ap/integration/graphql.clj index fef692aa..1ecbb196 100644 --- a/test/clj/auto_ap/integration/graphql.clj +++ b/test/clj/auto_ap/integration/graphql.clj @@ -3,7 +3,7 @@ [venia.core :as v] [clojure.test :as t :refer [deftest is testing use-fixtures]] [datomic.api :as dc] - [auto-ap.integration.util :refer [wrap-setup admin-token user-token]] + [auto-ap.integration.util :refer [wrap-setup admin-token user-token setup-test-data test-transaction]] [auto-ap.datomic :refer [conn]])) @@ -28,21 +28,19 @@ (use-fixtures :each wrap-setup) (deftest transaction-page (testing "transaction page" - @(dc/transact conn - [(new-client {:db/id "client"}) - (new-transaction {:transaction/client "client"})]) - - (testing "It should find all transactions" - (let [result (:transaction-page (:data (sut/query (admin-token) "{ transaction_page(filters: {client_id: null}) { count, start, data { id } }}")))] - (is (= 1 (:count result))) - (is (= 0 (:start result))) - (is (= 1 (count (:data result)))))) + (let [{:strs [test-client-id]} (setup-test-data [(test-transaction :transaction/description-original "hi")])] + + (testing "It should find all transactions" + (let [result (:transaction-page (:data (sut/query (admin-token) "{ transaction_page(filters: {}) { count, start, data { id } }}" {:clients [{:db/id test-client-id}]})))] + (is (= 1 (:count result))) + (is (= 0 (:start result))) + (is (= 1 (count (:data result)))))) - (testing "Users should not see transactions they don't own" - (let [result (:transaction-page (:data (sut/query (user-token) "{ transaction_page(filters: {client_id: null}) { count, start, data { id } }}")))] - (is (= 0 (:count result))) - (is (= 0 (:start result))) - (is (= 0 (count (:data result)))))))) + (testing "Users should not see transactions they don't own" + (let [result (:transaction-page (:data (sut/query (user-token) "{ transaction_page(filters: {}) { count, start, data { id } }}" {:clients []})))] + (is (= 0 (:count result))) + (is (= 0 (:start result))) + (is (= 0 (count (:data result))))))))) (deftest invoice-page @@ -52,13 +50,13 @@ (new-invoice {:invoice/client "client" :invoice/status :invoice-status/paid})]) (testing "It should find all invoices" - (let [result (first (:invoice-page (:data (sut/query (admin-token) "{ invoice_page(filters: {client_id: null, status:paid}) { count, start, invoices { id } }}"))))] + (let [result (first (:invoice-page (:data (sut/query (admin-token) "{ invoice_page(filters: { status:paid}) { count, start, invoices { id } }}"))))] (is (= 1 (:count result))) (is (= 0 (:start result))) (is (= 1 (count (:invoices result)))))) (testing "Users should not see transactions they don't own" - (let [result (first (:invoice-page (:data (sut/query (user-token) "{ invoice_page(filters: {client_id: null}) { count, start, invoices { id } }}"))))] + (let [result (first (:invoice-page (:data (sut/query (user-token) "{ invoice_page(filters: {}) { count, start, invoices { id } }}"))))] (is (= 0 (:count result))) (is (= 0 (:start result))) (is (= 0 (count (:data result)))))))) diff --git a/test/clj/auto_ap/integration/graphql/checks.clj b/test/clj/auto_ap/integration/graphql/checks.clj index 2f4d5af6..ddc4d34c 100644 --- a/test/clj/auto_ap/integration/graphql/checks.clj +++ b/test/clj/auto_ap/integration/graphql/checks.clj @@ -53,29 +53,29 @@ :paid_to "Someone", :_payment [], :check_number 1000}], - (map #(dissoc % :date) (:payments (first (sut/get-payment-page {:id (admin-token)} {} nil)))))) + (map #(dissoc % :date) (:payments (first (sut/get-payment-page {:clients [{:db/id client-id}]} {} nil)))))) (testing "Should omit clients that can't be seen" - (is (not (seq (:payments (first (sut/get-payment-page {:id (user-token -1)} {} nil)))))) - (is (not (seq (:payments (first (sut/get-payment-page {:id (user-token -1)} {:filters {:client_id client-id}} nil))))))) + (is (not (seq (:payments (first (sut/get-payment-page {:clients nil} {} nil)))))) + (is (not (seq (:payments (first (sut/get-payment-page {:clients []} {:filters {:client_id client-id}} nil))))))) (testing "Should include clients that can be seen" - (is (-> (sut/get-payment-page {:id (user-token client-id)} {} nil) + (is (-> (sut/get-payment-page {:clients [{:db/id client-id}]} {} nil) first :payments seq))) (testing "Should filter to date ranges" - (is (-> (sut/get-payment-page {:id (user-token client-id)} {:filters {:date_range {:start #inst "2000-01-01"}}} nil) + (is (-> (sut/get-payment-page {:clients [{:db/id client-id}]} {:filters {:date_range {:start #inst "2000-01-01"}}} nil) first :payments seq)) - (is (-> (sut/get-payment-page {:id (user-token client-id)} {:filters {:date_range {:start #inst "2022-01-01"}}} nil) + (is (-> (sut/get-payment-page {:clients [{:db/id client-id}]} {:filters {:date_range {:start #inst "2022-01-01"}}} nil) first :payments seq)) - (is (not (-> (sut/get-payment-page {:id (user-token client-id)} {:filters {:date_range {:start #inst "2022-01-02"}}} nil) + (is (not (-> (sut/get-payment-page {:clients [{:db/id client-id}]} {:filters {:date_range {:start #inst "2022-01-02"}}} nil) first :payments seq))) - (is (-> (sut/get-payment-page {:id (user-token client-id)} {:filters {:date_range {:end #inst "2022-01-02"}}} nil) + (is (-> (sut/get-payment-page {:clients [{:db/id client-id}]} {:filters {:date_range {:end #inst "2022-01-02"}}} nil) first :payments seq)))) @@ -307,7 +307,8 @@ (deftest get-potential-payments (testing "should match payments for a transaction" (let [{:strs [transaction-id - payment-id]} (setup-test-data [(test-payment + payment-id + test-client-id]} (setup-test-data [(test-payment :db/id "payment-id" :payment/status :payment-status/pending :payment/amount 100.0 @@ -316,7 +317,7 @@ :db/id "transaction-id" :transaction/amount -100.0 :transaction/date #inst "2021-06-01")])] - (is (= [payment-id] (->> (sut/get-potential-payments {:id (admin-token)} + (is (= [payment-id] (->> (sut/get-potential-payments {:id (admin-token) :clients [{:db/id test-client-id}]} {:transaction_id transaction-id} nil) (map :id)))))) diff --git a/test/clj/auto_ap/integration/graphql/invoices.clj b/test/clj/auto_ap/integration/graphql/invoices.clj index 4d9021c8..85ded831 100644 --- a/test/clj/auto_ap/integration/graphql/invoices.clj +++ b/test/clj/auto_ap/integration/graphql/invoices.clj @@ -162,7 +162,7 @@ :invoice/status :invoice-status/unpaid) (test-account :db/id "new-account-id")])] - (is (some? (sut/void-invoices {:id (admin-token)} + (is (some? (sut/void-invoices {:id (admin-token) :clients [{:db/id test-client-id}]} {:filters {:client_id test-client-id}} nil))) (is (= :invoice-status/voided