Sha256: fc39384fc5efdc1f3db0a6903deec64c2f2dc41cbc3a4d7a3360901374f7346c

Contents?: true

Size: 1.73 KB

Versions: 41

Compression:

Stored size: 1.73 KB

Contents

require 'spec_helper'
require 'spec/support/rack_test'
require 'spec/support/events'
require 'routemaster/middleware/parse'

describe Routemaster::Middleware::Parse do
  let(:terminator) { ErrorRackApp.new }
  let(:app) { described_class.new(terminator) }
  let(:payload) { [make_event(1), make_event(2)].to_json }
  let(:env) {{ 'CONTENT_TYPE' => 'application/json' }}
  let(:perform) { post '/whatever', payload, env }

  describe '#call' do
    context 'correct MIME and JSON' do
      it 'yields to next middleware' do
        perform
        expect(last_response.status).to eq(501)
      end

      it 'passes data in env' do
        perform
        expect(terminator.last_env['routemaster.payload']).to eq([make_event(1), make_event(2)])
      end
    end

    context 'with bad MIME' do
      let(:env) {{ 'CONTENT_TYPE' => 'text/plain' }}
      it 'returns 415' do
        perform
        expect(last_response.status).to eq(415)
      end

      it 'does not pass any data' do
        expect(terminator.last_env).not_to include('routemaster.payload')
      end
    end

    context 'bad JSON' do
      let(:payload) { '[{ "key": "gibberish' }

      it 'returns 400' do
        perform
        expect(last_response.status).to eq(400)
      end

      it 'does not pass any data' do
        expect(terminator.last_env).not_to include('routemaster.payload')
      end
    end

    # context 'no body'
    context 'correct JSON, bad format' do
      let(:payload) { '[{ "type": "noop", "topic":"widgets", "t":123 }]' }

      it 'returns 400' do
        perform
        expect(last_response.status).to eq(400)
      end

      it 'does not pass any data' do
        expect(terminator.last_env).not_to include('routemaster.payload')
      end
    end

  end
end



Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
routemaster-drain-3.7.1 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.7.0 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.6.8 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.6.7 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.6.6 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.6.5 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.6.4 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.6.3 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.6.2 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.6.1 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.6.0 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.5.1 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.5.0 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.4.0 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.3.0 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.2.0 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.1.0 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.0.3 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.0.2 spec/routemaster/middleware/parse_spec.rb
routemaster-drain-3.0.1 spec/routemaster/middleware/parse_spec.rb