|
| 1 | +require 'test_helper' |
| 2 | + |
| 3 | +class Api::V1::Users::PasswordsControllerTest < ActionDispatch::IntegrationTest |
| 4 | + test 'forgot returns successful given an email of an existing user' do |
| 5 | + create :user, email: 'forgetful@example.com' |
| 6 | + |
| 7 | + post api_v1_users_passwords_forgot_url, |
| 8 | + params: { email: 'forgetful@example.com' }, |
| 9 | + as: :json |
| 10 | + |
| 11 | + assert_equal 200, response.status |
| 12 | + end |
| 13 | + |
| 14 | + test 'forgot generates a password reset token' do |
| 15 | + user = create :user |
| 16 | + User.any_instance.expects(:generate_password_token!) |
| 17 | + |
| 18 | + post api_v1_users_passwords_forgot_url, |
| 19 | + params: { email: user.email }, |
| 20 | + as: :json |
| 21 | + end |
| 22 | + |
| 23 | + test 'forgot emails user instructions to reset their password' do |
| 24 | + user = create :user |
| 25 | + User.any_instance.expects(:send_reset_password_instructions) |
| 26 | + |
| 27 | + post api_v1_users_passwords_forgot_url, |
| 28 | + params: { email: user.email }, |
| 29 | + as: :json |
| 30 | + end |
| 31 | + |
| 32 | + test 'forgot returns unprocessable error when given an email that does not match an existing user' do |
| 33 | + post api_v1_users_passwords_forgot_url, |
| 34 | + params: { email: 'totallydoesnotexist@example.com' }, |
| 35 | + as: :json |
| 36 | + |
| 37 | + assert_equal 422, response.status |
| 38 | + end |
| 39 | + |
| 40 | + test 'forgot requires an email address be given' do |
| 41 | + post api_v1_users_passwords_forgot_url, |
| 42 | + params: { no: 'email key in params' }, |
| 43 | + as: :json |
| 44 | + assert_equal 422, response.status |
| 45 | + end |
| 46 | +end |
0 commit comments