                                             :commodity-id (:id commodity)
                                             :account-id (:id ira)
                                             :value 1000M})
-        result (trading/unbuy storage-spec (-> purchase :transaction :id))]
+        result (trading/unbuy storage-spec (:transaction purchase))]
     ; TODO Should we delete the price that was created?
     (testing "the account balance"
       (is (= 2000M (:balance (accounts/reload storage-spec ira)))

        _ (trading/sell storage-spec (-> context
                                         sale-attributes
                                         (assoc :shares 25M :value 375M)))
        gains-items (->> {:i.account-id (:id lt-capital-gains)} ; TODO remove table prefix
                         (transactions/search-items storage-spec)
                         (map #(dissoc % :id
                                         :entity-id
                                         :transaction-id
                                         :reconciled?
                                         :reconciliation-id
                                         :created-at
                                         :updated-at
                                         :reconciliation-status)))
        expected [{:transaction-date (t/local-date 2017 3 2)
                   :description "Sell 25 shares of AAPL at 15.000"
                   :action :credit

(def storage-spec (env :db))

(use-fixtures :each (partial reset-db storage-spec))

(defn items-by-account
  [account-id]
  (map #(dissoc %
                :id
                :polarized-amount
                :entity-id
                :transaction-id
                :reconciled?
                :reconciliation-id
                :created-at
                :updated-at
                :reconciliation-status)
       (transactions/items-by-account
         storage-spec
         account-id
         [(t/local-date 2015 1 1)
          (t/local-date 2017 12 31)])))

(def ^:private purchase-context
  {:users [(factory :user)]
