summaryrefslogtreecommitdiff
path: root/spec/services/chat_names/authorize_user_service_spec.rb
blob: 53d90c7f100e49c5caed79dea12f0afb70d456ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ChatNames::AuthorizeUserService do
  describe '#execute' do
    let(:integration) { create(:integration) }
    let(:result) { subject.execute }

    subject { described_class.new(integration, params) }

    context 'when all parameters are valid' do
      let(:params) { { team_id: 'T0001', team_domain: 'myteam', user_id: 'U0001', user_name: 'user' } }

      it 'produces a valid HTTP URL' do
        expect(result).to be_http_url
      end

      it 'requests a new token' do
        expect(subject).to receive(:request_token).once.and_call_original

        subject.execute
      end
    end

    context 'when there are missing parameters' do
      let(:params) { {} }

      it 'does not produce a URL' do
        expect(result).to be_nil
      end

      it 'does not request a new token' do
        expect(subject).not_to receive(:request_token)

        subject.execute
      end
    end
  end
end