2017-06-29 15:31:29 +02:00
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
describe NewGestionnaire::DossiersController, type: :controller do
|
2017-09-20 10:42:16 +02:00
|
|
|
|
render_views
|
|
|
|
|
|
2017-06-29 15:31:29 +02:00
|
|
|
|
let(:gestionnaire) { create(:gestionnaire) }
|
2017-07-18 15:26:33 +02:00
|
|
|
|
let(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire]) }
|
2017-07-06 16:33:36 +02:00
|
|
|
|
let(:dossier) { create(:dossier, :replied, procedure: procedure) }
|
2017-06-29 15:31:29 +02:00
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
before { sign_in(gestionnaire) }
|
2017-07-06 16:33:36 +02:00
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
describe '#attestation' do
|
2017-06-29 15:31:29 +02:00
|
|
|
|
context 'when a dossier has an attestation' do
|
|
|
|
|
let(:fake_pdf) { double(read: 'pdf content') }
|
2017-07-06 16:33:36 +02:00
|
|
|
|
let!(:dossier) { create(:dossier, :replied, attestation: Attestation.new, procedure: procedure) }
|
2017-07-18 15:26:33 +02:00
|
|
|
|
let!(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire]) }
|
2017-07-06 16:33:36 +02:00
|
|
|
|
let!(:dossier) { create(:dossier, :replied, attestation: Attestation.new, procedure: procedure) }
|
2017-06-29 15:31:29 +02:00
|
|
|
|
|
|
|
|
|
it 'returns the attestation pdf' do
|
|
|
|
|
allow_any_instance_of(Attestation).to receive(:pdf).and_return(fake_pdf)
|
|
|
|
|
|
|
|
|
|
expect(controller).to receive(:send_data)
|
|
|
|
|
.with('pdf content', filename: 'attestation.pdf', type: 'application/pdf') do
|
|
|
|
|
controller.render nothing: true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
get :attestation, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-07-11 15:45:20 +02:00
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
describe '#follow' do
|
|
|
|
|
before do
|
|
|
|
|
expect_any_instance_of(Dossier).to receive(:next_step!).with('gestionnaire', 'follow')
|
|
|
|
|
patch :follow, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
2017-07-11 15:45:20 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
it { expect(gestionnaire.followed_dossiers).to match([dossier]) }
|
|
|
|
|
it { expect(flash.notice).to eq('Dossier suivi') }
|
|
|
|
|
it { expect(response).to redirect_to(procedures_url) }
|
|
|
|
|
end
|
2017-07-11 15:56:23 +02:00
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
describe '#unfollow' do
|
|
|
|
|
before do
|
|
|
|
|
gestionnaire.followed_dossiers << dossier
|
|
|
|
|
patch :unfollow, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
|
|
|
|
gestionnaire.reload
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
it { expect(gestionnaire.followed_dossiers).to match([]) }
|
|
|
|
|
it { expect(flash.notice).to eq("Vous ne suivez plus le dossier nº #{dossier.id}") }
|
|
|
|
|
it { expect(response).to redirect_to(procedures_url) }
|
|
|
|
|
end
|
2017-07-06 16:33:36 +02:00
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
describe '#archive' do
|
|
|
|
|
before do
|
|
|
|
|
patch :archive, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
|
|
|
|
dossier.reload
|
2017-07-06 16:33:36 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
it { expect(dossier.archived).to be true }
|
|
|
|
|
it { expect(response).to redirect_to(procedures_url) }
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
describe '#unarchive' do
|
|
|
|
|
before do
|
|
|
|
|
dossier.update_attributes(archived: true)
|
|
|
|
|
patch :unarchive, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
|
|
|
|
dossier.reload
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
it { expect(dossier.archived).to be false }
|
|
|
|
|
it { expect(response).to redirect_to(procedures_url) }
|
|
|
|
|
end
|
2017-07-06 16:33:36 +02:00
|
|
|
|
|
2017-08-30 15:31:36 +02:00
|
|
|
|
describe '#show #messagerie #instruction' do
|
|
|
|
|
before do
|
|
|
|
|
dossier.notifications = %w(champs avis commentaire).map{ |type| Notification.create!(type_notif: type) }
|
|
|
|
|
get method, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
|
|
|
|
dossier.notifications.each(&:reload)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context '#show' do
|
|
|
|
|
let(:method) { :show }
|
|
|
|
|
it { expect(dossier.notifications.map(&:already_read)).to match([true, false, false]) }
|
|
|
|
|
it { expect(response).to have_http_status(:success) }
|
|
|
|
|
end
|
2017-07-06 16:33:36 +02:00
|
|
|
|
|
2017-08-30 15:31:36 +02:00
|
|
|
|
context '#instruction' do
|
|
|
|
|
let(:method) { :instruction }
|
|
|
|
|
it { expect(dossier.notifications.map(&:already_read)).to match([false, true, false]) }
|
|
|
|
|
it { expect(response).to have_http_status(:success) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context '#messagerie' do
|
|
|
|
|
let(:method) { :messagerie }
|
|
|
|
|
it { expect(dossier.notifications.map(&:already_read)).to match([false, false, true]) }
|
|
|
|
|
it { expect(response).to have_http_status(:success) }
|
|
|
|
|
end
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
2017-07-19 14:04:49 +02:00
|
|
|
|
|
2017-07-24 11:45:03 +02:00
|
|
|
|
describe "#create_commentaire" do
|
2017-07-19 14:04:49 +02:00
|
|
|
|
let(:saved_commentaire) { dossier.commentaires.first }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
post :create_commentaire, params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id,
|
|
|
|
|
commentaire: { body: 'body' }
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(saved_commentaire.body).to eq('body') }
|
|
|
|
|
it { expect(saved_commentaire.email).to eq(gestionnaire.email) }
|
|
|
|
|
it { expect(saved_commentaire.dossier).to eq(dossier) }
|
|
|
|
|
it { expect(response).to redirect_to(messagerie_dossier_path(dossier.procedure, dossier)) }
|
|
|
|
|
end
|
2017-08-28 14:16:13 +02:00
|
|
|
|
|
|
|
|
|
describe "#create_avis" do
|
|
|
|
|
let(:saved_avis) { dossier.avis.first }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
post :create_avis, params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id,
|
2017-09-20 10:42:16 +02:00
|
|
|
|
avis: { email: 'email@a.com', introduction: 'intro', confidentiel: true }
|
2017-08-28 14:16:13 +02:00
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(saved_avis.email).to eq('email@a.com') }
|
|
|
|
|
it { expect(saved_avis.introduction).to eq('intro') }
|
2017-09-20 10:42:16 +02:00
|
|
|
|
it { expect(saved_avis.confidentiel).to eq(true) }
|
2017-08-28 14:16:13 +02:00
|
|
|
|
it { expect(saved_avis.dossier).to eq(dossier) }
|
|
|
|
|
it { expect(saved_avis.claimant).to eq(gestionnaire) }
|
|
|
|
|
it { expect(response).to redirect_to(instruction_dossier_path(dossier.procedure, dossier)) }
|
|
|
|
|
end
|
2017-08-02 15:33:23 +02:00
|
|
|
|
|
|
|
|
|
describe "#update_annotations" do
|
|
|
|
|
let(:champ_multiple_drop_down_list) do
|
|
|
|
|
type_de_champ = TypeDeChamp.create(type_champ: 'multiple_drop_down_list', libelle: 'libelle')
|
|
|
|
|
ChampPrivate.create(type_de_champ: type_de_champ)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:champ_datetime) do
|
|
|
|
|
type_de_champ = TypeDeChamp.create(type_champ: 'datetime', libelle: 'libelle')
|
|
|
|
|
ChampPrivate.create(type_de_champ: type_de_champ)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:dossier) do
|
|
|
|
|
create(:dossier, :replied, procedure: procedure, champs_private: [champ_multiple_drop_down_list, champ_datetime])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
patch :update_annotations, params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id,
|
|
|
|
|
dossier: {
|
|
|
|
|
champs_private_attributes: {
|
|
|
|
|
'0': {
|
|
|
|
|
id: champ_multiple_drop_down_list.id,
|
|
|
|
|
value: ['', 'un', 'deux']
|
|
|
|
|
},
|
|
|
|
|
'1': {
|
|
|
|
|
id: champ_datetime.id,
|
|
|
|
|
'value(1i)': 2019,
|
|
|
|
|
'value(2i)': 12,
|
|
|
|
|
'value(3i)': 21,
|
|
|
|
|
'value(4i)': 13,
|
|
|
|
|
'value(5i)': 17
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
champ_multiple_drop_down_list.reload
|
|
|
|
|
champ_datetime.reload
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(champ_multiple_drop_down_list.value).to eq('["un", "deux"]') }
|
|
|
|
|
it { expect(champ_datetime.value).to eq('21/12/2019 13:17') }
|
|
|
|
|
it { expect(response).to redirect_to(instruction_dossier_path(dossier.procedure, dossier)) }
|
|
|
|
|
end
|
2017-06-29 15:31:29 +02:00
|
|
|
|
end
|