2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-10-26 09:44:53 +00:00
|
|
|
describe 'France Connect Particulier Connexion' do
|
2015-12-24 10:12:23 +01:00
|
|
|
let(:code) { 'plop' }
|
|
|
|
let(:given_name) { 'titi' }
|
|
|
|
let(:family_name) { 'toto' }
|
|
|
|
let(:birthdate) { '20150821' }
|
|
|
|
let(:gender) { 'M' }
|
|
|
|
let(:birthplace) { '1234' }
|
2024-11-26 10:18:55 +01:00
|
|
|
let(:fc_email) { 'plop@plop.com' }
|
2016-01-21 17:06:09 +01:00
|
|
|
let(:france_connect_particulier_id) { 'blabla' }
|
2015-12-24 10:12:23 +01:00
|
|
|
|
2018-01-11 14:04:24 +01:00
|
|
|
let(:user_info) do
|
|
|
|
{
|
|
|
|
france_connect_particulier_id: france_connect_particulier_id,
|
|
|
|
given_name: given_name,
|
|
|
|
family_name: family_name,
|
|
|
|
birthdate: birthdate,
|
|
|
|
birthplace: birthplace,
|
|
|
|
gender: gender,
|
2024-11-26 10:18:55 +01:00
|
|
|
email_france_connect: fc_email
|
2018-01-11 14:04:24 +01:00
|
|
|
}
|
|
|
|
end
|
2015-12-24 10:12:23 +01:00
|
|
|
|
|
|
|
context 'when user is on login page' do
|
2021-10-06 16:30:51 +02:00
|
|
|
before { visit new_user_session_path }
|
2015-12-24 10:12:23 +01:00
|
|
|
|
|
|
|
scenario 'link to France Connect is present' do
|
2022-09-20 17:33:52 +02:00
|
|
|
expect(page).to have_css('.fr-connect')
|
2015-12-24 10:12:23 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'and click on france connect link' do
|
|
|
|
context 'when authentification is ok' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(FranceConnectParticulierClient).to receive(:authorization_uri).and_return(france_connect_particulier_callback_path(code: code))
|
2021-04-26 16:25:33 +02:00
|
|
|
allow(FranceConnectService).to receive(:retrieve_user_informations_particulier).and_return(france_connect_information)
|
2015-12-24 10:12:23 +01:00
|
|
|
end
|
|
|
|
|
2021-10-13 16:51:00 +02:00
|
|
|
context 'when no user is linked' do
|
2021-10-06 16:30:51 +02:00
|
|
|
let(:france_connect_information) { build(:france_connect_information, user_info) }
|
2021-04-26 16:25:33 +02:00
|
|
|
|
2021-10-13 16:51:00 +02:00
|
|
|
context 'and no user has the same email' do
|
2024-11-26 10:18:55 +01:00
|
|
|
before do
|
|
|
|
page.find('.fr-connect').click
|
|
|
|
end
|
2015-12-24 10:12:23 +01:00
|
|
|
|
2024-11-26 10:18:55 +01:00
|
|
|
scenario 'he is redirected to user dossiers page', js: true do
|
2024-08-22 21:36:16 +00:00
|
|
|
expect(page).to have_content("Choisissez votre email de contact pour finaliser votre connexion")
|
2024-11-26 10:18:55 +01:00
|
|
|
|
|
|
|
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
|
2021-10-13 16:51:00 +02:00
|
|
|
end
|
2024-07-04 10:47:53 +00:00
|
|
|
|
2024-11-26 10:18:55 +01:00
|
|
|
scenario 'he can choose not to use FranceConnect email and input an alternative email', js: true do
|
|
|
|
alternative_email = 'alternative@example.com'
|
|
|
|
|
2024-08-22 21:36:16 +00:00
|
|
|
expect(page).to have_content("Choisissez votre email de contact pour finaliser votre connexion")
|
2024-11-26 10:18:55 +01:00
|
|
|
find('label', text: 'utiliser une autre adresse').click
|
2024-07-04 10:47:53 +00:00
|
|
|
|
2024-07-31 17:50:14 +02:00
|
|
|
expect(page).to have_selector("input[name='email']", visible: true, wait: 10)
|
2024-07-04 10:47:53 +00:00
|
|
|
|
2024-11-26 10:18:55 +01:00
|
|
|
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)
|
2024-07-31 17:50:14 +02:00
|
|
|
|
2024-11-26 10:18:55 +01:00
|
|
|
expect(User.find_by(email: alternative_email).email_verified_at).to be_present
|
2024-07-04 10:47:53 +00:00
|
|
|
end
|
2021-10-13 16:51:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'and an user exists with the same email' do
|
2024-11-26 10:18:55 +01:00
|
|
|
let!(:user) { create(:user, email: fc_email, password: SECURE_PASSWORD) }
|
2021-10-13 16:51:00 +02:00
|
|
|
|
|
|
|
before do
|
2022-09-20 17:33:52 +02:00
|
|
|
page.find('.fr-connect').click
|
2021-10-13 16:51:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'he is redirected to the merge page' do
|
|
|
|
expect(page).to have_content('Fusion des comptes')
|
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'it merges its account' do
|
|
|
|
page.find('#it-is-mine').click
|
2023-03-03 03:16:15 -10:00
|
|
|
fill_in 'password', with: SECURE_PASSWORD
|
2021-10-13 16:51:00 +02:00
|
|
|
click_on 'Fusionner les comptes'
|
|
|
|
|
|
|
|
expect(page).to have_content('Dossiers')
|
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'it uses another email that belongs to nobody' do
|
|
|
|
page.find('#it-is-not-mine').click
|
|
|
|
fill_in 'email', with: 'new_email@a.com'
|
|
|
|
click_on 'Utiliser ce mail'
|
|
|
|
|
2024-07-31 17:50:14 +02:00
|
|
|
expect(page).to have_content('Nous venons de vous envoyer le mail de confirmation')
|
2021-10-13 16:51:00 +02:00
|
|
|
end
|
|
|
|
|
2023-11-06 15:15:51 +01:00
|
|
|
context 'and the user wants an email that belongs to another account', js: true do
|
2023-03-03 03:16:15 -10:00
|
|
|
let!(:another_user) { create(:user, email: 'an_existing_email@a.com', password: SECURE_PASSWORD) }
|
2021-10-13 16:51:00 +02:00
|
|
|
|
|
|
|
scenario 'it uses another email that belongs to another account' do
|
2024-07-04 10:47:53 +00:00
|
|
|
find('label[for="it-is-not-mine"]').click
|
2021-10-13 16:51:00 +02:00
|
|
|
|
2024-07-04 10:47:53 +00:00
|
|
|
expect(page).to have_css('.new-account', visible: true)
|
2021-10-13 16:51:00 +02:00
|
|
|
|
2024-07-04 10:47:53 +00:00
|
|
|
within '.new-account' do
|
|
|
|
fill_in 'email', with: 'an_existing_email@a.com'
|
|
|
|
click_on 'Utiliser ce mail'
|
2021-10-13 16:51:00 +02:00
|
|
|
end
|
|
|
|
|
2024-07-31 17:50:14 +02:00
|
|
|
expect(page).to have_content('Nous venons de vous envoyer le mail de confirmation')
|
2021-10-13 16:51:00 +02:00
|
|
|
end
|
|
|
|
end
|
2015-12-24 10:12:23 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-10-13 16:51:00 +02:00
|
|
|
context 'when a user is linked' do
|
2021-04-26 16:25:33 +02:00
|
|
|
let!(:france_connect_information) do
|
2021-10-06 16:30:51 +02:00
|
|
|
create(:france_connect_information, :with_user, user_info.merge(created_at: Time.zone.parse('12/12/2012'), updated_at: Time.zone.parse('12/12/2012')))
|
2021-04-26 16:25:33 +02:00
|
|
|
end
|
|
|
|
|
2022-09-20 17:33:52 +02:00
|
|
|
before { page.find('.fr-connect').click }
|
2015-12-24 10:12:23 +01:00
|
|
|
|
|
|
|
scenario 'he is redirected to user dossiers page' do
|
2016-12-13 16:10:03 +01:00
|
|
|
expect(page).to have_content('Dossiers')
|
2015-12-24 10:12:23 +01:00
|
|
|
end
|
2020-11-02 11:37:21 +01:00
|
|
|
|
|
|
|
scenario 'the updated_at date is well updated' do
|
2021-04-26 16:26:09 +02:00
|
|
|
expect(france_connect_information.reload.updated_at).not_to eq(france_connect_information.created_at)
|
2020-11-02 11:37:21 +01:00
|
|
|
end
|
2015-12-24 10:12:23 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authentification is not ok' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(FranceConnectParticulierClient).to receive(:authorization_uri).and_return(france_connect_particulier_callback_path(code: code))
|
|
|
|
allow(FranceConnectService).to receive(:retrieve_user_informations_particulier) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') }
|
2022-09-20 17:33:52 +02:00
|
|
|
page.find('.fr-connect').click
|
2015-12-24 10:12:23 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'he is redirected to login page' do
|
2022-09-20 17:33:52 +02:00
|
|
|
expect(page).to have_css('.fr-connect')
|
2015-12-24 10:12:23 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'error message is displayed' do
|
|
|
|
expect(page).to have_content(I18n.t('errors.messages.france_connect.connexion'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-12-13 16:10:03 +01:00
|
|
|
end
|