2015-09-22 15:00:59 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Backoffice::CommentairesController, type: :controller do
|
2017-12-14 15:51:45 +01:00
|
|
|
let(:dossier) { create(:dossier, :en_construction) }
|
2015-09-22 15:00:59 +02:00
|
|
|
let(:dossier_id) { dossier.id }
|
|
|
|
let(:email_commentaire) { 'test@test.com' }
|
|
|
|
let(:texte_commentaire) { 'Commentaire de test' }
|
2016-07-18 18:24:29 +02:00
|
|
|
let(:gestionnaire) { create(:gestionnaire) }
|
2015-09-22 15:00:59 +02:00
|
|
|
|
2016-04-20 16:51:57 +02:00
|
|
|
before do
|
|
|
|
allow(ClamavService).to receive(:safe_file?).and_return(true)
|
|
|
|
end
|
|
|
|
|
2015-09-22 15:00:59 +02:00
|
|
|
describe '#POST create' do
|
|
|
|
before do
|
2016-07-18 18:24:29 +02:00
|
|
|
sign_in gestionnaire
|
2015-09-22 15:00:59 +02:00
|
|
|
end
|
2016-07-18 18:24:29 +02:00
|
|
|
|
2017-07-10 17:11:55 +02:00
|
|
|
context "when gestionnaire has no access to dossier" do
|
|
|
|
subject { post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire } }
|
2016-07-18 18:24:29 +02:00
|
|
|
|
2017-07-10 17:11:55 +02:00
|
|
|
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)) }
|
2016-07-18 18:24:29 +02:00
|
|
|
|
2017-07-10 17:11:55 +02:00
|
|
|
it { expect{ subject }.to change(Commentaire, :count).by(1) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when gestionnaire has access to dossier" do
|
|
|
|
before do
|
|
|
|
gestionnaire.procedures << dossier.procedure
|
2016-07-18 18:24:29 +02:00
|
|
|
end
|
|
|
|
|
2017-07-10 17:11:55 +02:00
|
|
|
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}")
|
2016-07-18 18:24:29 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'gestionnaire is automatically affect to follow the dossier' do
|
2017-07-10 17:11:55 +02:00
|
|
|
expect { subject }.to change(Follow, :count).by(1)
|
2016-07-18 18:24:29 +02:00
|
|
|
end
|
2015-09-25 10:46:09 +02:00
|
|
|
|
2017-07-10 17:11:55 +02:00
|
|
|
context 'when gestionnaire already follow dossier' do
|
|
|
|
before do
|
|
|
|
create :follow, gestionnaire_id: gestionnaire.id, dossier_id: dossier_id
|
|
|
|
end
|
2016-04-20 16:51:57 +02:00
|
|
|
|
2017-07-10 17:11:55 +02:00
|
|
|
it 'gestionnaire is automatically affect to follow the dossier' do
|
|
|
|
expect { subject }.to change(Follow, :count).by(0)
|
|
|
|
end
|
|
|
|
end
|
2016-04-20 16:51:57 +02:00
|
|
|
|
2017-07-10 17:11:55 +02:00
|
|
|
it 'Internal notification is not create' do
|
|
|
|
expect { subject }.to change(Notification, :count).by (0)
|
|
|
|
end
|
2016-04-20 16:51:57 +02:00
|
|
|
end
|
|
|
|
|
2017-07-10 17:11:55 +02:00
|
|
|
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') }
|
2016-04-20 16:51:57 +02:00
|
|
|
|
2017-07-10 17:11:55 +02:00
|
|
|
subject do
|
2017-10-31 17:45:04 +01:00
|
|
|
post :create, params: { dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire, file: document_upload }
|
2017-07-10 17:11:55 +02:00
|
|
|
end
|
2016-04-20 16:51:57 +02:00
|
|
|
|
2017-07-10 17:11:55 +02:00
|
|
|
it 'clamav check the pj' do
|
|
|
|
expect(ClamavService).to receive(:safe_file?)
|
2016-04-20 16:51:57 +02:00
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
2017-07-10 17:11:55 +02:00
|
|
|
describe 'commentaire created' do
|
|
|
|
let(:commentaire) { Commentaire.last }
|
|
|
|
|
2015-09-25 10:46:09 +02:00
|
|
|
before do
|
2017-07-10 17:11:55 +02:00
|
|
|
subject
|
|
|
|
end
|
2015-09-25 10:46:09 +02:00
|
|
|
|
2017-07-10 17:11:55 +02:00
|
|
|
it 'have a piece justificative reference' do
|
2017-10-31 17:45:04 +01:00
|
|
|
expect(commentaire.file.present?).to eq true
|
|
|
|
expect(commentaire.file.class).to eq(CommentaireFileUploader)
|
2015-09-25 10:46:09 +02:00
|
|
|
end
|
2017-07-10 17:11:55 +02:00
|
|
|
end
|
|
|
|
end
|
2015-09-25 10:46:09 +02:00
|
|
|
|
2017-07-10 17:11:55 +02:00
|
|
|
describe 'change dossier state after post a comment' do
|
|
|
|
context 'gestionnaire is connected' do
|
2017-12-14 15:51:45 +01:00
|
|
|
context 'when dossier is at state en_construction' do
|
2017-07-10 17:11:55 +02:00
|
|
|
before do
|
|
|
|
sign_in gestionnaire
|
2017-12-14 15:51:45 +01:00
|
|
|
dossier.en_construction!
|
2015-09-25 10:46:09 +02:00
|
|
|
|
2017-07-10 17:11:55 +02:00
|
|
|
post :create, params: {dossier_id: dossier_id, texte_commentaire: texte_commentaire}
|
|
|
|
dossier.reload
|
|
|
|
end
|
2015-12-15 15:33:21 +01:00
|
|
|
|
2017-07-10 17:11:55 +02:00
|
|
|
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
|
2015-12-15 15:33:21 +01:00
|
|
|
end
|
2015-09-25 10:46:09 +02:00
|
|
|
end
|
|
|
|
end
|
2016-06-14 16:00:37 +02:00
|
|
|
|
2017-07-10 17:11:55 +02:00
|
|
|
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!)
|
2016-06-14 16:00:37 +02:00
|
|
|
|
2017-07-10 17:11:55 +02:00
|
|
|
post :create, params: {dossier_id: dossier_id, texte_commentaire: texte_commentaire}
|
|
|
|
end
|
2016-06-14 16:00:37 +02:00
|
|
|
end
|
|
|
|
end
|
2015-09-22 15:00:59 +02:00
|
|
|
end
|
|
|
|
end
|