|
191 | 191 | expect(@user.reload).to have_password('newpassword') |
192 | 192 | end |
193 | 193 |
|
| 194 | + it 'should migrate the user to courses.mooc.fi when the password is changed' do |
| 195 | + expect_any_instance_of(User).to receive(:post_new_user_to_courses_mooc_fi).with('newpassword').and_return(true) |
| 196 | + put :update, params: { user: params.merge(old_password: 'oldpassword', |
| 197 | + password: 'newpassword', |
| 198 | + password_repeat: 'newpassword') } |
| 199 | + expect(response).to redirect_to(user_path) |
| 200 | + end |
| 201 | + |
| 202 | + it 'should not migrate the user to courses.mooc.fi when the password change fails' do |
| 203 | + expect_any_instance_of(User).not_to receive(:post_new_user_to_courses_mooc_fi) |
| 204 | + put :update, params: { user: params.merge(old_password: 'wrongpassword', |
| 205 | + password: 'newpassword', |
| 206 | + password_repeat: 'newpassword') } |
| 207 | + expect(response.status).to eq(403) |
| 208 | + end |
| 209 | + |
| 210 | + it 'should delegate to courses.mooc.fi without migrating for an already managed user' do |
| 211 | + @user.update!(password_managed_by_courses_mooc_fi: true, courses_mooc_fi_user_id: SecureRandom.uuid) |
| 212 | + expect_any_instance_of(User).to receive(:update_password_via_courses_mooc_fi).with('oldpassword', 'newpassword').and_return(true) |
| 213 | + expect_any_instance_of(User).not_to receive(:post_new_user_to_courses_mooc_fi) |
| 214 | + put :update, params: { user: params.merge(old_password: 'oldpassword', |
| 215 | + password: 'newpassword', |
| 216 | + password_repeat: 'newpassword') } |
| 217 | + expect(response).to redirect_to(user_path) |
| 218 | + end |
| 219 | + |
194 | 220 | it 'should not change the password if the old password was wrong' do |
195 | 221 | put :update, params: { user: params.merge(old_password: 'wrongpassword', |
196 | 222 | password: 'newpassword', |
|
0 commit comments