Files
eminuxCRM/test/controllers/authentication_test.rb
T
eminuxandCursor 936930e691 Espone API JSON e MCP HTTP per far lavorare gli agenti sul CRM.
Gli agenti autenticati con token Bearer possono leggere today/pipeline e annotare attività, con host MCP allineati a quelli di produzione.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-02 22:43:46 +02:00

110 lines
3.2 KiB
Ruby

require "test_helper"
class AuthenticationTest < ActionDispatch::IntegrationTest
test "requires login" do
get root_path
assert_redirected_to login_path
end
test "login and logout" do
login_as users(:admin)
assert_response :redirect
follow_redirect!
assert_response :success
delete logout_path
assert_redirected_to login_path
end
test "non admin cannot create users" do
login_as users(:marco)
follow_redirect! if response.redirect?
post users_path, params: {
user: { email: "x@example.com", first_name: "X", last_name: "Y", role: "user", password: "password123", password_confirmation: "password123" }
}
assert_response :redirect
end
test "project space is isolated by url" do
login_as users(:admin)
follow_redirect! if response.redirect?
get project_root_path(project_code: "matchlivetv")
assert_response :success
assert_match(/MatchLiveTV/, response.body)
get project_root_path(project_code: "riskmeter")
assert_response :success
assert_match(/RiskMeter/, response.body)
end
test "user cannot open disabled project" do
login_as users(:marco)
follow_redirect! if response.redirect?
get project_root_path(project_code: "riskmeter")
assert_redirected_to root_path
end
test "project pages render mobile navigation shell" do
login_as users(:admin)
follow_redirect! if response.redirect?
get project_root_path(project_code: "matchlivetv")
assert_response :success
assert_match(/mobile-bottom-nav/, response.body)
assert_match(/Altro/, response.body)
end
test "pipeline page renders mobile helper text" do
login_as users(:admin)
follow_redirect! if response.redirect?
get pipeline_path(project_code: "matchlivetv")
assert_response :success
assert_match(/Su cellulare la vedi per stage in verticale/, response.body)
end
test "disabled user cannot login" do
admin = users(:admin)
User.create!(
email: "keeper@example.com",
first_name: "Keep",
last_name: "Admin",
role: "admin",
password: "password123",
password_confirmation: "password123"
)
assert admin.update(active: false)
post login_path, params: { email: admin.email, password: "password123" }
assert_response :unprocessable_entity
assert_match(/Email o password non validi/i, response.body)
end
test "admin can open platform settings" do
login_as users(:admin)
follow_redirect! if response.redirect?
get admin_path
assert_response :success
assert_match(/Impostazioni piattaforma/, response.body)
assert_match(/Utenti/, response.body)
assert_match(/Token API/, response.body)
end
test "non admin cannot open platform settings" do
login_as users(:marco)
follow_redirect! if response.redirect?
get admin_path
assert_redirected_to root_path
end
test "admin home has new project and settings actions" do
login_as users(:admin)
follow_redirect! if response.redirect?
get root_path
assert_response :success
assert_match(/Nuovo progetto/, response.body)
assert_match(/Impostazioni/, response.body)
assert_no_match(/Amministrazione progetti/, response.body)
end
end