2024-04-13 09:28:45 -04:00
|
|
|
require "test_helper"
|
|
|
|
|
2024-04-18 07:56:51 -04:00
|
|
|
class Settings::HostingsControllerTest < ActionDispatch::IntegrationTest
|
2024-04-13 09:28:45 -04:00
|
|
|
setup do
|
|
|
|
sign_in users(:family_admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "cannot edit when self hosting is disabled" do
|
2024-04-18 07:56:51 -04:00
|
|
|
get settings_hosting_url
|
2024-04-13 09:28:45 -04:00
|
|
|
assert :not_found
|
|
|
|
|
2024-04-18 07:56:51 -04:00
|
|
|
patch settings_hosting_url, params: { setting: { render_deploy_hook: "https://example.com" } }
|
2024-04-13 09:28:45 -04:00
|
|
|
assert :not_found
|
|
|
|
end
|
2024-05-02 13:18:18 -04:00
|
|
|
|
2024-04-13 09:28:45 -04:00
|
|
|
test "should get edit when self hosting is enabled" do
|
2024-05-02 13:18:18 -04:00
|
|
|
with_self_hosting do
|
|
|
|
get settings_hosting_url
|
|
|
|
assert_response :success
|
|
|
|
end
|
2024-04-13 09:28:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "can update settings when self hosting is enabled" do
|
2024-05-02 13:18:18 -04:00
|
|
|
with_self_hosting do
|
|
|
|
NEW_RENDER_DEPLOY_HOOK = "https://api.render.com/deploy/srv-abc123"
|
|
|
|
assert_nil Setting.render_deploy_hook
|
2024-04-13 09:28:45 -04:00
|
|
|
|
2024-05-02 13:18:18 -04:00
|
|
|
patch settings_hosting_url, params: { setting: { render_deploy_hook: NEW_RENDER_DEPLOY_HOOK } }
|
2024-04-13 09:28:45 -04:00
|
|
|
|
2024-05-02 13:18:18 -04:00
|
|
|
assert_equal NEW_RENDER_DEPLOY_HOOK, Setting.render_deploy_hook
|
|
|
|
end
|
2024-04-13 09:28:45 -04:00
|
|
|
end
|
2024-04-25 14:55:39 -04:00
|
|
|
|
|
|
|
test "cannot set auto upgrades mode without a deploy hook" do
|
2024-05-02 13:18:18 -04:00
|
|
|
with_self_hosting do
|
|
|
|
patch settings_hosting_url, params: { setting: { upgrades_mode: "auto" } }
|
|
|
|
assert_response :unprocessable_entity
|
|
|
|
end
|
2024-04-25 14:55:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "can choose auto upgrades mode with a deploy hook" do
|
2024-05-02 13:18:18 -04:00
|
|
|
with_self_hosting do
|
|
|
|
NEW_RENDER_DEPLOY_HOOK = "https://api.render.com/deploy/srv-abc123"
|
|
|
|
assert_nil Setting.render_deploy_hook
|
2024-04-25 14:55:39 -04:00
|
|
|
|
2024-05-02 13:18:18 -04:00
|
|
|
patch settings_hosting_url, params: { setting: { render_deploy_hook: NEW_RENDER_DEPLOY_HOOK, upgrades_mode: "release" } }
|
2024-04-25 14:55:39 -04:00
|
|
|
|
2024-05-02 13:18:18 -04:00
|
|
|
assert_equal "auto", Setting.upgrades_mode
|
|
|
|
assert_equal "release", Setting.upgrades_target
|
|
|
|
assert_equal NEW_RENDER_DEPLOY_HOOK, Setting.render_deploy_hook
|
|
|
|
end
|
2024-04-25 14:55:39 -04:00
|
|
|
end
|
2024-04-29 22:44:24 +02:00
|
|
|
|
|
|
|
test " #send_test_email if smtp settings are populated try to send an email and redirect with notice" do
|
2024-05-02 13:18:18 -04:00
|
|
|
with_self_hosting do
|
|
|
|
Setting.stubs(:smtp_settings_populated?).returns(true)
|
2024-04-29 22:44:24 +02:00
|
|
|
|
2024-05-02 13:18:18 -04:00
|
|
|
test_email_mock = mock
|
|
|
|
test_email_mock.expects(:deliver_now)
|
2024-04-29 22:44:24 +02:00
|
|
|
|
2024-05-02 13:18:18 -04:00
|
|
|
mailer_mock = mock
|
|
|
|
mailer_mock.expects(:test_email).returns(test_email_mock)
|
2024-04-29 22:44:24 +02:00
|
|
|
|
2024-05-02 13:18:18 -04:00
|
|
|
NotificationMailer.expects(:with).with(user: users(:family_admin)).returns(mailer_mock)
|
2024-04-29 22:44:24 +02:00
|
|
|
|
2024-05-02 13:18:18 -04:00
|
|
|
post send_test_email_settings_hosting_path
|
|
|
|
assert_response :found
|
|
|
|
assert controller.flash[:notice].present?
|
|
|
|
end
|
2024-04-29 22:44:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test "#send_test_email with one blank smtp setting" do
|
2024-05-02 13:18:18 -04:00
|
|
|
with_self_hosting do
|
|
|
|
Setting.stubs(:smtp_settings_populated?).returns(false)
|
|
|
|
NotificationMailer.expects(:with).never
|
|
|
|
|
|
|
|
post send_test_email_settings_hosting_path
|
|
|
|
assert_response :unprocessable_entity
|
|
|
|
assert controller.flash[:error].present?
|
|
|
|
end
|
2024-04-29 22:44:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test "#send_test_email when sending the email raise an error" do
|
2024-05-02 13:18:18 -04:00
|
|
|
with_self_hosting do
|
|
|
|
Setting.stubs(:smtp_settings_populated?).returns(true)
|
|
|
|
NotificationMailer.stubs(:with).raises(StandardError)
|
|
|
|
|
|
|
|
post send_test_email_settings_hosting_path
|
|
|
|
assert_response :unprocessable_entity
|
|
|
|
assert controller.flash[:error].present?
|
|
|
|
end
|
2024-04-29 22:44:24 +02:00
|
|
|
end
|
2024-04-13 09:28:45 -04:00
|
|
|
end
|