demarches-normaliennes/spec/controllers/backoffice/dossiers_controller_spec.rb

244 lines
5.6 KiB
Ruby
Raw Normal View History

2015-09-22 15:00:59 +02:00
require 'rails_helper'
describe Backoffice::DossiersController, type: :controller do
before do
2016-09-01 10:27:22 +02:00
@request.env['HTTP_REFERER'] = TPS::Application::URL
end
2016-01-18 17:18:04 +01:00
let(:dossier) { create(:dossier, :with_entreprise) }
let(:dossier_archived) { create(:dossier, :with_entreprise, archived: true) }
2015-09-22 15:00:59 +02:00
let(:dossier_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 10 }
let(:gestionnaire) { create(:gestionnaire, administrateurs: [create(:administrateur)]) }
2015-09-22 15:00:59 +02:00
describe 'GET #show' do
2015-11-02 16:36:52 +01:00
context 'gestionnaire is connected' do
2015-09-22 15:00:59 +02:00
before do
sign_in gestionnaire
end
it 'returns http success' do
get :show, id: dossier_id
expect(response).to have_http_status(200)
end
2015-12-02 18:17:47 +01:00
context ' when dossier is archived' do
before do
get :show, id: dossier_archived.id
end
it { expect(response).to redirect_to('/backoffice') }
end
2015-12-02 18:17:47 +01:00
context 'when dossier id does not exist' do
before do
get :show, id: bad_dossier_id
end
it { expect(response).to redirect_to('/backoffice') }
2015-09-22 15:00:59 +02:00
end
end
2015-12-02 18:17:47 +01:00
context 'gestionnaire does not connected but dossier id is correct' do
2015-09-22 15:00:59 +02:00
subject { get :show, id: dossier_id }
2015-12-02 18:17:47 +01:00
2015-09-22 15:00:59 +02:00
it { is_expected.to redirect_to('/gestionnaires/sign_in') }
end
end
describe 'GET #a_traiter' do
context 'when gestionnaire is connected' do
before do
sign_in gestionnaire
end
it 'returns http success' do
get :index, liste: :a_traiter
expect(response).to have_http_status(200)
end
end
end
describe 'GET #en_attente' do
context 'when gestionnaire is connected' do
before do
sign_in gestionnaire
end
it 'returns http success' do
get :index, liste: :en_attente
expect(response).to have_http_status(200)
end
end
end
describe 'GET #termine' do
context 'when gestionnaire is connected' do
before do
sign_in gestionnaire
end
it 'returns http success' do
get :index, liste: :termine
expect(response).to have_http_status(200)
end
end
end
describe 'POST #search' do
before do
sign_in gestionnaire
end
it 'returns http success' do
post :search, search_terms: 'test'
expect(response).to have_http_status(200)
end
end
describe 'POST #valid' do
2015-11-02 16:36:52 +01:00
before do
dossier.initiated!
sign_in gestionnaire
end
subject { post :valid, dossier_id: dossier_id }
2015-12-02 18:17:47 +01:00
it 'change state to validated' do
subject
2015-11-02 16:36:52 +01:00
dossier.reload
expect(dossier.state).to eq('validated')
end
it 'Notification email is send' do
expect(NotificationMailer).to receive(:dossier_validated).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
subject
end
end
describe 'POST #receive' do
2015-11-02 16:36:52 +01:00
before do
dossier.submitted!
sign_in gestionnaire
end
2016-09-01 10:27:22 +02:00
subject { post :receive, dossier_id: dossier_id }
2016-09-01 10:27:22 +02:00
context 'when it post a receive instruction' do
before do
subject
dossier.reload
end
it 'change state to received' do
expect(dossier.state).to eq('received')
end
end
it 'Notification email is send' do
expect(NotificationMailer).to receive(:dossier_received).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
subject
end
end
describe 'POST #refuse' do
before do
dossier.refused!
sign_in gestionnaire
end
subject { post :refuse, dossier_id: dossier_id }
it 'change state to refused' do
subject
dossier.reload
expect(dossier.state).to eq('refused')
end
it 'Notification email is sent' do
expect(NotificationMailer).to receive(:dossier_refused).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
subject
end
end
describe 'POST #without_continuation' do
before do
dossier.without_continuation!
sign_in gestionnaire
end
subject { post :without_continuation, dossier_id: dossier_id }
it 'change state to without_continuation' do
subject
dossier.reload
expect(dossier.state).to eq('without_continuation')
end
it 'Notification email is sent' do
expect(NotificationMailer).to receive(:dossier_without_continuation).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
subject
end
end
describe 'POST #close' do
before do
dossier.received!
sign_in gestionnaire
end
subject { post :close, dossier_id: dossier_id }
2015-12-02 18:17:47 +01:00
it 'change state to closed' do
subject
2015-11-02 16:36:52 +01:00
dossier.reload
expect(dossier.state).to eq('closed')
end
it 'Notification email is sent' do
expect(NotificationMailer).to receive(:dossier_closed).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
subject
end
end
describe 'PUT #toggle_follow' do
before do
sign_in gestionnaire
end
subject { put :follow, dossier_id: dossier_id }
it { expect(subject.status).to eq 302 }
describe 'flash alert' do
context 'when dossier is not follow by gestionnaire' do
before do
subject
end
it { expect(flash[:notice]).to have_content 'Dossier suivi' }
end
context 'when dossier is follow by gestionnaire' do
before do
create :follow, gestionnaire_id: gestionnaire.id, dossier_id: dossier.id
subject
end
it { expect(flash[:notice]).to have_content 'Dossier relaché' }
end
end
end
2015-09-22 15:00:59 +02:00
end