               (let [{:keys [db/id]} query-result]
                 :result))
             (def user-create-cache-query
-              [{:name db/id :type :property}])
+              '[{:name db/id :type :property}])
+            (def user-create-data-spec
+              map?)
             (def user-create-definition
-              {:workflows pod/user-create-workflows
-               :lifecycles pod/user-create-lifecycles
+              {:foo pod/user-create-foo
                :implementation pod/user-create-implementation
-               :cache-query pod/user-create-cache-query}))
-         (macroexpand-1 `(defcommand user/create [~'[db [id]] map?]
-                           (~'workflows [:foo])
-                           (~'lifecycles [:bar])
+               :cache-query pod/user-create-cache-query
+               :data-spec pod/user-create-data-spec}))
+         (macroexpand-1 `(defcommand user/create [~'[db [id]] ~'map?]
+                           (~'foo [:bar])
                            (:result))))))
+
+;;;; Exercise run-command
+
+;;; Define a spec for the command data
+
+(s/def ::user-name string?)
+(s/def ::user-email string?)
+(s/def ::user-create-data
+  (s/keys :req-un [::user-name ::user-email]))
+
+;;; Define example query and run implementations
+
+(defn example-query
+  [query]
+  {:db/id 15})
+
+(defn example-process-result
+  [data]
+  data)
+
+(defcommand user/create
+  [[db [id]] ::user-create-data]
+  ({:cache {:db-id id}}))
+
+(c/configure! {:query example-query
+               :process-result example-process-result})
+
+(c/run-command 'user/create {:user-name "Jeff"
+                             :user-email "jeff@jeff.org"})

              (let [{:keys [user/name user/email]} query-result]
                {:some :data}))
            (def user-update-cache-query
              [{:name user/name :type :property}
               {:name user/email :type :property}])
            (def user-update-definition
              {:cache-query pod/user-update-cache-query
               :implementation pod/user-update-implementation}))
         (macroexpand-1 `(defcommand user/update [~'[user [name email]]
                                                  vector?]
                           ({:some :data}))))))

(deftest defcommand-with-forms
  (is (= '(do
            (defn user-update-workflows
              [query-result data]
              [:foo])
            (defn user-update-lifecycles
              [query-result data]
              [:bar])
            (defn user-update-implementation
              [query-result data]
              {:implementation :result})
            (def user-update-definition
              {:workflows pod/user-update-workflows
               :lifecycles pod/user-update-lifecycles
               :implementation pod/user-update-implementation}))
         (macroexpand-1 `(defcommand user/update [vector?]
                           (~'workflows [:foo])
                           (~'lifecycles [:bar])
                           ({:implementation :result}))))))

(deftest defcommand-with-cache-query-and-forms
  (is (= '(do
            (defn user-create-workflows
              [query-result data]
              (let [{:keys [db/id]} query-result]
                [:foo]))
            (defn user-create-lifecycles
              [query-result data]
              (let [{:keys [db/id]} query-result]
                [:bar]))

(ns workflo.macros.command-test
  (:require [clojure.spec :as s]
            [clojure.test :refer [deftest is]]
            [workflo.macros.command :as c :refer [defcommand]]))

(deftest minimal-defcommand
  (is (= '(do
            (defn user-create-implementation
              [query-result data]
              :foo :bar)
            (def user-create-data-spec
              vector?)
            (def user-create-definition
              {:data-spec pod/user-create-data-spec
               :implementation pod/user-create-implementation}))
         (macroexpand-1 `(defcommand user/create [~'vector?]
                           ~'(:foo :bar))))))

(deftest defcommand-with-cache-query
