Sha256: 7dfc394f404c61c03b72ba2efb451e164a10e10b11b50e28baf2d4a0276979fd

Contents?: true

Size: 1.75 KB

Versions: 9

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.create_password_reset_token.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.create_password_reset_token.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

9 entries across 9 versions & 1 rubygems

Version Path
authentication-zero-2.15.6 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.15.5 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.15.4 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.15.3 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.15.2 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.15.1 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.15.0 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.14.0 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
authentication-zero-2.13.0 lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt