Sha256: a414038bd6d5944bcf6c14f2696a27fd9b0cca5640f13f1b8b68033461cc3e33

Contents?: true

Size: 1.48 KB

Versions: 4

Compression:

Stored size: 1.48 KB

Contents

require File.expand_path("../spec_helper", __FILE__)

module Euston
  describe 'aggregate root' do
    let(:aggregate)       { Sample::Widget.new }
    let(:command_headers) { CommandHeaders.new id: Euston.uuid.generate, type: 'create_widget', version: 1 }
    let(:command_body)    { { :id => Euston.uuid.generate } }

    before do
      aggregate.consume_command command_headers, command_body
    end

    subject { aggregate }

    context 'commmand consumption' do
      its(:uncommitted_events)  { should have(1).item }
      
      describe 'the uncommitted headers' do
        subject { aggregate.uncommitted_headers }
        
        its([:source_message_type]) { should == :command }

        describe 'the source message' do
          subject { aggregate.uncommitted_headers[:source_message] }

          its([:headers]) { should == command_headers }
          its([:body])    { should == command_body }
        end
      end
    end

    context 'duplicate command consumption' do
      subject do 
        stream = OpenStruct.new.tap do |s| 
          s.committed_headers = { source_message_type: :command, 
                                  source_message: { headers: command_headers, body: command_body } }
          s.committed_events = aggregate.uncommitted_events
        end

        aggregate2 = Sample::Widget.hydrate stream
        aggregate2.consume_command command_headers, command_body
        aggregate2
      end

      its(:uncommitted_events) { should have(0).items }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
euston-1.2.10 spec/aggregate_root_spec.rb
euston-1.2.10-java spec/aggregate_root_spec.rb
euston-1.2.9-java spec/aggregate_root_spec.rb
euston-1.2.9 spec/aggregate_root_spec.rb