Sha256: dce34f9e98df2b62b7b3934696bc970b02a4ef1452db7e27393a1df1ea081621

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 KB

Contents

module SandthornSequelProjection
  describe Cursor do

    let(:first_page) { [ { sequence_number: 1 } ] }
    let(:second_page) { [ { sequence_number: 2 } ] }
    let(:third_page) { [] }
    let(:event_store) do
      store = Object.new
      env = self
      store.tap do |store|
        store.define_singleton_method(:get_events) do |after_sequence_number: 0, take: 1|
          case after_sequence_number
            when 0
              env.first_page
            when 1
              env.second_page
            else
              env.third_page
          end
        end
      end
    end
    let(:cursor) { Cursor.new(after_sequence_number: 0, batch_size: 1, event_store: event_store) }

    it "has the correct starting sequence number and batch size" do
      expect(cursor.batch_size).to eq(1)
      expect(cursor.last_sequence_number).to eq(0)
    end

    describe "#get_batch" do
      describe "sequential calls" do
        it "returns pages until empty and keeps track of seen sequence numbers" do
          expect(cursor.get_batch.events).to eq(first_page)
          expect(cursor.last_sequence_number).to eq(first_page.last[:sequence_number])
          expect(cursor.get_batch.events).to eq(second_page)
          expect(cursor.last_sequence_number).to eq(second_page.last[:sequence_number])
          expect(cursor.get_batch.events).to eq(third_page)
          expect(cursor.last_sequence_number).to eq(second_page.last[:sequence_number])
        end
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sandthorn_sequel_projection-0.1.0 spec/cursor_spec.rb
sandthorn_sequel_projection-0.0.4 spec/cursor_spec.rb
sandthorn_sequel_projection-0.0.3 spec/cursor_spec.rb
sandthorn_sequel_projection-0.0.2 spec/cursor_spec.rb
sandthorn_sequel_projection-0.0.1 spec/cursor_spec.rb