Skip to content

Commit

Permalink
Append events to event store test
Browse files Browse the repository at this point in the history
  • Loading branch information
slashdotdash committed Oct 12, 2018
1 parent 0fd3758 commit f3b30b7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
6 changes: 4 additions & 2 deletions .formatter.exs
@@ -1,3 +1,5 @@
# Used by "mix format"

locals_without_parens = [
dispatch: 2,
identify: 2,
Expand All @@ -6,8 +8,8 @@ locals_without_parens = [

[
inputs: [
"lib/*/{lib,test}/**/*.{ex,exs}",
"lib/*/mix.exs"
"{mix,.formatter}.exs",
"{config,lib,test}/**/*.{ex,exs}"
],
locals_without_parens: locals_without_parens,
export: [locals_without_parens: locals_without_parens]
Expand Down
Expand Up @@ -34,7 +34,7 @@ defmodule Commanded.EventStore.Adapters.InMemory.Subscription do
end

@impl GenServer
def handle_info({:DOWN, _ref, :process, pid, reason}, %Subscription{} = state) do
def handle_info({:DOWN, _ref, :process, _pid, reason}, %Subscription{} = state) do
{:stop, reason, state}
end
end
34 changes: 17 additions & 17 deletions test/event_store/support/append_events_test_case.ex
Expand Up @@ -13,13 +13,13 @@ defmodule Commanded.EventStore.AppendEventsTestCase do

describe "append events to a stream" do
test "should append events" do
assert :ok == EventStore.append_to_stream("stream", 0, build_events(2))
assert :ok == EventStore.append_to_stream("stream", 2, build_events(2))
assert :ok == EventStore.append_to_stream("stream", 4, build_events(1))
assert :ok == EventStore.append_to_stream("stream", 0, build_events(1))
assert :ok == EventStore.append_to_stream("stream", 1, build_events(2))
assert :ok == EventStore.append_to_stream("stream", 3, build_events(3))
end

test "should append events without checking expected version" do
assert :ok == EventStore.append_to_stream("stream", :any_version, build_events(2))
test "should append events with `:any_version` without checking expected version" do
assert :ok == EventStore.append_to_stream("stream", :any_version, build_events(3))
assert :ok == EventStore.append_to_stream("stream", :any_version, build_events(2))
assert :ok == EventStore.append_to_stream("stream", :any_version, build_events(1))
end
Expand All @@ -35,34 +35,34 @@ defmodule Commanded.EventStore.AppendEventsTestCase do
EventStore.append_to_stream("stream", :no_stream, build_events(1))
end

test "should append events with :stream_exists parameter" do
test "should append events with `:stream_exists` parameter" do
assert :ok == EventStore.append_to_stream("stream", :no_stream, build_events(2))
assert :ok == EventStore.append_to_stream("stream", :stream_exists, build_events(1))
end

test "should fail when stream does not exists with :stream_exists parameter" do
test "should fail with `:stream_exists` parameter when stream does not exist" do
assert {:error, :stream_does_not_exist} ==
EventStore.append_to_stream("stream", :stream_exists, build_events(1))
end

test "should fail to append to a stream because of wrong expected version when no previous events" do
events = build_events(1)

test "should fail to append to a stream because of wrong expected version when no stream" do
assert {:error, :wrong_expected_version} ==
EventStore.append_to_stream("stream", 1, events)
EventStore.append_to_stream("stream", 1, build_events(1))
end

test "should fail to append to a stream because of wrong expected version" do
assert :ok == EventStore.append_to_stream("stream", 0, build_events(2))
assert :ok == EventStore.append_to_stream("stream", 0, build_events(3))

assert {:error, :wrong_expected_version} ==
EventStore.append_to_stream("stream", 0, build_events(1))

assert {:error, :wrong_expected_version} ==
EventStore.append_to_stream("stream", 1, build_events(1))
end

test "should append events to any version" do
assert :ok == EventStore.append_to_stream("stream", :any_version, build_events(2))
assert :ok == EventStore.append_to_stream("stream", :any_version, build_events(2))
assert :ok == EventStore.append_to_stream("stream", :any_version, build_events(1))
assert {:error, :wrong_expected_version} ==
EventStore.append_to_stream("stream", 2, build_events(1))

assert :ok == EventStore.append_to_stream("stream", 3, build_events(1))
end
end

Expand Down

0 comments on commit f3b30b7

Please sign in to comment.