Sha256: e1889f52b2a7d5a067a371552cad2fc7d6dfd210eda8c8aaf6d67c066e590acb

Contents?: true

Size: 1.75 KB

Versions: 19

Compression:

Stored size: 1.75 KB

Contents

require "test_helper"

class Identity::PasswordResetsControllerTest < ActionDispatch::IntegrationTest
  setup do
    @user = users(:lazaro_nixon)
  end

  test "should send a password reset email" do
    assert_enqueued_email_with UserMailer, :password_reset, args: { user: @user } do
      post identity_password_reset_url, params: { email: @user.email }
    end

    assert_response :no_content
  end

  test "should not send a password reset email to a nonexistent email" do
    assert_no_enqueued_emails do
      post identity_password_reset_url, params: { email: "invalid_email@hey.com" }
    end

    assert_response :bad_request
    assert_equal "You can't reset your password until you verify your email", response.parsed_body["error"]
  end

  test "should not send a password reset email to a unverified email" do
    @user.update! verified: false

    assert_no_enqueued_emails do
      post identity_password_reset_url, params: { email: @user.email }
    end

    assert_response :bad_request
    assert_equal "You can't reset your password until you verify your email", response.parsed_body["error"]
  end

  test "should update password" do
    sid = @user.password_reset_tokens.create.signed_id(expires_in: 20.minutes)

    patch identity_password_reset_url, params: { sid: sid, password: "Secret6*4*2*", password_confirmation: "Secret6*4*2*" }
    assert_response :success
  end

  test "should not update password with expired token" do
    sid_exp = @user.password_reset_tokens.create.signed_id(expires_in: 0.minutes)

    patch identity_password_reset_url, params: { sid: sid_exp, password: "Secret6*4*2*", password_confirmation: "Secret6*4*2*" }
    assert_response :bad_request
    assert_equal "That password reset link is invalid", response.parsed_body["error"]
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
authentication-zero-2.16.15 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.16.14 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.16.13 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.16.12 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.16.11 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.16.10 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.16.9 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.16.8 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.16.7 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.16.6 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.16.5 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.16.4 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.16.3 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.16.2 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.16.1 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.16.0 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.15.9 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.15.8 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.15.7 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt