2016-11-14 18:36:09 +01:00
|
|
|
require 'spec_helper'
|
2015-09-22 15:00:59 +02:00
|
|
|
|
|
|
|
describe Backoffice::DossiersController, type: :controller do
|
2016-07-19 16:10:50 +02:00
|
|
|
before do
|
2016-09-01 10:27:22 +02:00
|
|
|
@request.env['HTTP_REFERER'] = TPS::Application::URL
|
2016-07-19 16:10:50 +02:00
|
|
|
end
|
2016-09-09 15:55:03 +02:00
|
|
|
let(:procedure) { create :procedure }
|
2016-07-19 16:10:50 +02:00
|
|
|
|
2016-12-01 18:05:49 +01:00
|
|
|
let(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: :initiated) }
|
2016-07-18 18:24:29 +02:00
|
|
|
let(:dossier_archived) { create(:dossier, :with_entreprise, archived: true) }
|
2015-11-27 15:09:16 +01:00
|
|
|
|
2015-09-22 15:00:59 +02:00
|
|
|
let(:dossier_id) { dossier.id }
|
|
|
|
let(:bad_dossier_id) { Dossier.count + 10 }
|
2016-05-20 15:39:17 +02:00
|
|
|
let(:gestionnaire) { create(:gestionnaire, administrateurs: [create(:administrateur)]) }
|
2015-09-22 15:00:59 +02:00
|
|
|
|
2016-09-09 15:55:03 +02:00
|
|
|
before do
|
|
|
|
create :assign_to, procedure: procedure, gestionnaire: gestionnaire
|
|
|
|
end
|
|
|
|
|
2016-12-14 18:41:33 +01:00
|
|
|
describe 'GET #index' do
|
|
|
|
subject { get :index }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gestionnaire is assign to a procedure' do
|
|
|
|
it { is_expected.to redirect_to backoffice_dossiers_procedure_path(id: procedure.id) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gestionnaire is not assign to a procedure' do
|
|
|
|
before do
|
|
|
|
AssignTo.where(procedure: procedure, gestionnaire: gestionnaire).delete_all
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to redirect_to root_path }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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
|
2016-11-15 04:50:18 +01:00
|
|
|
get :show, params: {id: dossier_id}
|
2015-09-22 15:00:59 +02:00
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
|
2015-12-02 18:17:47 +01:00
|
|
|
context ' when dossier is archived' do
|
|
|
|
before do
|
2016-11-15 04:50:18 +01:00
|
|
|
get :show, params: {id: dossier_archived.id}
|
2015-12-02 18:17:47 +01:00
|
|
|
end
|
|
|
|
it { expect(response).to redirect_to('/backoffice') }
|
2015-11-27 15:09:16 +01:00
|
|
|
end
|
|
|
|
|
2015-12-02 18:17:47 +01:00
|
|
|
context 'when dossier id does not exist' do
|
|
|
|
before do
|
2016-11-15 04:50:18 +01:00
|
|
|
get :show, params: {id: bad_dossier_id}
|
2015-12-02 18:17:47 +01:00
|
|
|
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
|
2016-11-15 04:50:18 +01:00
|
|
|
subject { get :show, params: {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
|
2015-09-24 16:51:14 +02:00
|
|
|
|
2015-11-13 15:23:21 +01:00
|
|
|
describe 'GET #a_traiter' do
|
|
|
|
context 'when gestionnaire is connected' do
|
|
|
|
before do
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
2016-11-15 04:50:18 +01:00
|
|
|
get :index, params: {liste: :a_traiter}
|
2016-12-01 18:05:49 +01:00
|
|
|
expect(response).to have_http_status(302)
|
2015-11-13 15:23:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-10 15:57:14 +01:00
|
|
|
describe 'GET #fige' do
|
2015-11-13 15:23:21 +01:00
|
|
|
context 'when gestionnaire is connected' do
|
|
|
|
before do
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
2016-11-15 04:50:18 +01:00
|
|
|
get :index, params: {liste: :fige}
|
2016-12-01 18:05:49 +01:00
|
|
|
expect(response).to have_http_status(302)
|
2015-11-13 15:23:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #termine' do
|
|
|
|
context 'when gestionnaire is connected' do
|
|
|
|
before do
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
2016-11-15 04:50:18 +01:00
|
|
|
get :index, params: {liste: :termine}
|
2016-12-01 18:05:49 +01:00
|
|
|
expect(response).to have_http_status(302)
|
2015-11-13 15:23:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-07 16:01:32 +02:00
|
|
|
describe 'GET #list_fake' do
|
|
|
|
context 'when gestionnaire is connected' do
|
|
|
|
before do
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
2016-11-15 04:50:18 +01:00
|
|
|
get :index, params: {liste: :list_fake}
|
2016-12-01 18:05:49 +01:00
|
|
|
expect(response).to redirect_to(backoffice_dossiers_procedure_path(id: gestionnaire.procedures.first.id))
|
2016-10-07 16:01:32 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-17 18:21:03 +01:00
|
|
|
describe 'POST #search' do
|
|
|
|
before do
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
2016-11-15 04:50:18 +01:00
|
|
|
post :search, params: {search_terms: 'test'}
|
2015-11-17 18:21:03 +01:00
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-11-02 11:45:52 +01:00
|
|
|
describe 'POST #valid' do
|
2015-11-02 16:36:52 +01:00
|
|
|
before do
|
|
|
|
dossier.initiated!
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
2015-09-24 16:51:14 +02:00
|
|
|
|
2016-11-15 04:50:18 +01:00
|
|
|
subject { post :valid, params: {dossier_id: dossier_id} }
|
2015-12-15 15:37:46 +01:00
|
|
|
|
2015-12-02 18:17:47 +01:00
|
|
|
it 'change state to validated' do
|
2015-12-15 15:37:46 +01:00
|
|
|
subject
|
2015-09-24 16:51:14 +02:00
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
dossier.reload
|
|
|
|
expect(dossier.state).to eq('validated')
|
2015-09-24 16:51:14 +02:00
|
|
|
end
|
2015-12-15 15:37:46 +01:00
|
|
|
|
|
|
|
it 'Notification email is send' do
|
|
|
|
expect(NotificationMailer).to receive(:dossier_validated).and_return(NotificationMailer)
|
|
|
|
expect(NotificationMailer).to receive(:deliver_now!)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
2015-09-24 16:51:14 +02:00
|
|
|
end
|
2015-10-09 12:05:07 +02:00
|
|
|
|
2016-08-25 15:21:25 +02:00
|
|
|
describe 'POST #receive' do
|
2015-11-02 16:36:52 +01:00
|
|
|
before do
|
|
|
|
dossier.submitted!
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
2015-10-09 12:05:07 +02:00
|
|
|
|
2016-11-15 04:50:18 +01:00
|
|
|
subject { post :receive, params: {dossier_id: dossier_id} }
|
2016-08-25 15:21:25 +02:00
|
|
|
|
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
|
2016-08-25 15:21:25 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-25 18:02:56 +02:00
|
|
|
describe 'POST #refuse' do
|
|
|
|
before do
|
|
|
|
dossier.refused!
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
|
|
|
|
2016-11-15 04:50:18 +01:00
|
|
|
subject { post :refuse, params: {dossier_id: dossier_id} }
|
2016-08-25 18:02:56 +02:00
|
|
|
|
|
|
|
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
|
2016-11-15 04:50:18 +01:00
|
|
|
subject { post :without_continuation, params: {dossier_id: dossier_id} }
|
2016-08-25 18:02:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-08-25 15:21:25 +02:00
|
|
|
describe 'POST #close' do
|
|
|
|
before do
|
|
|
|
dossier.received!
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
2016-11-15 04:50:18 +01:00
|
|
|
subject { post :close, params: {dossier_id: dossier_id} }
|
2016-08-25 15:21:25 +02:00
|
|
|
|
2015-12-02 18:17:47 +01:00
|
|
|
it 'change state to closed' do
|
2016-08-25 18:02:56 +02:00
|
|
|
subject
|
2015-10-09 12:05:07 +02:00
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
dossier.reload
|
|
|
|
expect(dossier.state).to eq('closed')
|
2015-10-09 12:05:07 +02:00
|
|
|
end
|
2016-08-25 18:02:56 +02:00
|
|
|
|
|
|
|
it 'Notification email is sent' do
|
|
|
|
expect(NotificationMailer).to receive(:dossier_closed).and_return(NotificationMailer)
|
|
|
|
expect(NotificationMailer).to receive(:deliver_now!)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
2015-10-09 12:05:07 +02:00
|
|
|
end
|
2016-07-18 18:24:29 +02:00
|
|
|
|
|
|
|
describe 'PUT #toggle_follow' do
|
|
|
|
before do
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
|
|
|
|
2016-11-15 04:50:18 +01:00
|
|
|
subject { put :follow, params: {dossier_id: dossier_id} }
|
2016-07-18 18:24:29 +02:00
|
|
|
|
|
|
|
it { expect(subject.status).to eq 302 }
|
|
|
|
|
2016-09-09 15:55:03 +02:00
|
|
|
context 'when dossier is at state initiated' do
|
|
|
|
let(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: 'initiated') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'change state for updated' do
|
|
|
|
expect(dossier.state).to eq 'updated'
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2016-07-18 18:24:29 +02:00
|
|
|
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
|