skill-assessment-app/test/controllers/admin/auth_controller_test.rb

98 lines
2.8 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2016-08-17 17:49:09 -05:00
require 'test_helper'
module Admin
class AuthControllerTest < ActionDispatch::IntegrationTest
2016-09-14 14:38:26 -05:00
include ActiveJob::TestHelper
2016-08-17 17:49:09 -05:00
test "should get login" do
2016-08-18 15:35:17 -05:00
get admin_login_url
2016-08-17 17:49:09 -05:00
assert_response :success
assert_template 'admin/auth/login'
end
test "should get logout" do
2016-08-18 15:35:17 -05:00
post admin_auth_url, params: { auth:
{ email: 'alan.admin@mailinator.com', password: 'password' } }
2016-08-17 17:49:09 -05:00
get admin_logout_url
2016-08-18 15:35:17 -05:00
assert_redirected_to admin_login_url
assert session[:user].nil?
end
test "should auth to dashboard" do
post admin_auth_url, params: { auth:
{ email: 'alan.admin@mailinator.com', password: 'password' } }
assert_redirected_to admin_url
end
2016-09-22 17:26:00 -05:00
test "should FAIL auth" do
post admin_auth_url, params: { auth:
{ email: 'alan.admin@mailinator.com', password: 'b@d9a$$werD' } }
assert_redirected_to admin_login_url
assert_match(/incorrect.*password/i, flash[:error])
end
test "recruiter should auth to dashboard" do
2016-08-18 15:35:17 -05:00
post admin_auth_url, params: { auth:
{ email: 'pdr.recruiter@mailinator.com', password: 'password' } }
assert_redirected_to admin_url
2016-08-18 15:35:17 -05:00
end
test "reviewer should auth to dashboard" do
2016-08-18 15:35:17 -05:00
post admin_auth_url, params: { auth:
{ email: 'fed.reviewer@mailinator.com', password: 'password' } }
assert_redirected_to admin_url
2016-08-17 17:49:09 -05:00
end
2016-08-24 15:02:32 -05:00
test "should get reset_request" do
get admin_reset_request_url
assert_response :success
end
test "should process a reset request" do
user = users(:admin)
2016-09-14 14:38:26 -05:00
assert_enqueued_jobs 1 do
2016-08-24 16:26:07 -05:00
post admin_send_reset_url, params: { auth: { email: user.email } }
end
2016-08-24 15:02:32 -05:00
refute_equal user.reset_token, User.find(user.id).reset_token
assert_redirected_to admin_reset_request_url
assert_match(/request.*sent/i, flash[:success])
end
test "should redirect with invalid reset_token" do
get admin_reset_url('fooBarBaz')
assert_redirected_to admin_reset_request_url
end
test "should get reset form" do
user = users(:admin)
user.setup_reset
get admin_reset_url(user.reset_token)
assert :success
end
test "should post password reset" do
user = users(:admin)
user.setup_reset
post admin_reset_password_url, params: { auth:
{ reset_token: user.reset_token, password: '12345', password_confirmation: '12345' } }
assert_redirected_to admin_auth_path
assert_match(/reset.*log/i, flash[:success])
end
2016-08-24 16:47:15 -05:00
test "should fail to reset with mistyped password" do
user = users(:admin)
user.setup_reset
post admin_reset_password_url, params: { auth:
{ reset_token: user.reset_token, password: '12345', password_confirmation: 'abcde' } }
assert :success
assert flash[:error]
end
2016-08-17 17:49:09 -05:00
end
end