|
55 | 55 |
|
56 | 56 | context 'register' do |
57 | 57 | before do |
58 | | - oauth_access = { 'bot' => { 'bot_access_token' => 'token' }, 'team_id' => 'team_id', 'team_name' => 'team_name' } |
| 58 | + oauth_access = { |
| 59 | + 'bot' => { |
| 60 | + 'bot_access_token' => 'token', |
| 61 | + 'bot_user_id' => 'bot_user_id' |
| 62 | + }, |
| 63 | + 'access_token' => 'access_token', |
| 64 | + 'user_id' => 'activated_user_id', |
| 65 | + 'team_id' => 'team_id', |
| 66 | + 'team_name' => 'team_name' |
| 67 | + } |
59 | 68 | ENV['SLACK_CLIENT_ID'] = 'client_id' |
60 | 69 | ENV['SLACK_CLIENT_SECRET'] = 'client_secret' |
| 70 | + allow_any_instance_of(Slack::Web::Client).to receive(:im_open).with( |
| 71 | + user: 'activated_user_id' |
| 72 | + ).and_return( |
| 73 | + 'channel' => { |
| 74 | + 'id' => 'C1' |
| 75 | + } |
| 76 | + ) |
61 | 77 | allow_any_instance_of(Slack::Web::Client).to receive(:oauth_access).with( |
62 | 78 | hash_including( |
63 | 79 | code: 'code', |
|
71 | 87 | ENV.delete('SLACK_CLIENT_SECRET') |
72 | 88 | end |
73 | 89 | it 'creates a team' do |
74 | | - expect(SlackApiExplorer::Service.instance).to receive(:start!) |
| 90 | + expect(SlackRubyBotServer::Service.instance).to receive(:start!) |
75 | 91 | expect do |
76 | 92 | team = client.teams._post(code: 'code') |
77 | 93 | expect(team.team_id).to eq 'team_id' |
|
81 | 97 | end.to change(Team, :count).by(1) |
82 | 98 | end |
83 | 99 | it 'reactivates a deactivated team' do |
84 | | - expect(SlackApiExplorer::Service.instance).to receive(:start!) |
| 100 | + expect(SlackRubyBotServer::Service.instance).to receive(:start!) |
85 | 101 | existing_team = Fabricate(:team, token: 'token', active: false) |
86 | 102 | expect do |
87 | 103 | team = client.teams._post(code: 'code') |
|
101 | 117 | end |
102 | 118 | end |
103 | 119 | it 'reactivates a deactivated team with a different code' do |
104 | | - expect(SlackApiExplorer::Service.instance).to receive(:start!) |
| 120 | + expect(SlackRubyBotServer::Service.instance).to receive(:start!) |
105 | 121 | existing_team = Fabricate(:team, token: 'old', team_id: 'team_id', active: false) |
106 | 122 | expect do |
107 | 123 | team = client.teams._post(code: 'code') |
|
113 | 129 | expect(team.active).to be true |
114 | 130 | end.to_not change(Team, :count) |
115 | 131 | end |
| 132 | + |
| 133 | + context 'with mailchimp settings' do |
| 134 | + before do |
| 135 | + SlackRubyBotServer::Mailchimp.configure do |config| |
| 136 | + config.mailchimp_api_key = 'api-key' |
| 137 | + config.mailchimp_list_id = 'list-id' |
| 138 | + end |
| 139 | + end |
| 140 | + after do |
| 141 | + SlackRubyBotServer::Mailchimp.config.reset! |
| 142 | + end |
| 143 | + |
| 144 | + let(:list) { double(Mailchimp::List, members: double(Mailchimp::List::Members)) } |
| 145 | + |
| 146 | + it 'subscribes to the mailing list' do |
| 147 | + expect(SlackRubyBotServer::Service.instance).to receive(:start!) |
| 148 | + |
| 149 | + allow_any_instance_of(Slack::Web::Client).to receive(:users_info).with( |
| 150 | + user: 'activated_user_id' |
| 151 | + ).and_return( |
| 152 | + user: { |
| 153 | + profile: { |
| 154 | + |
| 155 | + first_name: 'First', |
| 156 | + last_name: 'Last' |
| 157 | + } |
| 158 | + } |
| 159 | + ) |
| 160 | + |
| 161 | + allow_any_instance_of(Mailchimp::Client).to receive(:lists).with('list-id').and_return(list) |
| 162 | + |
| 163 | + expect(list.members).to receive(:where).with(email_address: '[email protected]').and_return([]) |
| 164 | + |
| 165 | + expect(list.members).to receive(:create_or_update).with( |
| 166 | + email_address: '[email protected]', |
| 167 | + merge_fields: { |
| 168 | + 'FNAME' => 'First', |
| 169 | + 'LNAME' => 'Last', |
| 170 | + 'BOT' => 'SlackApiExplorer' |
| 171 | + }, |
| 172 | + status: 'pending', |
| 173 | + name: nil, |
| 174 | + tags: %w[slack-api-explorer], |
| 175 | + unique_email_id: 'team_id-activated_user_id' |
| 176 | + ) |
| 177 | + |
| 178 | + client.teams._post(code: 'code') |
| 179 | + end |
| 180 | + after do |
| 181 | + ENV.delete('MAILCHIMP_API_KEY') |
| 182 | + ENV.delete('MAILCHIMP_LIST_ID') |
| 183 | + end |
| 184 | + end |
116 | 185 | end |
117 | 186 | end |
118 | 187 | end |
0 commit comments