[Fix #1120] Delete the old accompagnateur UI

This commit is contained in:
gregoirenovel 2018-01-15 10:02:10 +01:00
parent 1c295eafb6
commit 1368cd4b03
90 changed files with 19 additions and 12044 deletions

View file

@ -25,10 +25,6 @@ describe Admin::AccompagnateursController, type: :controller do
end
it { expect(flash[:notice]).to be_present }
it 'default pref list dossier procedure columns are created' do
expect(procedure.preference_list_dossiers.size).to eq gestionnaire.preference_list_dossiers.where('procedure_id IS NULL').size
end
end
end
end

View file

@ -1,80 +0,0 @@
require 'spec_helper'
describe Backoffice::AvisController, type: :controller do
describe '#POST create' do
let(:claimant){ create(:gestionnaire) }
let(:gestionnaire){ create(:gestionnaire) }
let!(:dossier) do
dossier = create(:dossier, state: 'en_instruction')
claimant.procedures << [dossier.procedure]
dossier
end
subject do
post :create, params: { dossier_id: dossier.id, avis: { email: gestionnaire.email, introduction: "Bonjour, regardez ce joli dossier." } }
end
context 'when gestionnaire is not authenticated' do
before { subject }
it { expect(response).to redirect_to new_user_session_path }
it { expect(Avis.count).to eq(0) }
end
context 'when gestionnaire is authenticated' do
let(:created_avis) { Avis.last }
before do
sign_in claimant
subject
end
it { expect(response).to redirect_to backoffice_dossier_path(dossier.id) }
it { expect(Avis.count).to eq(1) }
it { expect(created_avis.dossier_id).to eq(dossier.id) }
it { expect(created_avis.gestionnaire).to eq(gestionnaire) }
it { expect(created_avis.claimant).to eq(claimant) }
it { expect(created_avis.confidentiel).to be(true) }
end
end
describe '#POST update' do
let(:gestionnaire){ create(:gestionnaire) }
let(:dossier){ create(:dossier, state: 'en_instruction') }
let(:avis){ create(:avis, dossier: dossier, gestionnaire: gestionnaire )}
subject { post :update, params: { dossier_id: dossier.id, id: avis.id, avis: { answer: "Ok ce dossier est valide." } } }
before :each do
notification = double('notification', notify: true)
allow(NotificationService).to receive(:new).and_return(notification)
end
context 'when gestionnaire is not authenticated' do
it { is_expected.to redirect_to new_user_session_path }
it { expect(avis.answer).to be_nil }
end
context 'when gestionnaire is authenticated' do
before do
sign_in gestionnaire
end
context 'and is invited on dossier' do
it { is_expected.to redirect_to backoffice_dossier_path(dossier.id) }
it do
subject
expect(avis.reload.answer).to eq("Ok ce dossier est valide.")
expect(NotificationService).to have_received(:new).at_least(:once)
end
end
context 'but is not invited on dossier' do
let(:gestionnaire2) { create(:gestionnaire) }
let(:avis){ create(:avis, dossier: dossier, gestionnaire: gestionnaire2 )}
it { expect{ subject }.to raise_error(ActiveRecord::RecordNotFound) }
end
end
end
end

View file

@ -1,124 +0,0 @@
require 'spec_helper'
describe Backoffice::CommentairesController, type: :controller do
let(:dossier) { create(:dossier, :en_construction) }
let(:dossier_id) { dossier.id }
let(:email_commentaire) { 'test@test.com' }
let(:texte_commentaire) { 'Commentaire de test' }
let(:gestionnaire) { create(:gestionnaire) }
before do
allow(ClamavService).to receive(:safe_file?).and_return(true)
end
describe '#POST create' do
before do
sign_in gestionnaire
end
context "when gestionnaire has no access to dossier" do
subject { post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire } }
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
it { expect { subject rescue nil }.to change(Commentaire, :count).by(0) }
end
context "when gestionnaire is invited for avis on dossier" do
subject { post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire } }
before { Avis.create(dossier: dossier, gestionnaire: gestionnaire, claimant: create(:gestionnaire)) }
it { expect{ subject }.to change(Commentaire, :count).by(1) }
end
context "when gestionnaire has access to dossier" do
before do
gestionnaire.procedures << dossier.procedure
end
context "création correct d'un commentaire" do
subject { post :create, params: {dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire} }
it 'depuis la page admin' do
expect(subject).to redirect_to("/backoffice/dossiers/#{dossier_id}")
end
it 'gestionnaire is automatically affect to follow the dossier' do
expect { subject }.to change(Follow, :count).by(1)
end
context 'when gestionnaire already follow dossier' do
before do
create :follow, gestionnaire_id: gestionnaire.id, dossier_id: dossier_id
end
it 'gestionnaire is automatically affect to follow the dossier' do
expect { subject }.to change(Follow, :count).by(0)
end
end
it 'Internal notification is not create' do
expect { subject }.to change(Notification, :count).by (0)
end
end
context 'when document is upload whith a commentaire', vcr: {cassette_name: 'controllers_backoffice_commentaires_controller_doc_upload_with_comment'} do
let(:document_upload) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
subject do
post :create, params: { dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire, file: document_upload }
end
it 'clamav check the pj' do
expect(ClamavService).to receive(:safe_file?)
subject
end
describe 'commentaire created' do
let(:commentaire) { Commentaire.last }
before do
subject
end
it 'have a piece justificative reference' do
expect(commentaire.file.present?).to eq true
expect(commentaire.file.class).to eq(CommentaireFileUploader)
end
end
end
describe 'change dossier state after post a comment' do
context 'gestionnaire is connected' do
context 'when dossier is at state en_construction' do
before do
sign_in gestionnaire
dossier.en_construction!
post :create, params: {dossier_id: dossier_id, texte_commentaire: texte_commentaire}
dossier.reload
end
it 'Notification email is send' do
expect(NotificationMailer).to receive(:new_answer).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
post :create, params: {dossier_id: dossier_id, texte_commentaire: texte_commentaire}
end
end
end
end
describe 'comment cannot be saved' do
before do
allow_any_instance_of(Commentaire).to receive(:save).and_return(false)
end
it 'Notification email is not sent' do
expect(NotificationMailer).not_to receive(:new_answer)
expect(NotificationMailer).not_to receive(:deliver_now!)
post :create, params: {dossier_id: dossier_id, texte_commentaire: texte_commentaire}
end
end
end
end
end

View file

@ -1,58 +0,0 @@
require 'spec_helper'
describe Backoffice::Dossiers::ProcedureController, type: :controller do
let(:gestionnaire) { create :gestionnaire }
let(:procedure) { create :procedure, :published }
let(:archived) { false }
let(:dossier) { create :dossier, procedure: procedure, archived: archived, state: 'en_construction'}
before do
create :assign_to, gestionnaire: gestionnaire, procedure: procedure
sign_in gestionnaire
gestionnaire.build_default_preferences_list_dossier procedure.id
end
describe 'GET #index' do
let(:procedure_id) { procedure.id }
subject { get :index, params: {id: procedure_id} }
it { expect(subject.status).to eq 200 }
context 'when procedure id is not found' do
let(:procedure_id) { 100000 }
before do
subject
end
it { expect(response.status).to eq 302 }
it { is_expected.to redirect_to backoffice_dossiers_path }
it { expect(flash[:alert]).to be_present}
end
context 'when procedure contains a dossier' do
render_views
before do
dossier
subject
end
it { expect(response.body).to have_content('Tous les dossiers 1 dossier') }
context 'archived' do
let(:archived) { true }
it { expect(response.body).to have_content('Tous les dossiers 0 dossiers') }
it { expect(response.body).to have_content('Dossiers archivés 1 dossier') }
end
end
end
describe 'GET #filter' do
subject { get :filter, params: {id: procedure.id, filter_input: {"entreprise.raison_sociale" => "plop"}} }
it { is_expected.to redirect_to backoffice_dossiers_procedure_path(id: procedure.id) }
end
end

View file

@ -1,410 +0,0 @@
require 'spec_helper'
describe Backoffice::DossiersController, type: :controller do
before do
@request.env['HTTP_REFERER'] = TPS::Application::URL
end
let(:procedure) { create :procedure, :published }
let(:procedure2) { create :procedure, :published }
let(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: :en_construction) }
let(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure2, state: :en_construction) }
let(:dossier_archived) { create(:dossier, :with_entreprise, archived: true) }
let(:dossier_id) { dossier.id }
let(:dossier2_id) { dossier2.id }
let(:bad_dossier_id) { Dossier.count + 10 }
let(:gestionnaire) { create(:gestionnaire, administrateurs: [create(:administrateur)]) }
let!(:gestionnaire2) { create(:gestionnaire, administrateurs: [create(:administrateur)]) }
before do
create :assign_to, procedure: procedure, gestionnaire: gestionnaire
create :assign_to, procedure: procedure2, gestionnaire: gestionnaire2
procedure.dossiers << dossier
procedure2.dossiers << dossier2
end
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) }
context 'when gestionnaire is assign to many proceudure' do
before do
create :assign_to, procedure: create(:procedure, :published), gestionnaire: gestionnaire
create :assign_to, procedure: create(:procedure, :published), gestionnaire: gestionnaire
end
it { expect(gestionnaire.procedures.count).to eq 3 }
context 'when gestionnaire procedure_filter is nil' do
it { expect(gestionnaire.procedure_filter).to be_nil }
it { is_expected.to redirect_to backoffice_dossiers_procedure_path(id: gestionnaire.procedures.order('libelle ASC').first.id) }
end
context 'when gestionnaire procedure_filter is not nil' do
let(:procedure_filter_id) { gestionnaire.procedures.order('libelle ASC').last.id }
before do
gestionnaire.update_column :procedure_filter, procedure_filter_id
end
context 'when gestionnaire is assign_to the procedure filter id' do
it { is_expected.to redirect_to backoffice_dossiers_procedure_path(id: procedure_filter_id) }
end
context 'when gestionnaire not any more assign_to the procedure filter id' do
before do
AssignTo.where(procedure: procedure_filter_id, gestionnaire: gestionnaire).delete_all
end
it { expect(gestionnaire.procedure_filter).to be_nil }
it { expect(AssignTo.where(procedure: procedure_filter_id, gestionnaire: gestionnaire).count).to eq 0 }
it { is_expected.to redirect_to backoffice_dossiers_procedure_path(id: gestionnaire.procedures.order('libelle ASC').first.id) }
end
end
end
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
describe 'GET #show' do
subject { get :show, params: {id: dossier_id} }
context 'gestionnaire is connected' do
before do
sign_in gestionnaire
end
it 'returns http success' do
expect(subject).to have_http_status(200)
end
describe 'all notifications unread are changed' do
it do
expect(Notification).to receive(:where).with(dossier_id: dossier_id.to_s).and_return(Notification::ActiveRecord_Relation)
expect(Notification::ActiveRecord_Relation).to receive(:update_all).with(already_read: true).and_return(true)
subject
end
end
context 'when dossier id does not exist' do
let(:dossier_id) { bad_dossier_id }
it { expect(subject).to redirect_to('/backoffice') }
end
describe 'he can invite somebody for avis' do
render_views
it { expect(subject.body).to include("Invitez une personne externe à consulter le dossier et à vous donner un avis sur celui ci.") }
end
context 'and is invited on a dossier' do
let(:dossier_invited){ create(:dossier, procedure: create(:procedure)) }
let!(:avis){ create(:avis, dossier: dossier_invited, gestionnaire: gestionnaire) }
subject { get :show, params: { id: dossier_invited.id } }
render_views
it { expect(subject.status).to eq(200) }
it { expect(subject.body).to include("Votre avis est sollicité sur le dossier") }
it { expect(subject.body).to_not include("Invitez une personne externe à consulter le dossier et à vous donner un avis sur celui ci.") }
describe 'the notifications are not marked as read' do
it do
expect(Notification).not_to receive(:where)
subject
end
end
end
end
context 'gestionnaire does not connected but dossier id is correct' do
it { is_expected.to redirect_to('/users/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, params: {liste: :a_traiter}
expect(response).to have_http_status(302)
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, params: {liste: :termine}
expect(response).to have_http_status(302)
end
end
end
describe 'GET #list_fake' do
context 'when gestionnaire is connected' do
before do
sign_in gestionnaire
end
it 'returns http success' do
get :index, params: {liste: :list_fake}
expect(response).to redirect_to(backoffice_dossiers_procedure_path(id: gestionnaire.procedures.first.id))
end
end
end
describe 'POST #search' do
describe 'by id' do
context 'when I am logged as a gestionnaire' do
before do
sign_in gestionnaire
end
context 'when I own the dossier' do
before :each do
post :search, params: { q: dossier_id }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'returns the expected dossier' do
expect(assigns(:dossiers).count).to eq(1)
expect(assigns(:dossiers).first.id).to eq(dossier_id)
end
end
context 'when I do not own the dossier' do
before :each do
post :search, params: { q: dossier2_id }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'does not return the dossier' do
expect(assigns(:dossiers).pluck(:id)).not_to include(dossier2_id)
end
end
end
end
end
describe 'POST #receive' do
before do
dossier.en_construction!
sign_in gestionnaire
post :receive, params: { dossier_id: dossier_id }
dossier.reload
end
it { expect(dossier.state).to eq('en_instruction') }
it { is_expected.to redirect_to backoffice_dossier_path(dossier) }
it { expect(gestionnaire.follow?(dossier)).to be true }
end
describe 'POST #process_dossier' do
context "with refuse" do
before do
dossier.en_instruction!
sign_in gestionnaire
end
subject { post :process_dossier, params: { process_action: "refuse", dossier_id: dossier_id} }
it 'change state to refuse' do
subject
dossier.reload
expect(dossier.state).to eq('refuse')
end
it 'Notification email is sent' do
expect(NotificationMailer).to receive(:send_notification)
.with(dossier, kind_of(Mails::RefusedMail), nil).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
subject
end
it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) }
end
context "with sans_suite" do
before do
dossier.en_instruction!
sign_in gestionnaire
end
subject { post :process_dossier, params: { process_action: "without_continuation", dossier_id: dossier_id} }
it 'change state to sans_suite' do
subject
dossier.reload
expect(dossier.state).to eq('sans_suite')
end
it 'Notification email is sent' do
expect(NotificationMailer).to receive(:send_notification)
.with(dossier, kind_of(Mails::WithoutContinuationMail), nil).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
subject
end
it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) }
end
context "with close" do
let(:expected_attestation) { nil }
before do
dossier.en_instruction!
sign_in gestionnaire
expect(NotificationMailer).to receive(:send_notification)
.with(dossier, kind_of(Mails::ClosedMail), expected_attestation)
.and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
end
subject { post :process_dossier, params: { process_action: "close", dossier_id: dossier_id} }
it 'change state to accepte' do
subject
dossier.reload
expect(dossier.state).to eq('accepte')
end
context 'when the dossier does not have any attestation' do
it 'Notification email is sent' do
subject
end
end
context 'when the dossier has an attestation' do
before do
attestation = Attestation.new
allow(attestation).to receive(:pdf).and_return(double(read: 'pdf', size: 2.megabytes))
allow(attestation).to receive(:emailable?).and_return(emailable)
expect_any_instance_of(Dossier).to receive(:reload)
allow_any_instance_of(Dossier).to receive(:build_attestation).and_return(attestation)
end
context 'emailable' do
let(:emailable) { true }
let(:expected_attestation) { 'pdf' }
it 'Notification email is sent with the attestation' do
subject
is_expected.to redirect_to backoffice_dossier_path(id: dossier.id)
end
end
context 'when the dossier has an attestation not emailable' do
let(:emailable) { false }
let(:expected_attestation) { nil }
it 'Notification email is sent without the attestation' do
expect(controller).to receive(:capture_message)
subject
is_expected.to redirect_to backoffice_dossier_path(id: dossier.id)
end
end
end
context 'when the attestation template uses the motivation field' do
let(:emailable) { false }
let(:template) { create(:attestation_template) }
let(:procedure) { create(:procedure, :published, attestation_template: template, gestionnaires: [gestionnaire]) }
subject { post :process_dossier, params: { process_action: "close", dossier_id: dossier_id, dossier: { motivation: "Yallah" }}}
before do
Timecop.freeze(DateTime.now)
expect_any_instance_of(AttestationTemplate)
.to receive(:attestation_for)
.with(have_attributes(motivation: "Yallah", processed_at: DateTime.now))
end
after { Timecop.return }
it { subject }
end
end
end
describe 'POST #reopen' do
before do
dossier.en_instruction!
sign_in gestionnaire
end
subject { post :reopen, params: {dossier_id: dossier_id} }
it 'change state to en_construction' do
subject
dossier.reload
expect(dossier.state).to eq('en_construction')
end
it { is_expected.to redirect_to backoffice_dossier_path(id: dossier_id) }
end
describe 'POST #archive' do
before do
dossier.update(archived: false)
sign_in gestionnaire
end
subject { post :archive, params: {id: dossier_id} }
it 'change state to archived' do
subject
dossier.reload
expect(dossier.archived).to eq(true)
end
it { is_expected.to redirect_to backoffice_dossiers_path }
end
end

View file

@ -1,56 +0,0 @@
require 'spec_helper'
describe Backoffice::PreferenceListDossierController, type: :controller do
let(:gestionnaire) { create :gestionnaire }
let(:libelle) { 'Plop' }
let(:table) { 'plip' }
let(:attr) { 'plap' }
let(:attr_decorate) { 'plup' }
let(:bootstrap_lg) { 'plyp' }
before do
sign_in gestionnaire
end
describe '#POST add' do
subject { post :add,
params: {
libelle: libelle,
table: table,
attr: attr,
attr_decorate: attr_decorate,
bootstrap_lg: bootstrap_lg
}
}
it { expect(subject.status).to eq 200 }
it { expect { subject }.to change(PreferenceListDossier, :count).by(1) }
describe 'attributs' do
let(:last) { PreferenceListDossier.last }
before do
subject
end
it { expect(last.libelle).to eq libelle }
it { expect(last.table).to eq table }
it { expect(last.attr).to eq attr }
it { expect(last.attr_decorate).to eq attr_decorate }
it { expect(last.bootstrap_lg).to eq bootstrap_lg }
it { expect(last.order).to be_nil }
it { expect(last.filter).to be_nil }
it { expect(last.procedure_id).to be_nil }
it { expect(last.gestionnaire).to eq gestionnaire }
end
end
describe '#DELETE delete' do
let!(:pref) { create :preference_list_dossier }
subject { delete :delete, params: {pref_id: pref.id} }
it { expect(subject.status).to eq 200 }
it { expect { subject }.to change(PreferenceListDossier, :count).by(-1) }
end
end

View file

@ -1,32 +0,0 @@
require 'spec_helper'
describe Backoffice::PrivateFormulairesController, type: :controller do
let(:gestionnaire) { create :gestionnaire }
let(:dossier) { create :dossier, state: :en_construction }
let(:dossier_champs_first) { 'plop' }
before do
create :assign_to, procedure_id: dossier.procedure.id, gestionnaire_id: gestionnaire.id
sign_in gestionnaire
end
describe '#PATCH update' do
subject { patch :update,
params: {
dossier_id: dossier.id,
champs: {
"'#{dossier.champs_private.first.id}'" => dossier_champs_first
}
}
}
before do
subject
end
it { expect(response.status).to eq 200 }
it { expect(Dossier.find(dossier.id).champs_private.first.value).to eq dossier_champs_first }
it { expect(flash[:notice]).to be_present }
end
end

View file

@ -1,74 +0,0 @@
require 'spec_helper'
describe BackofficeController, type: :controller do
describe 'GET #index' do
context 'when gestionnaire is not connected' do
before do
get :index
end
it { expect(response).to redirect_to :new_gestionnaire_session }
end
context 'when gestionnaire is connected' do
before do
sign_in create(:gestionnaire)
get :index
end
it { expect(response).to redirect_to :backoffice_dossiers }
end
end
describe 'GET #invitations' do
context 'when gestionnaire is not invited on any dossiers' do
render_views
before do
sign_in create(:gestionnaire)
get :invitations
end
it { expect(response.status).to eq(200) }
it { expect(response.body).to include("INVITATIONS") }
it { expect(response.body).to include("0 avis à rendre") }
it { expect(response.body).to include("0 avis rendus") }
end
context 'when gestionnaire is invited on a dossier' do
let(:dossier){ create(:dossier) }
let(:gestionnaire){ create(:gestionnaire) }
let!(:avis){ create(:avis, dossier: dossier, gestionnaire: gestionnaire) }
render_views
before do
sign_in gestionnaire
get :invitations
end
it { expect(response.status).to eq(200) }
it { expect(response.body).to include("1 avis à rendre") }
it { expect(response.body).to include("0 avis rendus") }
it { expect(response.body).to include(dossier.procedure.libelle) }
context 'when avis is already sent' do
let!(:avis){ create(:avis, dossier: dossier, gestionnaire: gestionnaire, answer: "Voici mon avis.") }
it { expect(response.body).to include("0 avis à rendre") }
it { expect(response.body).to include("1 avis rendu") }
it { expect(response.body).to include(dossier.procedure.libelle) }
end
context 'when dossier linked to avis is hidden' do
before do
dossier.update_attributes(hidden_at: Time.now)
get :invitations
end
it { expect(response.status).to eq(200) }
it { expect(response.body).to include("0 avis à rendre") }
it { expect(response.body).to include("0 avis rendu") }
end
end
end
end

View file

@ -22,12 +22,6 @@ describe RootController, type: :controller do
end
it { expect(subject).to redirect_to(procedures_path) }
context 'and coming with old_ui param' do
subject { get :index, params: { old_ui: 1 } }
it { expect(subject).to redirect_to(backoffice_path) }
end
end
context 'when Administrateur is connected' do