49 lines
1.8 KiB
Ruby
49 lines
1.8 KiB
Ruby
require "test_helper"
|
|
|
|
class AdminSessionsFlowTest < ActionDispatch::IntegrationTest
|
|
def setup
|
|
@admin = AdminUser.create!(name: "Site Admin", email: "admin@example.com", password: "supersecret123")
|
|
end
|
|
|
|
test "login page renders the sign-in form" do
|
|
get admin_login_path
|
|
assert_response :success
|
|
assert_match "MySMSAPio", response.body
|
|
assert_match "Sign in", response.body
|
|
end
|
|
|
|
test "login page displays the auth error message on failed login" do
|
|
post admin_login_path, params: { email: "admin@example.com", password: "wrong-password" }
|
|
assert_response :unprocessable_entity
|
|
# The critical regression check: the alert must be present in the rendered HTML
|
|
assert_match "Invalid email or password", response.body
|
|
end
|
|
|
|
test "successful login redirects to the dashboard and shows welcome notice" do
|
|
post admin_login_path, params: { email: "admin@example.com", password: "supersecret123" }
|
|
assert_redirected_to admin_dashboard_path
|
|
follow_redirect!
|
|
assert_match "Welcome back", response.body
|
|
end
|
|
|
|
test "login is case-insensitive for email" do
|
|
post admin_login_path, params: { email: "ADMIN@example.com", password: "supersecret123" }
|
|
assert_redirected_to admin_dashboard_path
|
|
end
|
|
|
|
test "logging out clears the session and shows notice on the login page" do
|
|
post admin_login_path, params: { email: "admin@example.com", password: "supersecret123" }
|
|
delete admin_logout_path
|
|
assert_redirected_to admin_login_path
|
|
follow_redirect!
|
|
assert_match "logged out", response.body
|
|
end
|
|
|
|
test "protected admin page redirects to login with an alert" do
|
|
get admin_dashboard_path
|
|
assert_redirected_to admin_login_path
|
|
follow_redirect!
|
|
assert_match "Please log in to continue", response.body
|
|
end
|
|
end
|