Sha256: 6d05b8f4186ed310f1e62fe0bc127c33f692475c322bcc744e1999621eb57e89

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'Brokers Api', type: :request do
  let(:cluster) { KafkaCommand::Cluster.all.first }
  let(:broker) { cluster.brokers.first }
  let(:uri_base) { '/clusters' }

  describe 'listing all brokers' do
    let(:broker_obj) { double(:broker_obj, node_id: 0, host: 'localhost', port: '9092') }
    let(:broker_obj_two) { double(:broker_obj, node_id: 1, host: 'localhost2', port: '9092') }
    let(:broker) { KafkaCommand::Broker.new(broker_obj) }
    let(:broker_two) { KafkaCommand::Broker.new(broker_obj_two) }

    before do
      allow_any_instance_of(KafkaCommand::Cluster).to receive(:brokers).and_return(
        [
          broker,
          broker_two
        ]
      )
    end

    it 'lists' do
      get "#{uri_base}/#{cluster.name}/brokers.json"
      expect(response.status).to eq(200)
      expect(json['data']).to be_an_instance_of(Array)
      expect(json['data'].map { |d| d['id'] }).to eq([broker.node_id, broker_two.node_id])
    end
  end

  describe 'showing a single broker' do
    context 'broker exists' do
      it 'shows' do
        get "#{uri_base}/#{cluster.name}/brokers/#{broker.node_id}.json"
        expect(response.status).to eq(200)
        expect(json['id']).to eq(broker.node_id)
        expect(json['host']).to eq("#{broker.host}:#{broker.port}")
      end
    end

    context 'broker does not exist' do
      it 'returns 404' do
        get "#{uri_base}/#{cluster.name}/brokers/doesnotexist.json"
        expect(response.status).to eq(404)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kafka_command-0.0.3 spec/requests/json/brokers_spec.rb
kafka_command-0.0.2 spec/requests/json/brokers_spec.rb
kafka_command-0.0.1 spec/requests/json/brokers_spec.rb