Fix demo mode and add a test to run demo

I've extracted the main functionality into the `run` function so that this can
be tested without triggering the `System/exit` in `-main`.
This commit is contained in:
Ben Sturmfels 2025-09-20 00:19:32 +10:00
parent 5b8951c0f0
commit a49880cc94
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0
3 changed files with 33 additions and 22 deletions

View file

@ -1,4 +1,4 @@
{:paths ["src" "resources" "private"] ;; Private is not include in the build
{:paths ["src" "resources" "private"] ;; Private is not included in the build
:deps {
org.clojure/clojure {:mvn/version "1.11.1"}
org.clojure/data.csv {:mvn/version "1.0.1"}

View file

@ -48,14 +48,34 @@
(set/difference (set (keys projects)) (->> records (map :name) set)))
(def demo-options
{:csv (io/resource "example-paychex-pay-item-details.csv")
{:csv (io/resource "example-paychex-pay-item-details-2025.csv")
:date "2024-01-01"
:period "January 2024"
:total-fees 66.67M})
(defn run [options]
(let [options (if (:demo options) (merge options demo-options) options)
{:keys [date period pay-receipt-no pay-invoice-no total-fees project]} options
{:keys [fees-receipt-no fees-invoice-no retirement-receipt-no retirement-invoice-no]} options
records (import/read-csv (:csv options))
imported (concat (import/net-pay date period pay-invoice-no project records)
(import/individual-taxes date period pay-invoice-no retirement-invoice-no project records)
(import/employer-taxes date period pay-invoice-no project records)
(import/net-pay-ach-debit date period pay-receipt-no pay-invoice-no project records)
(import/taxes-ach-debit date period pay-receipt-no pay-invoice-no project records)
(import/fees date period fees-receipt-no fees-invoice-no total-fees project records)
(import/retirement date period retirement-receipt-no retirement-invoice-no records))
unmatched (unmatched-employees records project)]
(when (seq unmatched)
(println
(str "Could not find these employees in the payroll:\n\n"
(str/join ", " unmatched)))
(System/exit 1))
(doseq [i imported]
(println (import/render-transaction i)))))
(defn -main [& args]
(let [{:keys [options errors summary]} (parse-opts args cli-options)
options (if (:demo options) (merge options demo-options) options)]
(let [{:keys [options errors summary]} (parse-opts args cli-options)]
(when (:help options)
(println summary)
(System/exit 0))
@ -64,24 +84,7 @@
(str "The following errors occurred:\n\n"
(str/join \newline errors)))
(System/exit 1))
(let [{:keys [date period pay-receipt-no pay-invoice-no total-fees project]} options
{:keys [fees-receipt-no fees-invoice-no retirement-receipt-no retirement-invoice-no]} options
records (import/read-csv (:csv options))
imported (concat (import/net-pay date period pay-invoice-no project records)
(import/individual-taxes date period pay-invoice-no retirement-invoice-no project records)
(import/employer-taxes date period pay-invoice-no project records)
(import/net-pay-ach-debit date period pay-receipt-no pay-invoice-no project records)
(import/taxes-ach-debit date period pay-receipt-no pay-invoice-no project records)
(import/fees date period fees-receipt-no fees-invoice-no total-fees project records)
(import/retirement date period retirement-receipt-no retirement-invoice-no records))
unmatched (unmatched-employees records project)]
(when-not (empty? unmatched)
(println
(str "Could not find these employees in the payroll:\n\n"
(str/join ", " unmatched)))
(System/exit 1))
(doseq [i imported]
(println (import/render-transaction i))))))
(run options)))
(comment
;; Examples to exercise the importer during development.

8
test/core_test.clj Normal file
View file

@ -0,0 +1,8 @@
(ns core-test
(:require [core]
[clojure.test :as t :refer [deftest is]]
[clojure.string :as str]))
(deftest demo-produces-output
(let [output (with-out-str (core/run {:demo true}))]
(is (not (str/blank? output)))))