Migrates back to datomic on-prem

This commit is contained in:
2023-04-29 07:12:51 -07:00
parent aca8f7c92c
commit b2ad7790cf
88 changed files with 2289 additions and 2286 deletions

View File

@@ -2,7 +2,7 @@
(:require [auto-ap.graphql :as sut]
[venia.core :as v]
[clojure.test :as t :refer [deftest is testing use-fixtures]]
[datomic.client.api :as dc]
[datomic.api :as dc]
[auto-ap.integration.util :refer [wrap-setup admin-token user-token]]
[auto-ap.datomic :refer [conn]]))
@@ -29,9 +29,8 @@
(deftest transaction-page
(testing "transaction page"
(dc/transact conn
{:tx-data
[(new-client {:db/id "client"})
(new-transaction {:transaction/client "client"})]})
[(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 } }}")))]
@@ -49,10 +48,9 @@
(deftest invoice-page
(testing "invoice page"
(dc/transact conn
{:tx-data
[(new-client {:db/id "client"})
(new-invoice {:invoice/client "client"
:invoice/status :invoice-status/paid})]})
[(new-client {:db/id "client"})
(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 } }}"))))]
(is (= 1 (:count result)))
@@ -95,13 +93,12 @@
(let [{:strs [vendor-id account-id yodlee-merchant-id]} (->
(dc/transact
conn
{:tx-data
[{:vendor/name "Bryce's Meat Co"
:db/id "vendor-id"}
{:account/name "hello"
:db/id "account-id"}
{:yodlee-merchant/name "yodlee"
:db/id "yodlee-merchant-id"}]})
[{:vendor/name "Bryce's Meat Co"
:db/id "vendor-id"}
{:account/name "hello"
:db/id "account-id"}
{:yodlee-merchant/name "yodlee"
:db/id "yodlee-merchant-id"}])
:tempids)]
(testing "it should reject rules that don't add up to 100%"
@@ -194,27 +191,26 @@
(deftest test-transaction-rule
(testing "it should match rules"
(let [matching-transaction (dc/transact conn
{:tx-data
[{:transaction/description-original "matching-desc"
:transaction/date #inst "2019-01-05T00:00:00.000-08:00"
:transaction/client {:client/name "1"
:db/id "client-1"}
:transaction/bank-account {:db/id "bank-account-1"
:bank-account/name "1"}
[{:transaction/description-original "matching-desc"
:transaction/date #inst "2019-01-05T00:00:00.000-08:00"
:transaction/client {:client/name "1"
:db/id "client-1"}
:transaction/bank-account {:db/id "bank-account-1"
:bank-account/name "1"}
:transaction/amount 1.00
:transaction/id "2019-01-05 matching-desc 1"
:db/id "a"}
:transaction/amount 1.00
:transaction/id "2019-01-05 matching-desc 1"
:db/id "a"}
{:transaction/description-original "nonmatching-desc"
:transaction/client {:client/name "2"
:db/id "client-2"}
:transaction/bank-account {:db/id "bank-account-2"
: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"
:db/id "b"}]})
{:transaction/description-original "nonmatching-desc"
:transaction/client {:client/name "2"
:db/id "client-2"}
:transaction/bank-account {:db/id "bank-account-2"
: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"
: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)
@@ -253,34 +249,33 @@
(deftest test-match-transaction-rule
(testing "it should apply a rules"
(let [{:strs [transaction-id transaction-rule-id uneven-transaction-rule-id]} (-> (dc/transact conn
{:tx-data
[{:transaction/description-original "matching-desc"
:transaction/date #inst "2019-01-05T00:00:00.000-08:00"
:transaction/client {:client/name "1"
:db/id "client-1"}
:transaction/bank-account {:db/id "bank-account-1"
:bank-account/name "1"}
:transaction/amount 1.00
:db/id "transaction-id"}
[{:transaction/description-original "matching-desc"
:transaction/date #inst "2019-01-05T00:00:00.000-08:00"
:transaction/client {:client/name "1"
:db/id "client-1"}
:transaction/bank-account {:db/id "bank-account-1"
:bank-account/name "1"}
:transaction/amount 1.00
:db/id "transaction-id"}
{:db/id "transaction-rule-id"
:transaction-rule/note "transaction rule note"
:transaction-rule/description "matching-desc"
:transaction-rule/accounts [{:transaction-rule-account/location "A"
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
:transaction-rule-account/percentage 1.0}]}
{:db/id "uneven-transaction-rule-id"
:transaction-rule/note "transaction rule note"
:transaction-rule/description "matching-desc"
:transaction-rule/accounts [{:transaction-rule-account/location "A"
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
:transaction-rule-account/percentage 0.3333333}
{:transaction-rule-account/location "B"
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
:transaction-rule-account/percentage 0.33333333}
{:transaction-rule-account/location "c"
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
:transaction-rule-account/percentage 0.333333}]}]})
{:db/id "transaction-rule-id"
:transaction-rule/note "transaction rule note"
:transaction-rule/description "matching-desc"
:transaction-rule/accounts [{:transaction-rule-account/location "A"
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
:transaction-rule-account/percentage 1.0}]}
{:db/id "uneven-transaction-rule-id"
:transaction-rule/note "transaction rule note"
:transaction-rule/description "matching-desc"
:transaction-rule/accounts [{:transaction-rule-account/location "A"
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
:transaction-rule-account/percentage 0.3333333}
{:transaction-rule-account/location "B"
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
:transaction-rule-account/percentage 0.33333333}
{:transaction-rule-account/location "c"
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
:transaction-rule-account/percentage 0.333333}]}])
:tempids)
rule-test (-> (sut/query (admin-token) (v/graphql-query {:venia/operation {:operation/type :mutation
:operation/name "MatchTransactionRules"}