Sha256: 2865794aa5ef42755ee389a617e3aa5b801cb365db1ffcca1c9d7af70cd7f2e2

Contents?: true

Size: 1.86 KB

Versions: 6

Compression:

Stored size: 1.86 KB

Contents

require 'arthropod'

RSpec.describe(Arthropod::Server) do
  context "#pull" do
    let(:client) do
      Aws::SQS::Client.new(stub_responses: true)
    end

    let(:sender_queue_url) do
      "https://aws.com/sender_queue_url"
    end

    let(:return_queue_url) do
      "https://aws.com/return_queue_url"
    end

    let(:uuid) do
      "444444444444-4444-4444-8888-88888888"
    end

    before(:each) do
      expect(client).to(
        receive(:create_queue)
          .with({ queue_name: "test" })
          .and_return(OpenStruct.new(queue_url: sender_queue_url))
      )
      expect(client).to(
        receive(:receive_message)
        .with({ queue_url: sender_queue_url, max_number_of_messages: 1, wait_time_seconds: 1 })
        .and_return(OpenStruct.new(messages: [ OpenStruct.new({ "body" => JSON.dump({ "body" => "request", "return_queue_url" => return_queue_url }), receipt_handle: "receipt_handle" }) ]))
      )
    end

    it "works" do
      expect(client).to(
        receive(:send_message)
        .with({ queue_url: return_queue_url, message_body: JSON.dump({ state: "open", body: "response" }) })
      )
      expect(client).to(
        receive(:send_message)
        .with({ queue_url: return_queue_url, message_body: JSON.dump({ state: "close", body: "final_response" }) })
      )

      Arthropod::Server.pull(client: client, queue_name: "test") do |request|
        expect(request.body).to eq("request")
        request.respond "response"

        "final_response"
      end
    end

    it "send error on exception" do
      expect(client).to(
        receive(:send_message)
        .with({ queue_url: return_queue_url, message_body: JSON.dump({ state: "error", body: nil }) })
      )

      expect do
        Arthropod::Server.pull(client: client, queue_name: "test") do |request|
          raise "error"
        end
      end.to raise_error(Exception)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
arthropod-0.0.7 spec/server_spec.rb
arthropod-0.0.6 spec/server_spec.rb
arthropod-0.0.5 spec/server_spec.rb
arthropod-0.0.4 spec/server_spec.rb
arthropod-0.0.3 spec/server_spec.rb
arthropod-0.0.2 spec/server_spec.rb