2015-08-10 11:05:06 +02:00
|
|
|
module FeatureHelpers
|
2018-11-06 11:22:17 +01:00
|
|
|
include ActiveJob::TestHelper
|
|
|
|
|
2015-08-10 11:05:06 +02:00
|
|
|
def login_admin
|
2015-08-13 15:55:19 +02:00
|
|
|
user = create :user
|
2015-08-10 11:05:06 +02:00
|
|
|
login_as user, scope: :user
|
|
|
|
user
|
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
def login_instructeur
|
|
|
|
instructeur = create(:instructeur)
|
|
|
|
login_as instructeur, scope: :instructeur
|
2015-09-22 10:15:12 +02:00
|
|
|
end
|
|
|
|
|
2015-08-10 11:05:06 +02:00
|
|
|
def create_dossier
|
2018-01-23 17:15:42 +01:00
|
|
|
dossier = FactoryBot.create(:dossier)
|
2015-08-10 11:05:06 +02:00
|
|
|
dossier
|
|
|
|
end
|
2018-11-06 17:06:45 +01:00
|
|
|
|
2018-10-03 11:11:02 +02:00
|
|
|
def sign_in_with(email, password, sign_in_by_link = false)
|
2018-11-06 17:06:45 +01:00
|
|
|
fill_in :user_email, with: email
|
|
|
|
fill_in :user_password, with: password
|
2018-10-03 11:11:02 +02:00
|
|
|
|
2019-07-31 15:04:49 +02:00
|
|
|
if sign_in_by_link
|
|
|
|
Flipflop::FeatureSet.current.test!.switch!(:bypass_email_login_token, false)
|
|
|
|
end
|
|
|
|
|
2018-10-03 11:11:02 +02:00
|
|
|
perform_enqueued_jobs do
|
|
|
|
click_on 'Se connecter'
|
|
|
|
end
|
|
|
|
|
|
|
|
if sign_in_by_link
|
|
|
|
mail = ActionMailer::Base.deliveries.last
|
2018-12-26 17:35:28 +01:00
|
|
|
message = mail.html_part.body.raw_source
|
2019-08-06 11:02:54 +02:00
|
|
|
instructeur_id = message[/\".+\/connexion-par-jeton\/(.+)\?jeton=(.*)\"/, 1]
|
2018-12-26 17:35:28 +01:00
|
|
|
jeton = message[/\".+\/connexion-par-jeton\/(.+)\?jeton=(.*)\"/, 2]
|
2018-10-03 11:11:02 +02:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
visit sign_in_by_link_path(instructeur_id, jeton: jeton)
|
2018-10-03 11:11:02 +02:00
|
|
|
end
|
2018-11-06 17:06:45 +01:00
|
|
|
end
|
2018-11-06 11:22:17 +01:00
|
|
|
|
2019-06-20 00:36:50 +02:00
|
|
|
def sign_up_with(email, password = 'démarches-simplifiées-pwd')
|
2018-11-06 11:22:17 +01:00
|
|
|
fill_in :user_email, with: email
|
|
|
|
fill_in :user_password, with: password
|
|
|
|
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
click_button 'Créer un compte'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def click_confirmation_link_for(email)
|
|
|
|
confirmation_email = open_email(email)
|
|
|
|
token_params = confirmation_email.body.match(/confirmation_token=[^"]+/)
|
|
|
|
|
|
|
|
visit "/users/confirmation?#{token_params}"
|
|
|
|
end
|
2019-01-14 16:26:53 +01:00
|
|
|
|
|
|
|
def expect_page_to_have_procedure_description(procedure)
|
|
|
|
# Procedure context on the page
|
|
|
|
expect(page).to have_content(procedure.libelle)
|
|
|
|
expect(page).to have_content(procedure.description)
|
|
|
|
# Procedure contact infos in the footer
|
|
|
|
expect(page).to have_content(procedure.service.email)
|
|
|
|
end
|
2019-02-06 18:19:27 +01:00
|
|
|
|
|
|
|
def blur
|
|
|
|
page.find('body').click
|
|
|
|
end
|
2019-06-04 15:06:59 +02:00
|
|
|
|
|
|
|
def pause
|
|
|
|
$stderr.write 'Spec paused. Press enter to continue:'
|
|
|
|
$stdin.gets
|
|
|
|
end
|
2019-06-04 16:17:21 +02:00
|
|
|
|
|
|
|
def wait_until
|
|
|
|
Timeout.timeout(Capybara.default_max_wait_time) do
|
|
|
|
sleep(0.1) until (value = yield)
|
|
|
|
value
|
|
|
|
end
|
|
|
|
end
|
2019-08-14 17:26:47 +02:00
|
|
|
|
|
|
|
def click_reset_password_link_for(email)
|
|
|
|
reset_password_email = open_email(email)
|
|
|
|
token_params = reset_password_email.body.match(/reset_password_token=[^"]+/)
|
|
|
|
|
|
|
|
visit "/users/password/edit?#{token_params}"
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
|
|
|
config.include FeatureHelpers, type: :feature
|
2015-08-20 17:30:17 +02:00
|
|
|
end
|