require "rails_helper"

RSpec.describe "Zoom API integration", integration: true do
  before :all do
    WebMock.disable_net_connect!(allow_localhost: true)
  end

  describe "Utils.raise_if_error!" do
    it "raises Zoom::APIError if the code of response is equal or higher than 300" do
      response_body = {"code" => 301}
      expect {
        Zoom::Utils.raise_if_error!(response_body)
      }.to raise_error(Zoom::APIError)
    end

    it "returns unmodified response in when the code is lower than 300 and authentication is ok" do
      response_body = JSON.parse(api_response_fixture_body(Zoom, :user_list))
      expect(Zoom::Utils.raise_if_error!(response_body)).to eq(response_body)
    end
  end

  describe "Custom API calls" do
    subject { Zoom.new }
    it { is_expected.to respond_to(:roles_list) }
    it { is_expected.to respond_to(:roles_create) }
    it { is_expected.to respond_to(:roles_members) }
    it { is_expected.to respond_to(:roles_assign) }
    it { is_expected.to respond_to(:roles_delete) }
  end
end