Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stream-id and event number to ok response #3

Merged
merged 6 commits into from Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/rill/wheel.clj
Expand Up @@ -331,6 +331,7 @@
"
(:refer-clojure :exclude [empty empty? type])
(:require [rill.event-store :refer [retrieve-events append-events]]
[rill.message :as message]
[rill.wheel.repository :as repo]
[clojure.string :as string]
[clojure.spec :as s]
Expand Down Expand Up @@ -377,6 +378,12 @@
[aggregate]
(::new-events aggregate))

(defn aggregate?
"Test that `obj` is an aggregate."
[obj]
(boolean (and (::id obj)
(::type obj))))

(defn empty
"Create a new aggregate with id `aggregate-id` and no
events. Aggregate version will be -1. Note that empty aggregates
Expand Down Expand Up @@ -586,7 +593,12 @@
[aggregate]
(let [events (::new-events aggregate)]
{::status :ok
::events events
::events (->> events
(map-indexed (fn [index event]
(-> event
(assoc ::message/stream-id (::id aggregate))
(assoc ::message/number (+ (::version aggregate) (inc index))))))
vec)
::aggregate (-> aggregate
(update ::version + (count events))
(assoc ::new-events []))}))
Expand Down
1 change: 0 additions & 1 deletion src/rill/wheel/repository.clj
Expand Up @@ -24,4 +24,3 @@
"Test if `repo` is a repository"
[repo]
(satisfies? Repository repo))

17 changes: 12 additions & 5 deletions test/rill/wheel_test.clj
Expand Up @@ -151,31 +151,38 @@
commit!)))

(is (sub? {::aggregate/status :ok
::aggregate/events [{::message/type ::installed}]}
::aggregate/events [{::message/type ::installed
::message/stream-id {:turnstile-id id
::aggregate/type ::turnstile}
::message/number 0}]}
(-> (get-turnstile repo id)
(install-turnstile)
commit!)))

(is (sub? {::aggregate/status :ok
::aggregate/events [{::message/type ::arm-pushed-ineffectively}]}
::aggregate/events [{::message/type ::arm-pushed-ineffectively
::message/number 1}]}
(-> (get-turnstile repo id)
(push-arm)
commit!)))

(is (sub? {::aggregate/status :ok
::aggregate/events [{::message/type ::coin-inserted}]}
::aggregate/events [{::message/type ::coin-inserted
::message/number 2}]}
(-> (get-turnstile repo id)
(insert-coin)
commit!)))

(is (sub? {::aggregate/status :ok
::aggregate/events [{::message/type ::arm-turned}]}
::aggregate/events [{::message/type ::arm-turned
::message/number 3}]}
(-> (get-turnstile repo id)
(push-arm)
commit!)))

(is (sub? {::aggregate/status :ok
::aggregate/events [{::message/type ::arm-pushed-ineffectively}]}
::aggregate/events [{::message/type ::arm-pushed-ineffectively
::message/number 4}]}
(-> (get-turnstile repo id)
(push-arm)
commit!)))))
Expand Down