Sha256: 2d8e1358ad1285f95cb20268fd4ccde883fbf012600110eafe15fcfc7519c96c

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true
require 'spec_helper'

RSpec.describe Slack::Web::Faraday::Response::RaiseError do
  subject(:raise_error_obj) { described_class.new }

  describe '#on_complete' do
    let(:status) { 200 }
    let(:response) { nil }
    let(:body) { {} }
    let(:env) { double status: status, response: response, body: body }

    context 'with status of 429' do
      let(:status) { 429 }

      it 'raises a TooManyRequestsError' do
        expect { raise_error_obj.on_complete(env) }.to(
          raise_error(Slack::Web::Api::Errors::TooManyRequestsError)
        )
      end
    end

    context 'with an ok payload in the body' do
      let(:body) { { 'ok' => 'true' } }

      it 'is nil' do
        expect(raise_error_obj.on_complete(env)).to eq nil
      end
    end

    context 'with a single error in the body' do
      let(:body) { { 'error' => 'already_in_channel' } }

      it 'raises a SlackError with the error message' do
        expect { raise_error_obj.on_complete(env) }.to(
          raise_error(Slack::Web::Api::Errors::SlackError, 'already_in_channel')
        )
      end
    end

    context 'with multiple errors in the body' do
      let(:body) do
        {
          'errors' => [
            { 'error' => 'already_in_channel' },
            { 'error' => 'something_else_terrible' }
          ]
        }
      end

      it 'raises a SlackError with the concatenated error messages' do
        expect { raise_error_obj.on_complete(env) }.to(
          raise_error(
            Slack::Web::Api::Errors::SlackError,
            'already_in_channel,something_else_terrible'
          )
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slack-ruby-client-0.14.5 spec/slack/web/faraday/response/raise_error_spec.rb