2015-12-15 15:17:12 +01:00
|
|
|
describe Users::RegistrationsController, type: :controller do
|
|
|
|
let(:email) { 'test@octo.com' }
|
2023-03-03 14:16:15 +01:00
|
|
|
let(:password) { SECURE_PASSWORD }
|
2015-12-15 15:17:12 +01:00
|
|
|
|
2017-06-21 14:20:22 +02:00
|
|
|
let(:user) { { email: email, password: password } }
|
2015-12-15 15:17:12 +01:00
|
|
|
|
|
|
|
before do
|
|
|
|
@request.env["devise.mapping"] = Devise.mappings[:user]
|
|
|
|
end
|
|
|
|
|
2018-09-18 16:54:37 +02:00
|
|
|
describe '#new' do
|
2019-01-14 16:26:53 +01:00
|
|
|
subject { get :new }
|
2018-09-18 16:54:37 +02:00
|
|
|
|
2019-01-14 16:26:53 +01:00
|
|
|
it { expect(subject).to have_http_status(:ok) }
|
|
|
|
it { expect(subject).to render_template(:new) }
|
2018-09-18 16:54:37 +02:00
|
|
|
|
|
|
|
context 'when an email address is provided' do
|
|
|
|
render_views true
|
2019-01-14 16:26:53 +01:00
|
|
|
subject { get :new, params: { user: { email: 'test@exemple.fr' } } }
|
2018-09-18 16:54:37 +02:00
|
|
|
|
|
|
|
it 'prefills the form with the email address' do
|
2019-01-14 16:26:53 +01:00
|
|
|
expect(subject.body).to include('test@exemple.fr')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a procedure location has been stored' do
|
|
|
|
let(:procedure) { create :procedure, :published }
|
|
|
|
|
|
|
|
before do
|
2019-01-16 16:16:15 +01:00
|
|
|
controller.store_location_for(:user, commencer_path(path: procedure.path))
|
2019-01-14 16:26:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'makes the saved procedure available' do
|
|
|
|
expect(subject.status).to eq 200
|
|
|
|
expect(assigns(:procedure)).to eq procedure
|
2018-09-18 16:54:37 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-20 16:00:30 +01:00
|
|
|
describe '#create' do
|
2018-05-22 17:11:48 +02:00
|
|
|
subject do
|
|
|
|
post :create, params: { user: user }
|
|
|
|
end
|
2015-12-15 15:17:12 +01:00
|
|
|
|
2024-03-20 12:56:11 +01:00
|
|
|
before do
|
|
|
|
allow(Current).to receive(:host).and_return(ENV.fetch("APP_HOST"))
|
|
|
|
end
|
|
|
|
|
2016-01-04 16:09:04 +01:00
|
|
|
context 'when user is correct' do
|
2018-05-22 17:11:48 +02:00
|
|
|
it 'sends confirmation instruction' do
|
2018-05-26 00:06:40 +02:00
|
|
|
message = double()
|
|
|
|
expect(DeviseUserMailer).to receive(:confirmation_instructions).and_return(message)
|
|
|
|
expect(message).to receive(:deliver_later)
|
2015-12-15 15:17:12 +01:00
|
|
|
|
2016-01-04 16:09:04 +01:00
|
|
|
subject
|
2024-03-20 12:56:11 +01:00
|
|
|
|
2024-04-05 15:15:40 +02:00
|
|
|
# expect(User.last.preferred_domain_demarches_gouv_fr?).to be_truthy
|
2016-01-04 16:09:04 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not correct' do
|
2017-06-21 14:20:22 +02:00
|
|
|
let(:user) { { email: '', password: password } }
|
2016-01-04 16:09:04 +01:00
|
|
|
|
2018-05-22 17:11:48 +02:00
|
|
|
it 'not sends confirmation instruction' do
|
|
|
|
expect(DeviseUserMailer).not_to receive(:confirmation_instructions)
|
2016-01-04 16:09:04 +01:00
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
2015-12-15 15:17:12 +01:00
|
|
|
end
|
2018-05-23 11:27:33 +02:00
|
|
|
|
|
|
|
context 'when the user already exists' do
|
2018-06-20 13:30:32 +02:00
|
|
|
let!(:existing_user) { create(:user, email: email, password: password, confirmed_at: confirmed_at) }
|
2018-05-23 11:27:33 +02:00
|
|
|
|
|
|
|
before do
|
2018-06-07 15:07:14 +02:00
|
|
|
allow(UserMailer).to receive(:new_account_warning).and_return(double(deliver_later: 'deliver'))
|
2018-05-23 11:27:33 +02:00
|
|
|
end
|
|
|
|
|
2018-06-20 13:30:32 +02:00
|
|
|
context 'and the user is confirmed' do
|
2018-10-25 15:07:15 +02:00
|
|
|
let(:confirmed_at) { Time.zone.now }
|
2018-06-20 13:30:32 +02:00
|
|
|
|
|
|
|
before { subject }
|
|
|
|
|
2019-05-13 11:57:01 +02:00
|
|
|
it 'sends an email to the user, stating that the account already exists' do
|
|
|
|
expect(UserMailer).to have_received(:new_account_warning)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'avoids leaking information about the account existence, by redirecting to the same page than normal signup' do
|
|
|
|
expect(response).to redirect_to(new_user_confirmation_path(user: { email: user[:email] }))
|
|
|
|
end
|
2018-06-20 13:30:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'and the user is not confirmed' do
|
|
|
|
let(:confirmed_at) { nil }
|
|
|
|
|
|
|
|
before do
|
|
|
|
expect_any_instance_of(User).to receive(:resend_confirmation_instructions)
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
2019-05-13 11:57:01 +02:00
|
|
|
it 'does not send a warning email' do
|
|
|
|
expect(UserMailer).not_to have_received(:new_account_warning)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'avoids leaking information about the account existence, by redirecting to the same page than normal signup' do
|
|
|
|
expect(response).to redirect_to(new_user_confirmation_path(user: { email: user[:email] }))
|
|
|
|
end
|
2018-06-20 13:30:32 +02:00
|
|
|
end
|
2018-05-23 11:27:33 +02:00
|
|
|
end
|
2015-12-15 15:17:12 +01:00
|
|
|
end
|
|
|
|
end
|