Sha256: 43bb4387f0575f6a84db7a583696ac4c65b295da5a4d3ea4e7f004df3aac92ff

Contents?: true

Size: 1.92 KB

Versions: 2

Compression:

Stored size: 1.92 KB

Contents

require_relative "./spec_helper"

describe Alephant::Publisher::Request do
  include Rack::Test::Methods
  let (:response) { instance_double(Faraday::Response, :status => 200, :body => nil) }
  let (:base_path) { File.join(File.dirname(__FILE__), '..', 'fixtures', 'components') }
  let (:processor) { Alephant::Publisher::Request::Processor.new(base_path) }
  let (:connection) { instance_double(Faraday::Connection, :get => response) }
  let (:data_mapper_factory) { Alephant::Publisher::Request::DataMapperFactory.new(connection, base_path) }
  let (:app) { subject.create(processor, data_mapper_factory, { :debug => true }) }

  describe "status endpoint (/status)" do
    before(:each) do
      get "/status"
    end

    context "status code" do
      specify { expect(last_response.status).to eq 200 }
    end
  end

  describe "component endpoint (/component/{component_id}?foo=bar)" do
    let (:component_id) { "foo" }

    describe "content" do

      context "with a valid component id" do
        let (:api_response) { "{\"content\":\"#{component_id}\"}" }
        before(:each) do
          allow(response).to receive(:body).and_return(api_response)
          get "/component/#{component_id}"
        end

        specify { expect(last_response.body.chomp).to eq component_id }
      end

    end

    describe "status code" do

      context "with an invalid component id" do
        let (:component_id) { "foo_invalid" }
        before(:each) do
          get "/component/#{component_id}"
        end

        specify { expect(last_response.status).to eq 404 }
      end

      context "with an invalid API endpoint" do
        let (:expected_exception) { Alephant::Publisher::Request::InvalidApiResponse }
        before(:each) do
          allow(connection).to receive(:get).and_raise expected_exception
          get "/component/#{component_id}"
        end

        specify { expect(last_response.status).to eq 502 }
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
alephant-publisher-request-0.1.1 spec/integration/rack_server_spec.rb
alephant-publisher-request-0.0.3 spec/integration/rack_server_spec.rb