2018-01-17 10:28:59 +01:00
|
|
|
describe Manager::AdministrateursController, type: :controller do
|
2018-12-24 17:28:20 +01:00
|
|
|
let(:administration) { create(:administration) }
|
2018-01-17 10:28:59 +01:00
|
|
|
|
|
|
|
describe 'POST #create' do
|
|
|
|
let(:email) { 'plop@plop.com' }
|
2019-06-20 00:36:50 +02:00
|
|
|
let(:password) { 'démarches-simplifiées-pwd' }
|
2018-01-17 10:28:59 +01:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in administration
|
|
|
|
end
|
|
|
|
|
2018-01-23 18:16:44 +01:00
|
|
|
subject { post :create, params: { administrateur: { email: email } } }
|
2018-01-17 10:28:59 +01:00
|
|
|
|
|
|
|
context 'when email and password are correct' do
|
|
|
|
it 'add new administrateur in database' do
|
|
|
|
expect { subject }.to change(Administrateur, :count).by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'alert new mail are send' do
|
|
|
|
expect(AdministrationMailer).to receive(:new_admin_email).and_return(AdministrationMailer)
|
2018-05-25 18:05:28 +02:00
|
|
|
expect(AdministrationMailer).to receive(:deliver_later)
|
2018-01-17 10:28:59 +01:00
|
|
|
expect(AdministrationMailer).to receive(:invite_admin).and_return(AdministrationMailer)
|
2018-05-25 18:05:28 +02:00
|
|
|
expect(AdministrationMailer).to receive(:deliver_later)
|
2018-01-17 10:28:59 +01:00
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when email or password are missing' do
|
|
|
|
let(:email) { '' }
|
|
|
|
|
|
|
|
it { expect { subject }.to change(Administrateur, :count).by(0) }
|
|
|
|
end
|
|
|
|
end
|
2019-08-19 10:47:37 +02:00
|
|
|
|
|
|
|
describe '#delete' do
|
|
|
|
let!(:admin) { create(:administrateur) }
|
|
|
|
|
|
|
|
before { sign_in administration }
|
|
|
|
|
|
|
|
subject { delete :delete, params: { id: admin.id } }
|
|
|
|
|
|
|
|
it 'deletes the admin' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(Administrateur.find_by(id: admin.id)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2018-01-17 10:28:59 +01:00
|
|
|
end
|