Skip to content

Commit

Permalink
fix: Try to fix tests to get a more sustainable test env
Browse files Browse the repository at this point in the history
  • Loading branch information
AyakorK committed Aug 2, 2024
1 parent d907559 commit 6ea4fa6
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize(auth_settings, form)

def call
return broadcast(:invalid) if form.invalid?
return broadcast(:sms_service_not_configured) if form.enable_partial_sms_signup && !check_sms_service
return broadcast(:sms_service_not_configured) if form.enable_partial_sms_signup && !sms_gateway_service_configured?

update_auth_settings
broadcast(:ok)
Expand All @@ -27,7 +27,7 @@ def call

attr_reader :form

def check_sms_service
def sms_gateway_service_configured?
Decidim.config.sms_gateway_service.present?
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
)
end
let(:command) { described_class.new(auth_settings, form) }
let(:sms_gateway_service) { "Decidim::Verifications::Sms::ExampleGateway" }
let(:sms_gateway_service) { instance_double(Decidim::Verifications::Sms::ExampleGateway, present?: true) }

before do
Decidim.configure do |config|
config.sms_gateway_service = sms_gateway_service
end
allow(Decidim.config).to receive(:sms_gateway_service).and_return(sms_gateway_service)
end

after do
allow(Decidim.config).to receive(:sms_gateway_service).and_call_original
end

describe "#call" do
Expand Down
4 changes: 4 additions & 0 deletions spec/commands/decidim/half_signup/send_verification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
end
end

after do
allow(Decidim.config).to receive(:sms_gateway_service).and_call_original
end

describe "when email" do
let!(:auth_method) { "email" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
request.env["devise.mapping"] = ::Devise.mappings[:user]
request.session[:auth_attempt] = auth_session

Decidim.configure do |config|
config.sms_gateway_service = sms_gateway_service
end
allow(Decidim.config).to receive(:sms_gateway_service).and_return(sms_gateway_service)
end

after do
allow(Decidim.config).to receive(:sms_gateway_service).and_call_original
end

describe "GET #sms" do
Expand Down
8 changes: 5 additions & 3 deletions spec/system/add_update_phone_number_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
switch_to_host(organization.host)
visit decidim.account_path

Decidim.configure do |config|
config.sms_gateway_service = sms_gateway_service
end
allow(Decidim.config).to receive(:sms_gateway_service).and_return(sms_gateway_service)
end

after do
allow(Decidim.config).to receive(:sms_gateway_service).and_call_original
end

context "when sms_auth is not enabled" do
Expand Down
71 changes: 37 additions & 34 deletions spec/system/admin_manage_auth_settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
switch_to_host(organization.host)
visit decidim_admin.edit_organization_path

Decidim.configure do |config|
config.sms_gateway_service = sms_gateway_service
end
allow(Decidim.config).to receive(:sms_gateway_service).and_return(sms_gateway_service)
end

after do
allow(Decidim.config).to receive(:sms_gateway_service).and_call_original
end

it "shows the menu in the admin panel in a correct place" do
Expand Down Expand Up @@ -54,41 +56,42 @@
expect(auth_settings.enable_partial_sms_signup).to be(true)
end

it "shows a warning message when the SMS gateway service is not configured" do
Decidim.configure do |config|
config.sms_gateway_service = nil
context "when sms gateway service is not present" do
before do
allow(Decidim.config).to receive(:sms_gateway_service).and_return(nil)
end
click_link "Authentication settings"
expect(page).to have_current_path(decidim_half_signup_admin.edit_auth_setting_path(slug: "authentication_settings"))
expect(page).to have_css(".is-active", text: "Authentication settings")
expect(page.find("#auth_setting_enable_partial_sms_signup")).to be_disabled
expect(page).to have_content("This option is disabled please contact the host of the platform to enable it.")
end

it "shows an error message when the SMS gateway service is not configured if the user tries to force the change" do
click_link "Authentication settings"
expect(page).to have_current_path(decidim_half_signup_admin.edit_auth_setting_path(slug: "authentication_settings"))
expect(page).to have_css(".is-active", text: "Authentication settings")
check "Enable partial sign up and sign in using SMS verification"
check "Enable partial sign up and sign in using email verification"

Decidim.configure do |config|
config.sms_gateway_service = nil
it "shows a warning message when the SMS gateway service is not configured" do
click_link "Authentication settings"
expect(page).to have_current_path(decidim_half_signup_admin.edit_auth_setting_path(slug: "authentication_settings"))
expect(page).to have_css(".is-active", text: "Authentication settings")
expect(page.find("#auth_setting_enable_partial_sms_signup")).to be_disabled
expect(page).to have_content("This option is disabled please contact the host of the platform to enable it.")
end

click_button "Update"
expect(page).to have_current_path(decidim_half_signup_admin.edit_auth_setting_path(slug: "authentication_settings"))
within ".callout-wrapper" do
expect(page).not_to have_content("Organization updated successfully.")
expect(page).to have_content("The SMS gateway service is not defined.")
end
expect(page).to have_content("Settings available through code")
within "code" do
expect(page).to have_content("Decidim::HalfSignup.configure do |config|")
it "shows an error message when the SMS gateway service is not configured if the user tries to force the change" do
click_link "Authentication settings"
expect(page).to have_current_path(decidim_half_signup_admin.edit_auth_setting_path(slug: "authentication_settings"))
expect(page).to have_css(".is-active", text: "Authentication settings")
check "Enable partial sign up and sign in using SMS verification"
check "Enable partial sign up and sign in using email verification"

allow(Decidim.config).to receive(:sms_gateway_service).and_return(nil)

click_button "Update"
expect(page).to have_current_path(decidim_half_signup_admin.edit_auth_setting_path(slug: "authentication_settings"))
within ".callout-wrapper" do
expect(page).not_to have_content("Organization updated successfully.")
expect(page).to have_content("The SMS gateway service is not defined.")
end
expect(page).to have_content("Settings available through code")
within "code" do
expect(page).to have_content("Decidim::HalfSignup.configure do |config|")
end
expect(page.find("#auth_setting_enable_partial_sms_signup")).not_to be_checked
auth_settings = Decidim::HalfSignup::AuthSetting.last
expect(auth_settings.enable_partial_email_signup).to be(false)
expect(auth_settings.enable_partial_sms_signup).to be(false)
end
expect(page.find("#auth_setting_enable_partial_sms_signup")).not_to be_checked
auth_settings = Decidim::HalfSignup::AuthSetting.last
expect(auth_settings.enable_partial_email_signup).to be(false)
expect(auth_settings.enable_partial_sms_signup).to be(false)
end
end
8 changes: 5 additions & 3 deletions spec/system/budgets_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
before do
switch_to_host(organization.host)

Decidim.configure do |config|
config.sms_gateway_service = sms_gateway_service
end
allow(Decidim.config).to receive(:sms_gateway_service).and_return(sms_gateway_service)
end

after do
allow(Decidim.config).to receive(:sms_gateway_service).and_call_original
end

context "with multiple budgets" do
Expand Down

0 comments on commit 6ea4fa6

Please sign in to comment.