                            {:index 0 :amount (bigdec 1000)    :balance (bigdec 1000)}]
         actual-checking (->> (:id checking)
                              (transactions/items-by-account storage-spec)
-                             (map #(select-keys % [:index :amount :balance]))) 
+                             (map #(select-keys % [:index :amount :balance])))
         expected-groceries [{:index 1 :amount (bigdec 102)    :balance (bigdec 201.99)}
                             {:index 0 :amount (bigdec  99.99) :balance (bigdec  99.99)}]
         actual-groceries (->> (:id groceries)

                           {:index 0 :amount (bigdec 1000) :balance (bigdec 1000)}]
        actual-checking (->> (:id checking)
                             (transactions/items-by-account storage-spec)
                             (map #(select-keys % [:index :amount :balance]))) 
        expected-groceries [{:index 1 :amount (bigdec 101) :balance (bigdec 203)}
                            {:index 0 :amount (bigdec 102) :balance (bigdec 102)}]
        actual-groceries (->> (:id groceries)

            "The transaction date is correct")))))

(deftest create-a-transaction-us-string-date
  (let [context (serialization/realize storage-spec create-context)
        transaction (transactions/create storage-spec (-> (attributes context)
                                                          (assoc :transaction-date "3/2/2016")))]
    (is (validation/valid? transaction) "The transaction is valid")
    (is (= (t/local-date 2016 3 2) (:transaction-date transaction)) "The transaction date is parsed correctly")))

(deftest transaction-date-is-required
  (let [context (serialization/realize storage-spec create-context)
        transaction (transactions/create storage-spec (-> (attributes context)
                                                          (dissoc :transaction-date)))]
    (is (validation/has-error? transaction :transaction-date))))

(deftest entity-id-is-required
  (let [context (serialization/realize storage-spec create-context)
        transaction (transactions/create storage-spec (-> (attributes context)
                                                          (dissoc :entity-id)))]
    (is (validation/has-error? transaction :entity-id))))

(deftest item-account-id-is-required
  (let [context (serialization/realize storage-spec create-context)
        transaction (transactions/create
                      storage-spec
                      (-> (attributes context)
                          (update-in
                            [:items 0]
                            #(dissoc % :account-id))))]
    (is (validation/has-error? transaction :items))))

(deftest item-amount-is-required
  (let [context (serialization/realize storage-spec create-context)
        transaction (transactions/create
                      storage-spec
                      (-> (attributes context)
                          (update-in
                            [:items 0]
                            #(dissoc % :amount))))]
    (is (validation/has-error? transaction :items) "Validation error should be present")))

(deftest item-amount-must-be-greater-than-zero
  (let [context (serialization/realize storage-spec create-context)
        transaction (transactions/create
                      storage-spec
                      (-> (attributes context)
                          (update-in
                            [:items 0]
                            #(assoc % :amount (bigdec -1000)))))]
    (is (validation/has-error? transaction :items) "Validation error should be present")))

(deftest item-action-is-required
  (let [context (serialization/realize storage-spec create-context)
        transaction (transactions/create
                      storage-spec
                      (-> (attributes context)
                          (update-in
                            [:items 0]
                            #(dissoc % :action))))]
    (is (validation/has-error? transaction :items) "Validation error should be present")))

(deftest item-action-must-be-debit-or-created
  (let [context (serialization/realize storage-spec create-context)
        transaction (transactions/create
                      storage-spec
                      (-> (attributes context)
                          (update-in
                            [:items 0]
                            #(assoc % :action :not-valid))))]
    (is (validation/has-error? transaction :items) "Validation error should be present")))

(deftest sum-of-debits-must-equal-sum-of-credits
  (let [context (serialization/realize storage-spec create-context)
        transaction (transactions/create
                      storage-spec
                      (-> (attributes context)
                          (update-in
                            [:items 0]
                            #(assoc % :amount (bigdec 1001)))))]
    (is (validation/has-error? transaction :items) "Validation error should be present")))

(def balance-context
