add specs
This commit is contained in:
parent
d7893b9102
commit
75403ba949
4 changed files with 33 additions and 8 deletions
|
@ -366,11 +366,17 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
|
||||||
|
|
||||||
before { gi_1_2.instructeurs << instructeur }
|
before { gi_1_2.instructeurs << instructeur }
|
||||||
|
|
||||||
context 'of a news instructeurs' do
|
context 'of news instructeurs' do
|
||||||
let(:new_instructeur_emails) { ['new_i1@mail.com', 'new_i2@mail.com'] }
|
let!(:user_email_verified) { create(:user, :with_email_verified) }
|
||||||
|
let!(:instructeur_email_verified) { create(:instructeur, user: user_email_verified) }
|
||||||
|
let(:new_instructeur_emails) { ['new_i1@mail.com', 'new_i2@mail.com', instructeur_email_verified.email] }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(GroupeInstructeurMailer).to receive(:notify_added_instructeurs)
|
allow(GroupeInstructeurMailer).to receive(:notify_added_instructeurs)
|
||||||
.and_return(double(deliver_later: true))
|
.and_return(double(deliver_later: true))
|
||||||
|
|
||||||
|
allow(InstructeurMailer).to receive(:confirm_and_notify_added_instructeur)
|
||||||
|
.and_return(double(deliver_later: true))
|
||||||
do_request
|
do_request
|
||||||
end
|
end
|
||||||
it { expect(gi_1_2.instructeurs.pluck(:email)).to include(*new_instructeur_emails) }
|
it { expect(gi_1_2.instructeurs.pluck(:email)).to include(*new_instructeur_emails) }
|
||||||
|
@ -380,7 +386,21 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
|
||||||
it "calls GroupeInstructeurMailer with the right params" do
|
it "calls GroupeInstructeurMailer with the right params" do
|
||||||
expect(GroupeInstructeurMailer).to have_received(:notify_added_instructeurs).with(
|
expect(GroupeInstructeurMailer).to have_received(:notify_added_instructeurs).with(
|
||||||
gi_1_2,
|
gi_1_2,
|
||||||
gi_1_2.instructeurs.last(2),
|
[instructeur_email_verified],
|
||||||
|
admin.email
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "calls InstructeurMailer with the right params" do
|
||||||
|
expect(InstructeurMailer).to have_received(:confirm_and_notify_added_instructeur).with(
|
||||||
|
User.find_by(email: 'new_i1@mail.com').instructeur,
|
||||||
|
gi_1_2,
|
||||||
|
admin.email
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(InstructeurMailer).to have_received(:confirm_and_notify_added_instructeur).with(
|
||||||
|
User.find_by(email: 'new_i2@mail.com').instructeur,
|
||||||
|
gi_1_2,
|
||||||
admin.email
|
admin.email
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,5 +16,9 @@ FactoryBot.define do
|
||||||
trait :with_fci do
|
trait :with_fci do
|
||||||
france_connect_informations { [association(:france_connect_information)] }
|
france_connect_informations { [association(:france_connect_information)] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :with_email_verified do
|
||||||
|
email_verified_at { Time.zone.now }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -224,13 +224,14 @@ describe User, type: :model do
|
||||||
|
|
||||||
describe '.create_or_promote_to_gestionnaire' do
|
describe '.create_or_promote_to_gestionnaire' do
|
||||||
let(:email) { 'inst1@gmail.com' }
|
let(:email) { 'inst1@gmail.com' }
|
||||||
let(:password) { 'un super password !' }
|
let(:password) { 'un super p1ssw0rd !' }
|
||||||
|
|
||||||
subject { User.create_or_promote_to_gestionnaire(email, password) }
|
subject { User.create_or_promote_to_gestionnaire(email, password) }
|
||||||
|
|
||||||
it 'verifies its email' do
|
it 'creates a gestionnaire with unverified email' do
|
||||||
user = subject
|
user = subject
|
||||||
expect(user.email_verified_at).not_to be_present
|
expect(user.email_verified_at).to be_nil
|
||||||
|
expect(user.reload.gestionnaire?).to be true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -293,8 +293,8 @@ describe 'The routing with rules', js: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
def register_instructeur_and_log_in(email)
|
def register_instructeur_and_log_in(email)
|
||||||
confirmation_email = emails_sent_to(email)
|
confirmation_email = emails_sent_to(email).reverse
|
||||||
.find { |m| m.subject == 'Activez votre compte instructeur' }
|
.find { |m| m.subject.starts_with?('Vous avez été ajouté(e) au groupe') }
|
||||||
token_params = confirmation_email.body.match(/token=[^"]+/)
|
token_params = confirmation_email.body.match(/token=[^"]+/)
|
||||||
|
|
||||||
visit "users/activate?#{token_params}"
|
visit "users/activate?#{token_params}"
|
||||||
|
|
Loading…
Add table
Reference in a new issue