require 'spec_helper'
require 'webmock/rspec'

describe ApiSearchController, type: :controller do
  let (:user) { FactoryGirl.create(:user) }
  let(:user1) { FactoryGirl.create(:user) }

  before(:each) do
    controller.current_user = user
  end

  describe "GET filter" do
    let(:latency_data_uri) { /\S+\/search_users/ }
    let(:response_body) { mock_latency_response([
      { user: user1, ars_total_latency: 1.0, ars_internet_latency: 0.4, audio_latency: 0.6 }
    ])}

    it "success" do
      stub_request(:post, latency_data_uri)
      .to_return(body: response_body, status: 200)

      get :filter, { latency_good: true, latency_fair: true, latency_high: true, format: 'json' }
      
      response.should be_success
      expect(response.content_type).to eq("application/json")
      expect(response).to render_template(:filter)
      expect(response).to have_http_status(:created)
    end
  end
end