Skip to content

Commit

Permalink
Merge pull request #6251 from CitizenLabDotCo/fix-e2e
Browse files Browse the repository at this point in the history
Fix e2e: Set and send confirmation code synchronously
  • Loading branch information
sebastienhoorens authored Oct 27, 2023
2 parents 5dde780 + 87fe824 commit 1840e0e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion back/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def reset_confirmation_and_counts
end

def should_send_confirmation_email?
confirmation_required? && email_confirmation_code_sent_at.nil?
confirmation_required? && email_confirmation_code_sent_at.nil? && (PhoneService.new.encoded_phone_or_email?(email) == :email)
end

def email_confirmation_code_expiration_at
Expand Down
4 changes: 2 additions & 2 deletions back/app/services/side_fx_user_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def after_create(user, current_user)
LogActivityJob.set(wait: 5.seconds).perform_later(user, 'admin_rights_given', current_user, user.created_at.to_i)
end
user.create_email_campaigns_unsubscription_token
RequestConfirmationCodeJob.perform_later(user) if user.should_send_confirmation_email?
RequestConfirmationCodeJob.perform_now(user) if user.should_send_confirmation_email?
AdditionalSeatsIncrementer.increment_if_necessary(user, current_user) if user.roles_previously_changed?
end

Expand All @@ -29,7 +29,7 @@ def after_update(user, current_user)
AdditionalSeatsIncrementer.increment_if_necessary(user, current_user) if user.roles_previously_changed?

UpdateMemberCountJob.perform_later
RequestConfirmationCodeJob.perform_later(user) if user.should_send_confirmation_email?
RequestConfirmationCodeJob.perform_now(user) if user.should_send_confirmation_email?
end

def before_destroy(user, _current_user)
Expand Down
10 changes: 5 additions & 5 deletions back/spec/acceptance/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@

context 'when the user_confirmation module is active' do
before do
allow(RequestConfirmationCodeJob).to receive(:perform_later)
allow(RequestConfirmationCodeJob).to receive(:perform_now)
SettingsService.new.activate_feature! 'user_confirmation'
end

Expand All @@ -170,7 +170,7 @@
assert_status 201
json_response = json_parse(response_body)
user = User.order(:created_at).last
expect(RequestConfirmationCodeJob).to have_received(:perform_later).with(user).once
expect(RequestConfirmationCodeJob).to have_received(:perform_now).with(user).once
expect(json_response.dig(:data, :attributes, :confirmation_required)).to be true # when no custom fields
end
end
Expand Down Expand Up @@ -292,15 +292,15 @@
let(:locale) { 'en' }

before do
allow(RequestConfirmationCodeJob).to receive(:perform_later)
allow(RequestConfirmationCodeJob).to receive(:perform_now)
SettingsService.new.activate_feature! 'user_confirmation'
end

describe 'create a user with no password' do
example_request 'User successfully created and requires confirmation' do
assert_status 201
user = User.order(:created_at).last
expect(RequestConfirmationCodeJob).to have_received(:perform_later).with(user).once
expect(RequestConfirmationCodeJob).to have_received(:perform_now).with(user).once
expect(response_data.dig(:attributes, :confirmation_required)).to be(true)
end

Expand All @@ -319,7 +319,7 @@
do_request
assert_status 200
expect(response_data.dig(:attributes, :confirmation_required)).to be(true)
expect(RequestConfirmationCodeJob).to have_received(:perform_later).with(existing_user).once
expect(RequestConfirmationCodeJob).to have_received(:perform_now).with(existing_user).once
end

context 'when the request tries to pass additional changed attributes', document: false do
Expand Down

0 comments on commit 1840e0e

Please sign in to comment.