mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-23 07:09:39 +02:00
Test environment stability improvements (#703)
* Add climate_control gem and test helper * Replace ENV mods in upgrades test * Replace ENV mods in registrations test * Remove ENV references in hostings controller * Update ENV refs in mailer test * ActiveStorage cleanup * Consolidate queue config so appropriate adapter runs in test environment * Make test environment more explicit * Centralize self hosting config * Remove flaky system test
This commit is contained in:
parent
98df7ccb11
commit
5dfbba403a
14 changed files with 137 additions and 137 deletions
|
@ -25,7 +25,7 @@ class RegistrationsControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
test "create when hosted requires an invite code" do
|
||||
in_invited_app do
|
||||
with_env_overrides REQUIRE_INVITE_CODE: "true" do
|
||||
assert_no_difference "User.count" do
|
||||
post registration_url, params: { user: {
|
||||
email: "john@example.com",
|
||||
|
@ -51,13 +51,4 @@ class RegistrationsControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def in_invited_app
|
||||
ENV["REQUIRE_INVITE_CODE"] = "true"
|
||||
yield
|
||||
ensure
|
||||
ENV["REQUIRE_INVITE_CODE"] = nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,80 +2,92 @@ require "test_helper"
|
|||
|
||||
class Settings::HostingsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
ENV["SELF_HOSTING_ENABLED"] = "true"
|
||||
sign_in users(:family_admin)
|
||||
end
|
||||
|
||||
test "cannot edit when self hosting is disabled" do
|
||||
ENV["SELF_HOSTING_ENABLED"] = "false"
|
||||
|
||||
get settings_hosting_url
|
||||
assert :not_found
|
||||
|
||||
patch settings_hosting_url, params: { setting: { render_deploy_hook: "https://example.com" } }
|
||||
assert :not_found
|
||||
end
|
||||
|
||||
test "should get edit when self hosting is enabled" do
|
||||
get settings_hosting_url
|
||||
assert_response :success
|
||||
with_self_hosting do
|
||||
get settings_hosting_url
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
test "can update settings when self hosting is enabled" do
|
||||
NEW_RENDER_DEPLOY_HOOK = "https://api.render.com/deploy/srv-abc123"
|
||||
assert_nil Setting.render_deploy_hook
|
||||
with_self_hosting do
|
||||
NEW_RENDER_DEPLOY_HOOK = "https://api.render.com/deploy/srv-abc123"
|
||||
assert_nil Setting.render_deploy_hook
|
||||
|
||||
patch settings_hosting_url, params: { setting: { render_deploy_hook: NEW_RENDER_DEPLOY_HOOK } }
|
||||
patch settings_hosting_url, params: { setting: { render_deploy_hook: NEW_RENDER_DEPLOY_HOOK } }
|
||||
|
||||
assert_equal NEW_RENDER_DEPLOY_HOOK, Setting.render_deploy_hook
|
||||
assert_equal NEW_RENDER_DEPLOY_HOOK, Setting.render_deploy_hook
|
||||
end
|
||||
end
|
||||
|
||||
test "cannot set auto upgrades mode without a deploy hook" do
|
||||
patch settings_hosting_url, params: { setting: { upgrades_mode: "auto" } }
|
||||
assert_response :unprocessable_entity
|
||||
with_self_hosting do
|
||||
patch settings_hosting_url, params: { setting: { upgrades_mode: "auto" } }
|
||||
assert_response :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
test "can choose auto upgrades mode with a deploy hook" do
|
||||
NEW_RENDER_DEPLOY_HOOK = "https://api.render.com/deploy/srv-abc123"
|
||||
assert_nil Setting.render_deploy_hook
|
||||
with_self_hosting do
|
||||
NEW_RENDER_DEPLOY_HOOK = "https://api.render.com/deploy/srv-abc123"
|
||||
assert_nil Setting.render_deploy_hook
|
||||
|
||||
patch settings_hosting_url, params: { setting: { render_deploy_hook: NEW_RENDER_DEPLOY_HOOK, upgrades_mode: "release" } }
|
||||
patch settings_hosting_url, params: { setting: { render_deploy_hook: NEW_RENDER_DEPLOY_HOOK, upgrades_mode: "release" } }
|
||||
|
||||
assert_equal "auto", Setting.upgrades_mode
|
||||
assert_equal "release", Setting.upgrades_target
|
||||
assert_equal NEW_RENDER_DEPLOY_HOOK, Setting.render_deploy_hook
|
||||
assert_equal "auto", Setting.upgrades_mode
|
||||
assert_equal "release", Setting.upgrades_target
|
||||
assert_equal NEW_RENDER_DEPLOY_HOOK, Setting.render_deploy_hook
|
||||
end
|
||||
end
|
||||
|
||||
test " #send_test_email if smtp settings are populated try to send an email and redirect with notice" do
|
||||
Setting.stubs(:smtp_settings_populated?).returns(true)
|
||||
with_self_hosting do
|
||||
Setting.stubs(:smtp_settings_populated?).returns(true)
|
||||
|
||||
test_email_mock = mock
|
||||
test_email_mock.expects(:deliver_now)
|
||||
test_email_mock = mock
|
||||
test_email_mock.expects(:deliver_now)
|
||||
|
||||
mailer_mock = mock
|
||||
mailer_mock.expects(:test_email).returns(test_email_mock)
|
||||
mailer_mock = mock
|
||||
mailer_mock.expects(:test_email).returns(test_email_mock)
|
||||
|
||||
NotificationMailer.expects(:with).with(user: users(:family_admin)).returns(mailer_mock)
|
||||
NotificationMailer.expects(:with).with(user: users(:family_admin)).returns(mailer_mock)
|
||||
|
||||
post send_test_email_settings_hosting_path
|
||||
assert_response :found
|
||||
assert controller.flash[:notice].present?
|
||||
post send_test_email_settings_hosting_path
|
||||
assert_response :found
|
||||
assert controller.flash[:notice].present?
|
||||
end
|
||||
end
|
||||
|
||||
test "#send_test_email with one blank smtp setting" do
|
||||
Setting.stubs(:smtp_settings_populated?).returns(false)
|
||||
NotificationMailer.expects(:with).never
|
||||
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?
|
||||
post send_test_email_settings_hosting_path
|
||||
assert_response :unprocessable_entity
|
||||
assert controller.flash[:error].present?
|
||||
end
|
||||
end
|
||||
|
||||
test "#send_test_email when sending the email raise an error" do
|
||||
Setting.stubs(:smtp_settings_populated?).returns(true)
|
||||
NotificationMailer.stubs(:with).raises(StandardError)
|
||||
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?
|
||||
post send_test_email_settings_hosting_path
|
||||
assert_response :unprocessable_entity
|
||||
assert controller.flash[:error].present?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,8 +4,6 @@ class UpgradesControllerTest < ActionDispatch::IntegrationTest
|
|||
setup do
|
||||
sign_in @user = users(:family_admin)
|
||||
|
||||
ENV["UPGRADES_ENABLED"] = "true"
|
||||
|
||||
@completed_upgrade = Upgrader::Upgrade.new(
|
||||
"commit",
|
||||
commit_sha: "47bb430954292d2fdcc81082af731a16b9587da3",
|
||||
|
@ -28,56 +26,64 @@ class UpgradesControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
test "controller not available when upgrades are disabled" do
|
||||
ENV["UPGRADES_ENABLED"] = "false"
|
||||
MOCK_COMMIT = "47bb430954292d2fdcc81082af731a16b9587da3"
|
||||
|
||||
post "/upgrades/acknowledge/47bb430954292d2fdcc81082af731a16b9587da3"
|
||||
post acknowledge_upgrade_url(MOCK_COMMIT)
|
||||
assert_response :not_found
|
||||
|
||||
post "/upgrades/deploy/47bb430954292d2fdcc81082af731a16b9587da3"
|
||||
post deploy_upgrade_url(MOCK_COMMIT)
|
||||
assert_response :not_found
|
||||
end
|
||||
|
||||
test "should acknowledge an upgrade prompt" do
|
||||
Upgrader.stubs(:find_upgrade).returns(@available_upgrade)
|
||||
with_env_overrides UPGRADES_ENABLED: "true" do
|
||||
Upgrader.stubs(:find_upgrade).returns(@available_upgrade)
|
||||
|
||||
post acknowledge_upgrade_url(@available_upgrade.commit_sha)
|
||||
post acknowledge_upgrade_url(@available_upgrade.commit_sha)
|
||||
|
||||
@user.reload
|
||||
assert_equal @user.last_prompted_upgrade_commit_sha, @available_upgrade.commit_sha
|
||||
assert :redirect
|
||||
@user.reload
|
||||
assert_equal @user.last_prompted_upgrade_commit_sha, @available_upgrade.commit_sha
|
||||
assert :redirect
|
||||
end
|
||||
end
|
||||
|
||||
test "should acknowledge an upgrade alert" do
|
||||
Upgrader.stubs(:find_upgrade).returns(@completed_upgrade)
|
||||
with_env_overrides UPGRADES_ENABLED: "true" do
|
||||
Upgrader.stubs(:find_upgrade).returns(@completed_upgrade)
|
||||
|
||||
post acknowledge_upgrade_url(@completed_upgrade.commit_sha)
|
||||
post acknowledge_upgrade_url(@completed_upgrade.commit_sha)
|
||||
|
||||
@user.reload
|
||||
assert_equal @user.last_alerted_upgrade_commit_sha, @completed_upgrade.commit_sha
|
||||
assert :redirect
|
||||
@user.reload
|
||||
assert_equal @user.last_alerted_upgrade_commit_sha, @completed_upgrade.commit_sha
|
||||
assert :redirect
|
||||
end
|
||||
end
|
||||
|
||||
test "should deploy an upgrade" do
|
||||
Upgrader.stubs(:find_upgrade).returns(@available_upgrade)
|
||||
with_env_overrides UPGRADES_ENABLED: "true" do
|
||||
Upgrader.stubs(:find_upgrade).returns(@available_upgrade)
|
||||
|
||||
post deploy_upgrade_path(@available_upgrade.commit_sha)
|
||||
post deploy_upgrade_path(@available_upgrade.commit_sha)
|
||||
|
||||
@user.reload
|
||||
assert_equal @user.last_prompted_upgrade_commit_sha, @available_upgrade.commit_sha
|
||||
assert :redirect
|
||||
@user.reload
|
||||
assert_equal @user.last_prompted_upgrade_commit_sha, @available_upgrade.commit_sha
|
||||
assert :redirect
|
||||
end
|
||||
end
|
||||
|
||||
test "should rollback user state if upgrade fails" do
|
||||
PRIOR_COMMIT = "47bb430954292d2fdcc81082af731a16b9587da2"
|
||||
@user.update!(last_prompted_upgrade_commit_sha: PRIOR_COMMIT)
|
||||
with_env_overrides UPGRADES_ENABLED: "true" do
|
||||
PRIOR_COMMIT = "47bb430954292d2fdcc81082af731a16b9587da2"
|
||||
@user.update!(last_prompted_upgrade_commit_sha: PRIOR_COMMIT)
|
||||
|
||||
Upgrader.stubs(:find_upgrade).returns(@available_upgrade)
|
||||
Upgrader.stubs(:upgrade_to).returns({ success: false })
|
||||
Upgrader.stubs(:find_upgrade).returns(@available_upgrade)
|
||||
Upgrader.stubs(:upgrade_to).returns({ success: false })
|
||||
|
||||
post deploy_upgrade_path(@available_upgrade.commit_sha)
|
||||
post deploy_upgrade_path(@available_upgrade.commit_sha)
|
||||
|
||||
@user.reload
|
||||
assert_equal @user.last_prompted_upgrade_commit_sha, PRIOR_COMMIT
|
||||
assert :redirect
|
||||
@user.reload
|
||||
assert_equal @user.last_prompted_upgrade_commit_sha, PRIOR_COMMIT
|
||||
assert :redirect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue