2017-05-02 16:20:16 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Backoffice::AvisController, type: :controller do
|
|
|
|
describe '#POST create' do
|
2017-07-20 16:30:11 +02:00
|
|
|
let(:claimant){ create(:gestionnaire) }
|
2017-05-02 16:20:16 +02:00
|
|
|
let(:gestionnaire){ create(:gestionnaire) }
|
2017-07-20 16:30:11 +02:00
|
|
|
let!(:dossier) do
|
2017-12-14 15:53:02 +01:00
|
|
|
dossier = create(:dossier, state: 'en_instruction')
|
2017-07-20 16:30:11 +02:00
|
|
|
claimant.procedures << [dossier.procedure]
|
|
|
|
dossier
|
|
|
|
end
|
2017-05-02 16:20:16 +02:00
|
|
|
|
2017-07-20 16:30:11 +02:00
|
|
|
subject do
|
|
|
|
post :create, params: { dossier_id: dossier.id, avis: { email: gestionnaire.email, introduction: "Bonjour, regardez ce joli dossier." } }
|
|
|
|
end
|
2017-05-02 16:20:16 +02:00
|
|
|
|
|
|
|
context 'when gestionnaire is not authenticated' do
|
2017-07-20 16:30:11 +02:00
|
|
|
before { subject }
|
|
|
|
|
|
|
|
it { expect(response).to redirect_to new_user_session_path }
|
|
|
|
it { expect(Avis.count).to eq(0) }
|
2017-05-02 16:20:16 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gestionnaire is authenticated' do
|
2017-07-20 16:30:11 +02:00
|
|
|
let(:created_avis) { Avis.last }
|
|
|
|
|
2017-05-02 16:20:16 +02:00
|
|
|
before do
|
2017-07-20 16:30:11 +02:00
|
|
|
sign_in claimant
|
|
|
|
subject
|
2017-05-02 16:20:16 +02:00
|
|
|
end
|
|
|
|
|
2017-07-20 16:30:11 +02:00
|
|
|
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) }
|
2017-09-22 17:58:16 +02:00
|
|
|
it { expect(created_avis.confidentiel).to be(true) }
|
2017-05-02 16:20:16 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-24 18:45:31 +02:00
|
|
|
describe '#POST update' do
|
|
|
|
let(:gestionnaire){ create(:gestionnaire) }
|
2017-12-14 15:53:02 +01:00
|
|
|
let(:dossier){ create(:dossier, state: 'en_instruction') }
|
2017-05-24 18:45:31 +02:00
|
|
|
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." } } }
|
|
|
|
|
2017-05-22 17:10:17 +02:00
|
|
|
before :each do
|
|
|
|
notification = double('notification', notify: true)
|
|
|
|
allow(NotificationService).to receive(:new).and_return(notification)
|
|
|
|
end
|
|
|
|
|
2017-05-24 18:45:31 +02:00
|
|
|
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.")
|
2017-05-22 17:10:17 +02:00
|
|
|
expect(NotificationService).to have_received(:new).at_least(:once)
|
2017-05-24 18:45:31 +02:00
|
|
|
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
|
2017-05-02 16:20:16 +02:00
|
|
|
end
|