(cloud) experimental approach to ensure the ledgers do not get out of sync
This commit is contained in:
@@ -146,13 +146,13 @@
|
||||
(is (= #:transaction{:vendor {:db/id test-vendor-id}
|
||||
:approval-status {:db/ident :transaction-approval-status/approved}
|
||||
:payment {:db/id payment-id}
|
||||
:accounts [#:transaction-account{:account {:db/id accounts-payable-id}
|
||||
:accounts [#:transaction-account{:account {:account/name "Accounts Payable"}
|
||||
:location "A"
|
||||
:amount 50.0}]}
|
||||
(dc/pull (dc/db conn) '[:transaction/vendor
|
||||
:transaction/payment
|
||||
{:transaction/approval-status [:db/ident]
|
||||
:transaction/accounts [:transaction-account/account
|
||||
:transaction/accounts [{:transaction-account/account [:account/name]}
|
||||
:transaction-account/location
|
||||
:transaction-account/amount]}]
|
||||
transaction-id)))))
|
||||
|
||||
@@ -108,5 +108,10 @@
|
||||
:client/bank-accounts [(test-bank-account :db/id "test-bank-account-id")])
|
||||
(test-vendor :db/id "test-vendor-id")
|
||||
{:db/id "accounts-payable-id"
|
||||
:account/name "Accounts Payable"
|
||||
:db/ident :account/accounts-payable
|
||||
:account/numeric-code 21000
|
||||
:account/account-set "default"}])})))
|
||||
|
||||
(defn apply-tx [data]
|
||||
(:db-after (dc/transact conn {:tx-data data})))
|
||||
|
||||
84
test/clj/iol_ion/integration/tx.clj
Normal file
84
test/clj/iol_ion/integration/tx.clj
Normal file
@@ -0,0 +1,84 @@
|
||||
(ns iol-ion.integration.tx
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.integration.util
|
||||
:refer [setup-test-data test-invoice wrap-setup apply-tx]]
|
||||
[clojure.test :as t :refer [deftest is use-fixtures testing]]
|
||||
[datomic.client.api :as dc]
|
||||
[iol-ion.tx :as sut]))
|
||||
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
(def journal-pull [:journal-entry/date
|
||||
:journal-entry/original-entity
|
||||
:journal-entry/client
|
||||
:journal-entry/source
|
||||
:journal-entry/cleared
|
||||
:journal-entry/amount
|
||||
:journal-entry/vendor
|
||||
{:journal-entry/line-items [{:journal-entry-line/account '[:account/name]}
|
||||
:journal-entry-line/location
|
||||
:journal-entry-line/credit
|
||||
:journal-entry-line/dirty
|
||||
:journal-entry-line/debit]}])
|
||||
|
||||
|
||||
(deftest upsert-invoice
|
||||
(testing "Importing should create a journal entry"
|
||||
(let [{:strs [invoice-id
|
||||
test-client-id
|
||||
test-vendor-id
|
||||
]} (setup-test-data
|
||||
[(test-invoice :db/id "invoice-id"
|
||||
:invoice/import-status :import-status/pending
|
||||
:invoice/total 200.0
|
||||
)])]
|
||||
|
||||
(is (nil? (:db/id (dc/pull (dc/db conn) journal-pull
|
||||
[:journal-entry/original-entity invoice-id]))))
|
||||
(let [db-after (apply-tx (sut/upsert-invoice
|
||||
(dc/with-db conn)
|
||||
{:db/id invoice-id
|
||||
:invoice/import-status :import-status/imported}))]
|
||||
|
||||
(is (= #:journal-entry{:date #inst "2022-01-01T00:00:00.000-00:00",
|
||||
:original-entity #:db{:id invoice-id},
|
||||
:client #:db{:id test-client-id},
|
||||
:line-items
|
||||
[#:journal-entry-line{:account
|
||||
#:account{:name
|
||||
"Accounts Payable"},
|
||||
:credit 200.0,
|
||||
:location "A",
|
||||
:dirty true}
|
||||
#:journal-entry-line{:account
|
||||
#:account{:name "Account"},
|
||||
:location "DT",
|
||||
:dirty true,
|
||||
:debit 100.0}],
|
||||
:source "invoice",
|
||||
:cleared false,
|
||||
:amount 200.0,
|
||||
:vendor #:db{:id test-vendor-id}}
|
||||
(dc/pull db-after journal-pull
|
||||
[:journal-entry/original-entity invoice-id])))
|
||||
|
||||
(testing "voiding an invoice should remove the journal entry"
|
||||
(let [db-after (apply-tx (sut/upsert-invoice
|
||||
(dc/with-db conn)
|
||||
{:db/id invoice-id
|
||||
:invoice/status :invoice-status/voided}))]
|
||||
|
||||
(is (= nil
|
||||
(dc/pull db-after journal-pull
|
||||
[:journal-entry/original-entity invoice-id])))))
|
||||
(testing "invoice should remove the journal entry"
|
||||
(let [db-after (apply-tx (sut/upsert-invoice
|
||||
(dc/db conn)
|
||||
{:db/id invoice-id
|
||||
:invoice/status :invoice-status/unpaid
|
||||
:invoice/import-status :import-status/pending}))]
|
||||
|
||||
(is (= nil
|
||||
(dc/pull db-after journal-pull
|
||||
[:journal-entry/original-entity invoice-id])))))))))
|
||||
Reference in New Issue
Block a user