2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe ChatNames::AuthorizeUserService do
|
2017-08-17 22:00:37 +05:30
|
|
|
describe '#execute' do
|
2019-12-04 20:38:33 +05:30
|
|
|
subject { described_class.new(service, params) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
let(:result) { subject.execute }
|
|
|
|
let(:service) { create(:service) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
context 'when all parameters are valid' do
|
|
|
|
let(:params) { { team_id: 'T0001', team_domain: 'myteam', user_id: 'U0001', user_name: 'user' } }
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it 'produces a valid HTTP URL' do
|
|
|
|
expect(result).to be_http_url
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'requests a new token' do
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(subject).to receive(:request_token).once.and_call_original
|
|
|
|
|
|
|
|
subject.execute
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are missing parameters' do
|
|
|
|
let(:params) { {} }
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it 'does not produce a URL' do
|
|
|
|
expect(result).to be_nil
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'does not request a new token' do
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(subject).not_to receive(:request_token)
|
|
|
|
|
|
|
|
subject.execute
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|