Sha256: ed4f4ab87e7a7e5035403ac1f4ce6938c6b139d121ca4919e1c30c66b59a76ab

Contents?: true

Size: 1.37 KB

Versions: 7

Compression:

Stored size: 1.37 KB

Contents

require 'spec_helper'

describe SearchKit::Polling::Process do
  let(:block) { -> x { true } }
  let(:channel) { "mail" }
  let(:process) { described_class.new(channel, &block) }

  subject { process }

  it { is_expected.to respond_to :channel }
  it { is_expected.to respond_to :client }
  it { is_expected.to respond_to :block }

  describe '#perform' do
    let(:event_id) { 345 }
    let(:event) do
      {
        data: [{
          type: 'events',
          id: event_id,
          attributes: {
            channel: channel,
            payload: { id: event_id, title: "Gee willikers" }
          }
        }]
      }
    end

    before do
      allow(process.client).to receive(:pending).and_return(event)
      allow(process.client).to receive(:complete)
    end

    subject { process.perform }

    it "calls the block with every event" do
      expect(process.block)
        .to receive(:call)
        .and_return(process.block)
        .with(instance_of(OpenStruct))
        .once

      subject
    end

    it "completes the event" do
      expect(process.client)
        .to receive(:complete)
        .with(event_id)
        .once

      subject
    end

    context "if something fails" do
      let(:block) do
        -> * { fail("Generic failure") }
      end

      it "raises an exception" do
        expect { subject }.to raise_exception(StandardError)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
search-kit-0.0.10 spec/search_kit/polling/process_spec.rb
search-kit-0.0.9 spec/search_kit/polling/process_spec.rb
search-kit-0.0.8 spec/search_kit/polling/process_spec.rb
search-kit-0.0.7 spec/search_kit/polling/process_spec.rb
search-kit-0.0.6 spec/search_kit/polling/process_spec.rb
search-kit-0.0.5 spec/search_kit/polling/process_spec.rb
search-kit-0.0.4 spec/search_kit/polling/process_spec.rb