                                     :transaction-date transaction-date}
                                    {:limit 1})))
 
-(defn- upsert-item
+; This is public to support the unit test
+(defn upsert-item
   "Updates the specified transaction item"
   [storage {:keys [id transaction-date] :as item}]
   (let [to-save (before-save-item item)]

                            {:sort [:transaction-date :index]})
        account (accounts/find-by-id storage account-id)
        [last-index
         balance] (process-items storage account base-item items)]
    ; TODO only update account if balance is not nil
    (accounts/update storage (assoc account :quantity balance))))

; Processing a transaction
; 1. Save the transaction and item records

            (doseq [item dereferenced-items]
              (delete-transaction-item storage (:id item) (:transaction-date existing)))
            (doseq [account-id recalc-account-ids]
              (recalculate-account storage account-id recalc-base-date))
            (reload storage validated)))))))

(defn- get-preceding-items
  "Returns the items that precede each item in the
