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