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:
parent
5b8951c0f0
commit
a49880cc94
3 changed files with 33 additions and 22 deletions
2
deps.edn
2
deps.edn
|
@ -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"}
|
||||
|
|
33
src/core.clj
33
src/core.clj
|
@ -48,23 +48,14 @@
|
|||
(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 -main [& args]
|
||||
(let [{:keys [options errors summary]} (parse-opts args cli-options)
|
||||
options (if (:demo options) (merge options demo-options) options)]
|
||||
(when (:help options)
|
||||
(println summary)
|
||||
(System/exit 0))
|
||||
(when errors
|
||||
(println
|
||||
(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
|
||||
(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)
|
||||
|
@ -75,13 +66,25 @@
|
|||
(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)
|
||||
(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))))))
|
||||
(println (import/render-transaction i)))))
|
||||
|
||||
(defn -main [& args]
|
||||
(let [{:keys [options errors summary]} (parse-opts args cli-options)]
|
||||
(when (:help options)
|
||||
(println summary)
|
||||
(System/exit 0))
|
||||
(when errors
|
||||
(println
|
||||
(str "The following errors occurred:\n\n"
|
||||
(str/join \newline errors)))
|
||||
(System/exit 1))
|
||||
(run options)))
|
||||
|
||||
(comment
|
||||
;; Examples to exercise the importer during development.
|
||||
|
|
8
test/core_test.clj
Normal file
8
test/core_test.clj
Normal 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)))))
|
Loading…
Add table
Reference in a new issue