Sha256: 59fa07f73b42b0abcfefcbf294f129464d8ef5f24e61308bfb9017842dbdfed2

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true
require 'spec_helper'

RSpec.describe Slack::Web::Api::Mixins::Users do
  subject(:users) do
    klass.new
  end

  let(:klass) do
    Class.new do
      include Slack::Web::Api::Mixins::Users
    end
  end

  before do
    allow(users).to receive(:users_list).and_yield(
      Slack::Messages::Message.new(
        'members' => [{
          'id' => 'UDEADBEEF',
          'name' => 'aws',
          'profile' => {}
        }]
      )
    )
  end

  context '#users_id' do
    it 'leaves users specified by ID alone' do
      expect(users.users_id(user: 'U123456')).to eq('ok' => true, 'user' => { 'id' => 'U123456' })
    end
    it 'translates a user that starts with a #' do
      expect(users.users_id(user: '@aws')).to eq('ok' => true, 'user' => { 'id' => 'UDEADBEEF' })
    end
    it 'fails with an exception' do
      expect { users.users_id(user: '@foo') }.to(
        raise_error(Slack::Web::Api::Errors::SlackError, 'user_not_found')
      )
    end
  end

  if defined?(Picky)
    context '#users_search' do
      it 'finds a user' do
        expect(users.users_search(user: 'aws')).to(
          eq('ok' => true, 'members' => [{ 'id' => 'UDEADBEEF', 'name' => 'aws', 'profile' => {} }])
        )
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
slack-ruby-client-1.1.0 spec/slack/web/api/mixins/users_spec.rb
slack-ruby-client-1.0.0 spec/slack/web/api/mixins/users_spec.rb
slack-ruby-client-0.17.0 spec/slack/web/api/mixins/users_spec.rb
slack-ruby-client-0.16.0 spec/slack/web/api/mixins/users_spec.rb
slack-ruby-client-0.15.1 spec/slack/web/api/mixins/users_spec.rb