Skip to content

Commit

Permalink
fix spec
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSim committed Dec 13, 2024
1 parent 2a25171 commit 7b02aeb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
47 changes: 32 additions & 15 deletions spec/system/france_connect/france_connect_particulier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let(:birthdate) { '20150821' }
let(:gender) { 'M' }
let(:birthplace) { '1234' }
let(:email) { '[email protected]' }
let(:fc_email) { '[email protected]' }
let(:france_connect_particulier_id) { 'blabla' }

let(:user_info) do
Expand All @@ -18,7 +18,7 @@
birthdate: birthdate,
birthplace: birthplace,
gender: gender,
email_france_connect: email
email_france_connect: fc_email
}
end

Expand All @@ -40,32 +40,49 @@
let(:france_connect_information) { build(:france_connect_information, user_info) }

context 'and no user has the same email' do
before { page.find('.fr-connect').click }
before do
page.find('.fr-connect').click
end

scenario 'he is redirected to user dossiers page' do
scenario 'he is redirected to user dossiers page', js: true do
expect(page).to have_content("Choisissez votre email de contact pour finaliser votre connexion")
find("#use_france_connect_email_no").click
fill_in("email", with: "[email protected]")
page.find("input[type='submit'][name='commit'][value='Confirmer']").click
expect(page).to have_content("Confirmez votre email")
click_on 'Continuer'
expect(User.find_by(email: email)).not_to be nil

find('label', text: "Oui, utiliser #{fc_email} comme email de contact").click

click_on 'Valider'
expect(User.find_by(email: fc_email).email_verified_at).to be_present
end

scenario 'he can choose not to use FranceConnect email and input an alternative email' do
scenario 'he can choose not to use FranceConnect email and input an alternative email', js: true do
alternative_email = '[email protected]'

expect(page).to have_content("Choisissez votre email de contact pour finaliser votre connexion")
find('label', text: 'utiliser une autre adresse').click

expect(page).to have_selector("input[name='email']", visible: true, wait: 10)

fill_in 'email', with: '[email protected]'
click_on 'Confirmer'
fill_in 'email', with: alternative_email
click_on 'Valider'

expect(page).to have_content('Nous venons de vous envoyer le mail de confirmation')
expect(User.find_by(email: alternative_email)).to be_nil

perform_enqueued_jobs

confirmation_email = open_email(alternative_email)
link = confirmation_email.body.match(/href="[^"]*(\/france_connect\/particulier\/merge_using_email_link.*?)"/)[1]

visit link

expect(page).to have_content('Les comptes FranceConnect et demarches-simplifiees.fr sont à présent fusionnés')
expect(page).to have_content(alternative_email)

expect(page).to have_content("Confirmez votre email")
expect(User.find_by(email: alternative_email).email_verified_at).to be_present
end
end

context 'and an user exists with the same email' do
let!(:user) { create(:user, email: email, password: SECURE_PASSWORD) }
let!(:user) { create(:user, email: fc_email, password: SECURE_PASSWORD) }

before do
page.find('.fr-connect').click
Expand Down
10 changes: 4 additions & 6 deletions spec/system/users/dossier_prefill_get_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,10 @@
page.find('.fr-connect').click

expect(page).to have_content("Choisissez votre email de contact pour finaliser votre connexion")
expect(page).to have_selector("#use_france_connect_email_no", visible: false, wait: 10)
page.execute_script('document.getElementById("use_france_connect_email_no").click()')
fill_in("email", with: "[email protected]")
page.find("input[type='submit'][name='commit'][value='Confirmer']").click
expect(page).to have_content("Confirmez votre email")
click_on 'Continuer'

find('label', text: /Oui, utiliser .* comme email de contact/).click

click_on 'Valider'
expect(page).to have_content('Vous avez un dossier prérempli')
find('.fr-btn.fr-mb-2w', text: 'Poursuivre mon dossier prérempli', wait: 10).click
end
Expand Down
8 changes: 3 additions & 5 deletions spec/system/users/dossier_prefill_post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,10 @@

page.find('.fr-connect').click
expect(page).to have_content("Choisissez votre email de contact pour finaliser votre connexion")
expect(page).to have_selector("#use_france_connect_email_yes", visible: false, wait: 10)
page.execute_script('document.getElementById("use_france_connect_email_yes").click()')

click_on 'Confirmer'
expect(page).to have_content("Confirmez votre email")
click_on 'Continuer'
find('label', text: /Oui, utiliser .* comme email de contact/).click

click_on 'Valider'
expect(page).to have_content('Vous avez un dossier prérempli')
find('.fr-btn.fr-mb-2w', text: 'Poursuivre mon dossier prérempli', wait: 10).click
end
Expand Down

0 comments on commit 7b02aeb

Please sign in to comment.