payroll-import/test/import_test.clj

318 lines
14 KiB
Clojure

;; Copyright 2024 Ben Sturmfels
;; License: GPLv3-or-later
(ns import-test
(:require [import]
[clojure.java.io]
[clojure.string :as str]
[clojure.test :as t :refer [deftest is]]))
(deftest payroll
(let [data (import/read-csv (clojure.java.io/resource "example-paychex-pay-item-details.csv"))
actual (import/payroll "DATE" "PERIOD" "TODO-PAY-RECEIPT" data)
expected '[{:date "DATE"
:desc "Monthly Payroll - PERIOD - Net Pay"
:meta
{:program "Conservancy:Payroll"
:project "Conservancy"
:receipt "TODO-PAY-RECEIPT"
:approval
"Financial/Employment-Records/memo-re-board-approval-of-payroll.txt"
:tax-implication "W2"
:payroll-type "US:General"}
:postings
({:account "Expenses:Payroll:Salary"
:amount 4134.49M
:currency "USD"
:meta {:entity "Citizen-Jack"}}
{:account "Assets:FR:Check2721"
:amount -4134.49M
:currency "USD"
:meta {:entity "Citizen-Jack"}}
{:account "Expenses:Hosting"
:amount 50M
:currency "USD"
:meta {:entity "Citizen-Jack" :payroll-type "US:Reimbursement"}}
{:account "Assets:FR:Check2721"
:amount -50M
:currency "USD"
:meta {:entity "Citizen-Jack" :tax-implication "Reimbursement"}}
{:account "Expenses:Payroll:Salary"
:amount 4347.39M
:currency "USD"
:meta {:entity "Citizen-Jill"}}
{:account "Assets:FR:Check2721"
:amount -4347.39M
:currency "USD"
:meta {:entity "Citizen-Jill"}}
{:account "Expenses:Hosting"
:amount 50M
:currency "USD"
:meta {:entity "Citizen-Jill" :payroll-type "US:Reimbursement"}}
{:account "Assets:FR:Check2721"
:amount -50M
:currency "USD"
:meta {:entity "Citizen-Jill" :tax-implication "Reimbursement"}})}]]
(is (= actual expected))))
(deftest individual-taxes
(let [data (import/read-csv (clojure.java.io/resource "example-paychex-pay-item-details.csv"))
actual (import/individual-taxes "DATE" "PERIOD" "TODO-PAY-RECEIPT" "TODO-RETIREMENT-INVOICE" data)
expected '({:date "DATE"
:desc "Monthly Payroll - PERIOD - TAXES - Citizen-Jack"
:meta
{:project "Conservancy"
:program "Conservancy:Payroll"
:entity "Citizen-Jack"
:receipt "TODO-PAY-RECEIPT"
:approval
"Financial/Employment-Records/memo-re-board-approval-of-payroll.txt"}
:postings
({:account "Expenses:Payroll:Salary"
:amount 1000M
:currency "USD"
:meta
{:payroll-type "US:403b:Employee"
:invoice "TODO-RETIREMENT-INVOICE"}}
{:account "Liabilities:Payable:Accounts"
:amount -1000M
:currency "USD"
:meta {:invoice "TODO-RETIREMENT-INVOICE"}}
{:account "Expenses:Payroll:Salary"
:amount 470.22M
:currency "USD"
:meta {:payroll-type "US:Tax:Income"}}
{:account "Expenses:Payroll:Salary"
:amount 88M
:currency "USD"
:meta {:payroll-type "US:Tax:Medicare"}}
{:account "Expenses:Payroll:Salary"
:amount 376.28M
:currency "USD"
:meta {:payroll-type "US:Tax:SocialSecurity"}}
{:account "Assets:FR:Check2721"
:amount -934.50M
:currency "USD"
:meta {:tax-implication "W2"}}
{:account "Assets:FR:Check2721" :amount 0M :currency "USD"})}
{:date "DATE"
:desc "Monthly Payroll - PERIOD - TAXES - Citizen-Jill"
:meta
{:project "Conservancy"
:program "Conservancy:Payroll"
:entity "Citizen-Jill"
:receipt "TODO-PAY-RECEIPT"
:approval
"Financial/Employment-Records/memo-re-board-approval-of-payroll.txt"}
:postings
({:account "Expenses:Payroll:Salary"
:amount 820M
:currency "USD"
:meta
{:payroll-type "US:403b:Employee"
:invoice "TODO-RETIREMENT-INVOICE"}}
{:account "Liabilities:Payable:Accounts"
:amount -820M
:currency "USD"
:meta {:invoice "TODO-RETIREMENT-INVOICE"}}
{:account "Expenses:Payroll:Salary"
:amount 681.01M
:currency "USD"
:meta {:payroll-type "US:Tax:Income"}}
{:account "Expenses:Payroll:Salary"
:amount 99.29M
:currency "USD"
:meta {:payroll-type "US:Tax:Medicare"}}
{:account "Expenses:Payroll:Salary"
:amount 41.08M
:currency "USD"
:meta {:payroll-type "US:OR:Disability:PFL"}}
{:account "Expenses:Payroll:Salary"
:amount 0M
:currency "USD"
:meta {:payroll-type "OR EE Work Bene"}}
{:account "Expenses:Payroll:Salary"
:amount 427.8M
:currency "USD"
:meta {:payroll-type "US:OR:Tax:Income"}}
{:account "Expenses:Payroll:Salary"
:amount 6.03M
:currency "USD"
:meta {:payroll-type "US:OR:Tax:STT"}}
{:account "Expenses:Payroll:Salary"
:amount 424.52M
:currency "USD"
:meta {:payroll-type "US:Tax:SocialSecurity"}}
{:account "Assets:FR:Check2721"
:amount -1679.73M
:currency "USD"
:meta {:tax-implication "W2"}}
{:account "Assets:FR:Check2721" :amount 0M :currency "USD"})})]
(is (= actual expected))))
(deftest employer-taxes
(let [data (import/read-csv (clojure.java.io/resource "example-paychex-pay-item-details.csv"))
actual (import/employer-taxes "DATE" "PERIOD" "TODO-PAY-RECEIPT" data)
expected '[{:date "DATE"
:desc "Monthly Payroll - PERIOD - TAXES - Employer"
:meta
{:program "Conservancy:Payroll"
:project "Conservancy"
:receipt "TODO-PAY-RECEIPT"
:approval
"Financial/Employment-Records/memo-re-board-approval-of-payroll.txt"}
:postings
({:account "Expenses:Payroll:Tax"
:amount 88M
:currency "USD"
:meta {:entity "Citizen-Jack" :payroll-type "US:Medicare"}}
{:account "Expenses:Payroll:Tax"
:amount 376.28M
:currency "USD"
:meta {:entity "Citizen-Jack" :payroll-type "US:SocialSecurity"}}
{:account "Expenses:Payroll:Tax"
:amount 99.28M
:currency "USD"
:meta {:entity "Citizen-Jill" :payroll-type "US:Medicare"}}
{:account "Expenses:Payroll:Tax"
:amount 0M
:currency "USD"
:meta
{:entity "Citizen-Jill" :payroll-type "US:OR:Disability:PFL"}}
{:account "Expenses:Payroll:Tax"
:amount 0M
:currency "USD"
:meta {:entity "Citizen-Jill" :payroll-type "OR ER Work Bene"}}
{:account "Expenses:Payroll:Tax"
:amount 424.52M
:currency "USD"
:meta {:entity "Citizen-Jill" :payroll-type "US:SocialSecurity"}}
{:account "Expenses:Payroll:Tax"
:amount 0M
:currency "USD"
:meta
{:entity "Fed"
:memo "Citizen-Jack"
:payroll-type "US:US:Unemployment"}}
{:account "Expenses:Payroll:Tax"
:amount 0M
:currency "USD"
:meta
{:entity "TN"
:memo "Citizen-Jack"
:payroll-type "US:TN Unemploy"}}
{:account "Expenses:Payroll:Tax"
:amount 0M
:currency "USD"
:meta
{:entity "Fed"
:memo "Citizen-Jill"
:payroll-type "US:US:Unemployment"}}
{:account "Expenses:Payroll:Tax"
:amount 0M
:currency "USD"
:meta
{:entity "OR"
:memo "Citizen-Jill"
:payroll-type "US:OR:Unemployment"}}
{:account "Assets:FR:Check2721"
:amount -988.08M
:currency "USD"
:meta {:entity "Paychex" :tax-implication "Tax-Payment"}})}]]
(is (= actual expected))))
(deftest payroll-fees
(let [data (import/read-csv (clojure.java.io/resource "example-paychex-pay-item-details.csv"))
actual (import/payroll-fees "DATE" "PERIOD" "TODO-FEES-RECEIPT" "TODO-FEES-INVOICE" 206.51 data)
expected '[{:date "DATE"
:payee "Paychex"
:desc "Monthly Payroll - PERIOD - Fee"
:meta
{:program "Conservancy:Payroll"
:project "Conservancy"
:receipt "TODO-FEES-RECEIPT"
:invoice "TODO-FEES-INVOICE"
:approval
"Financial/Employment-Records/memo-re-board-approval-of-payroll.txt"
:tax-implication "USA-Corporation"}
:postings
({:account "Expenses:Payroll:Fees"
:amount 103.26M
:currency "USD"
:meta {:entity "Citizen-Jack"}}
{:account "Expenses:Payroll:Fees"
:amount 103.25M
:currency "USD"
:meta {:entity "Citizen-Jill"}}
{:account "Assets:FR:Check2721" :amount -206.51 :currency "USD"})}]
]
(is (= actual expected))))
(deftest retirement
(let [data (import/read-csv (clojure.java.io/resource "example-paychex-pay-item-details.csv"))
actual (import/retirement "DATE" "PERIOD" "TODO-RETIREMENT-RECEIPT" "TODO-RETIREMENT-INVOICE" data)
expected '[{:date "DATE"
:desc
"ASCENSUS TRUST RET PLAN - ACH DEBIT - Vanguard 403(b) - PERIOD"
:meta
{:program "Conservancy:Payroll"
:project "Conservancy"
:receipt "TODO-RETIREMENT-RECEIPT"
:approval
"Financial/Employment-Records/memo-re-board-approval-of-payroll.txt"
:tax-implication "Retirement-Pretax"
:invoice "TODO-RETIREMENT-INVOICE"}
:postings
({:account "Liabilities:Payable:Accounts"
:amount 1000M
:currency "USD"
:meta {:entity "Citizen-Jack"}}
{:account "Liabilities:Payable:Accounts"
:amount 820M
:currency "USD"
:meta {:entity "Citizen-Jill"}}
{:account "Assets:FR:Check1345" :amount -1820M :currency "USD"})}]]
(is (= actual expected))))
(deftest render-transaction
(let [transaction '{:date "DATE"
:payee "Paychex"
:desc "Monthly Payroll - PERIOD - Fee"
:meta
{:program "Conservancy:Payroll"
:project "Conservancy"
:receipt "TODO-FEES-RECEIPT"
:invoice "TODO-FEES-INVOICE"
:approval
"Financial/Employment-Records/memo-re-board-approval-of-payroll.txt"
:tax-implication "USA-Corporation"}
:postings
({:account "Expenses:Payroll:Fees"
:amount 103.26M
:currency "USD"
:meta {:entity "Citizen-Jack"}}
{:account "Expenses:Payroll:Fees"
:amount 103.25M
:currency "USD"
:meta {:entity "Citizen-Jill"}}
{:account "Assets:FR:Check2721" :amount -206.51M :currency "USD"})}
actual (import/render-transaction transaction)
expected (str/triml "
DATE txn \"Paychex\" \"Monthly Payroll - PERIOD - Fee\"
program: \"Conservancy:Payroll\"
project: \"Conservancy\"
receipt: \"TODO-FEES-RECEIPT\"
invoice: \"TODO-FEES-INVOICE\"
approval: \"Financial/Employment-Records/memo-re-board-approval-of-payroll.txt\"
tax-implication: \"USA-Corporation\"
Expenses:Payroll:Fees 103.26 USD
entity: \"Citizen-Jack\"
Expenses:Payroll:Fees 103.25 USD
entity: \"Citizen-Jill\"
Assets:FR:Check2721 -206.51 USD
")]
(is (= actual expected))))
(comment
(t/run-all-tests)
)