-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathteams_spec.rb
75 lines (74 loc) · 2.84 KB
/
teams_spec.rb
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require 'spec_helper'
describe 'Teams', js: true, type: :feature do
before do
ENV['SLACK_CLIENT_ID'] = 'client_id'
ENV['SLACK_CLIENT_SECRET'] = 'client_secret'
SlackRubyBotServer::Config.oauth_scope = ['channels:read', 'channels:write']
allow_any_instance_of(Team).to receive(:ping!).and_return(ok: true)
end
after do
ENV.delete 'SLACK_CLIENT_ID'
ENV.delete 'SLACK_CLIENT_SECRET'
SlackRubyBotServer::Config.oauth_scope = nil
end
context 'oauth v1' do
before do
SlackRubyBotServer::Config.oauth_version = :v1
end
context 'oauth' do
before do
oauth_access = Slack::Messages::Message.new({ 'bot' => { 'bot_access_token' => 'token' }, 'team_id' => 'team_id', 'team_name' => 'team_name' })
allow_any_instance_of(Slack::Web::Client).to receive(:oauth_access).with(hash_including(code: 'code')).and_return(oauth_access)
end
it 'registers a team' do
expect do
visit '/?v1&code=code'
expect(page.find('#messages')).to have_content 'Team successfully registered!'
end.to change(Team, :count).by(1)
end
it 'includes optional parameter' do
expect(SlackRubyBotServer::Service.instance).to receive(:create!).with(instance_of(Team), { state: 'property' })
visit '/?v1&code=code&state=property'
end
end
context 'homepage' do
before do
visit '/?v1'
end
it 'includes a link to add to slack with the client id' do
expect(title).to eq('Slack Ruby Bot Server')
expect(find("a[href='https://slack.com/oauth/authorize?scope=channels:read,channels:write&client_id=client_id"))
end
end
end
context 'oauth v2' do
before do
SlackRubyBotServer::Config.oauth_version = :v2
end
context 'oauth' do
before do
oauth_access = Slack::Messages::Message.new({ 'access_token' => 'token', 'team' => { 'id' => 'team_id', 'name' => 'team_name' } })
allow_any_instance_of(Slack::Web::Client).to receive(:oauth_v2_access).with(hash_including(code: 'code')).and_return(oauth_access)
end
it 'registers a team' do
expect do
visit '/?v2&code=code'
expect(page.find('#messages')).to have_content 'Team successfully registered!'
end.to change(Team, :count).by(1)
end
it 'includes optional parameter' do
expect(SlackRubyBotServer::Service.instance).to receive(:create!).with(instance_of(Team), { state: 'property' })
visit '/?v2&code=code&state=property'
end
end
context 'homepage' do
before do
visit '/?v2'
end
it 'includes a link to add to slack with the client id' do
expect(title).to eq('Slack Ruby Bot Server')
expect(find("a[href='https://slack.com/oauth/v2/authorize?scope=channels:read,channels:write&client_id=client_id"))
end
end
end
end