2016-09-14 16:36:01 +02:00
|
|
|
shared_examples 'description_controller_spec' do
|
|
|
|
describe 'GET #show' do
|
2016-11-02 16:33:01 +01:00
|
|
|
before do
|
|
|
|
dossier.update_column :autorisation_donnees, true
|
|
|
|
end
|
2016-09-14 16:36:01 +02:00
|
|
|
context 'user is not connected' do
|
|
|
|
before do
|
|
|
|
sign_out dossier.user
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to users/sign_in' do
|
2018-01-11 15:37:33 +01:00
|
|
|
get :show, params: { dossier_id: dossier_id }
|
2016-09-14 16:36:01 +02:00
|
|
|
expect(response).to redirect_to('/users/sign_in')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-02 16:33:01 +01:00
|
|
|
context 'when all is ok' do
|
|
|
|
before do
|
|
|
|
dossier.entreprise = create :entreprise
|
2018-01-11 15:37:33 +01:00
|
|
|
get :show, params: { dossier_id: dossier_id }
|
2016-11-02 16:33:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
end
|
2017-03-06 14:29:01 +01:00
|
|
|
|
2017-03-06 15:03:51 +01:00
|
|
|
context 'procedure is archived' do
|
2017-03-06 14:29:01 +01:00
|
|
|
render_views
|
2017-07-10 23:42:33 +02:00
|
|
|
let(:archived_at) { Time.now }
|
2017-03-06 14:29:01 +01:00
|
|
|
|
|
|
|
it { expect(response).to have_http_status(:success) }
|
2017-03-06 15:03:51 +01:00
|
|
|
it { expect(response.body).to_not have_content(I18n.t('errors.messages.procedure_archived')) }
|
|
|
|
|
2017-12-04 16:17:15 +01:00
|
|
|
context 'dossier is a brouillon' do
|
|
|
|
let(:state) { 'brouillon' }
|
2017-03-06 15:03:51 +01:00
|
|
|
|
|
|
|
it { expect(response).to have_http_status(:success) }
|
|
|
|
it { expect(response.body).to have_content(I18n.t('errors.messages.procedure_archived')) }
|
|
|
|
end
|
2017-03-06 14:29:01 +01:00
|
|
|
end
|
2016-09-14 16:36:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirection vers start si mauvais dossier ID' do
|
2018-01-11 15:37:33 +01:00
|
|
|
get :show, params: { dossier_id: bad_dossier_id }
|
2016-12-19 15:08:00 +01:00
|
|
|
|
|
|
|
expect(flash[:alert]).to be_present
|
2016-09-14 16:36:01 +02:00
|
|
|
expect(response).to redirect_to(root_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like "not owner of dossier", :show
|
|
|
|
|
|
|
|
describe 'before_action authorized_routes?' do
|
|
|
|
context 'when dossier does not have a valid state' do
|
|
|
|
before do
|
2017-12-14 15:53:02 +01:00
|
|
|
dossier.state = 'en_instruction'
|
2016-09-14 16:36:01 +02:00
|
|
|
dossier.save
|
|
|
|
|
2018-01-11 15:37:33 +01:00
|
|
|
get :show, params: { dossier_id: dossier.id }
|
2016-09-14 16:36:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to redirect_to root_path }
|
|
|
|
end
|
|
|
|
end
|
2016-11-02 16:33:01 +01:00
|
|
|
|
|
|
|
describe 'before action check_autorisation_donnees' do
|
2018-01-11 15:37:33 +01:00
|
|
|
subject { get :show, params: { dossier_id: dossier_id } }
|
2016-11-02 16:33:01 +01:00
|
|
|
|
|
|
|
context 'when dossier does not have a valid autorisations_donness (nil)' do
|
|
|
|
before do
|
|
|
|
dossier.update_column :autorisation_donnees, nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when dossier does not have a valid autorisations_donness (false)' do
|
|
|
|
before do
|
|
|
|
dossier.update_column :autorisation_donnees, false
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'before action check_starter_dossier_informations' do
|
2018-01-11 15:37:33 +01:00
|
|
|
subject { get :show, params: { dossier_id: dossier_id } }
|
2016-11-02 16:33:01 +01:00
|
|
|
|
|
|
|
context 'when dossier does not have an enterprise datas' do
|
|
|
|
it { expect(dossier.entreprise).to be_nil }
|
|
|
|
it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when dossier does not have an individual datas' do
|
|
|
|
before do
|
|
|
|
procedure.update_column :for_individual, true
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(dossier.individual).to be_nil }
|
|
|
|
it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
|
|
|
|
end
|
|
|
|
end
|
2016-09-14 16:36:01 +02:00
|
|
|
end
|
|
|
|
|
2017-03-06 14:29:01 +01:00
|
|
|
describe 'POST #update' do
|
2016-09-14 16:36:01 +02:00
|
|
|
context 'Tous les attributs sont bons' do
|
|
|
|
describe 'Premier enregistrement des données' do
|
2018-01-11 16:16:08 +01:00
|
|
|
let(:state) { 'brouillon' }
|
|
|
|
|
2018-01-11 15:58:37 +01:00
|
|
|
def submit_dossier
|
|
|
|
post :update, params: { dossier_id: dossier_id, submit: submit }
|
2016-09-14 16:36:01 +02:00
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
2017-12-18 17:51:04 +01:00
|
|
|
context "when the user submits the dossier" do
|
2018-01-11 15:37:33 +01:00
|
|
|
let(:submit) { { nouveaux: 'nouveaux' } }
|
2017-12-18 17:51:04 +01:00
|
|
|
|
|
|
|
it "redirection vers la page recapitulative" do
|
2018-01-11 15:58:37 +01:00
|
|
|
submit_dossier
|
|
|
|
|
2017-12-18 17:51:04 +01:00
|
|
|
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif")
|
|
|
|
end
|
2016-09-14 16:36:01 +02:00
|
|
|
|
2017-12-18 17:51:04 +01:00
|
|
|
it 'etat du dossier est en construction' do
|
2018-01-11 15:58:37 +01:00
|
|
|
submit_dossier
|
|
|
|
|
2017-12-18 17:51:04 +01:00
|
|
|
expect(dossier.state).to eq('en_construction')
|
|
|
|
end
|
2018-01-11 16:21:26 +01:00
|
|
|
|
|
|
|
context 'sending the accusé de réception mail' do
|
|
|
|
before { Timecop.freeze(DateTime.now) }
|
|
|
|
|
|
|
|
after { Timecop.return }
|
|
|
|
|
|
|
|
it 'sets the state of the dossier before sending the mail' do
|
|
|
|
expect_any_instance_of(Mails::InitiatedMail)
|
|
|
|
.to receive(:subject_for_dossier)
|
|
|
|
.with(have_attributes(en_construction_at: DateTime.now))
|
|
|
|
|
|
|
|
submit_dossier
|
|
|
|
end
|
|
|
|
end
|
2016-09-14 16:36:01 +02:00
|
|
|
end
|
2016-10-05 16:45:51 +02:00
|
|
|
|
2017-12-18 17:51:04 +01:00
|
|
|
context 'when user saves a brouillon' do
|
2018-01-11 15:37:33 +01:00
|
|
|
let(:submit) { { brouillon: 'brouillon' } }
|
2016-10-05 16:45:51 +02:00
|
|
|
|
2017-12-18 17:51:04 +01:00
|
|
|
it "reste sur la page du dossier" do
|
2018-01-11 15:58:37 +01:00
|
|
|
submit_dossier
|
2017-12-18 17:51:04 +01:00
|
|
|
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/description")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'etat du dossier est brouillon' do
|
2018-01-11 15:58:37 +01:00
|
|
|
submit_dossier
|
2017-12-18 17:51:04 +01:00
|
|
|
expect(dossier.state).to eq('brouillon')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user saves a brouillon and goes to dashboard' do
|
2018-01-11 15:37:33 +01:00
|
|
|
let(:submit) { { brouillon_then_dashboard: 'brouillon_then_dashboard' } }
|
2017-12-18 17:51:04 +01:00
|
|
|
|
|
|
|
it "goes to dashboard" do
|
2018-01-11 15:58:37 +01:00
|
|
|
submit_dossier
|
2016-10-05 16:45:51 +02:00
|
|
|
expect(response).to redirect_to("/users/dossiers?liste=brouillon")
|
|
|
|
end
|
|
|
|
|
2017-12-18 17:51:04 +01:00
|
|
|
it 'etat du dossier est brouillon' do
|
2018-01-11 15:58:37 +01:00
|
|
|
submit_dossier
|
2017-12-04 16:17:15 +01:00
|
|
|
expect(dossier.state).to eq('brouillon')
|
2016-10-05 16:45:51 +02:00
|
|
|
end
|
|
|
|
end
|
2016-09-14 16:36:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'En train de manipuler un dossier non brouillon' do
|
|
|
|
before do
|
2017-12-14 15:51:45 +01:00
|
|
|
dossier.en_construction!
|
2018-01-11 15:37:33 +01:00
|
|
|
post :update, params: { dossier_id: dossier_id }
|
2016-09-14 16:36:01 +02:00
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'Redirection vers la page récapitulatif' do
|
|
|
|
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'etat du dossier n\'est pas soumis' do
|
2017-12-04 16:17:15 +01:00
|
|
|
expect(dossier.state).not_to eq('brouillon')
|
2016-09-14 16:36:01 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'Quand la procédure accepte les CERFA' do
|
2018-01-11 15:37:33 +01:00
|
|
|
subject { post :update, params: { dossier_id: dossier_id, cerfa_pdf: cerfa_pdf } }
|
2016-12-26 11:33:12 +01:00
|
|
|
|
|
|
|
it 'Notification interne is create' do
|
|
|
|
expect { subject }.to change(Notification, :count).by (1)
|
|
|
|
end
|
|
|
|
|
2018-01-11 15:37:33 +01:00
|
|
|
context 'Sauvegarde du CERFA PDF', vcr: { cassette_name: 'controllers_users_description_controller_save_cerfa' } do
|
2016-09-14 16:36:01 +02:00
|
|
|
before do
|
2018-01-11 15:37:33 +01:00
|
|
|
post :update, params: { dossier_id: dossier_id, cerfa_pdf: cerfa_pdf }
|
2016-09-14 16:36:01 +02:00
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
2018-01-11 15:37:33 +01:00
|
|
|
context 'when a CERFA PDF is sent', vcr: { cassette_name: 'controllers_users_description_controller_cerfa_is_sent' } do
|
2016-09-14 16:36:01 +02:00
|
|
|
subject { dossier.cerfa.first }
|
|
|
|
|
|
|
|
it 'content' do
|
|
|
|
if Features.remote_storage
|
|
|
|
expect(subject['content']).to eq('cerfa-3dbb3535-5388-4a37-bc2d-778327b9f999.pdf')
|
|
|
|
else
|
|
|
|
expect(subject['content']).to eq('cerfa.pdf')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'dossier_id' do
|
|
|
|
expect(subject.dossier_id).to eq(dossier_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject.user).to eq user }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'les anciens CERFA PDF ne sont pas écrasées' do
|
|
|
|
let(:cerfas) { Cerfa.where(dossier_id: dossier_id) }
|
|
|
|
|
|
|
|
before do
|
2018-01-11 15:37:33 +01:00
|
|
|
post :update, params: { dossier_id: dossier_id, cerfa_pdf: cerfa_pdf }
|
2016-09-14 16:36:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "il y a deux CERFA PDF pour ce dossier" do
|
|
|
|
expect(cerfas.size).to eq 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'Quand la procédure n\'accepte pas les CERFA' do
|
|
|
|
context 'Sauvegarde du CERFA PDF' do
|
|
|
|
let!(:procedure) { create(:procedure) }
|
|
|
|
before do
|
2018-01-11 15:37:33 +01:00
|
|
|
post :update, params: { dossier_id: dossier_id, cerfa_pdf: cerfa_pdf }
|
2016-09-14 16:36:01 +02:00
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'un CERFA PDF est envoyé' do
|
|
|
|
it { expect(dossier.cerfa_available?).to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Sauvegarde des champs' do
|
|
|
|
let(:champs_dossier) { dossier.champs }
|
2017-09-08 11:01:31 +02:00
|
|
|
let(:dossier_text_value) { 'test value' }
|
2016-09-14 16:36:01 +02:00
|
|
|
let(:dossier_date_value) { '23/06/2016' }
|
|
|
|
let(:dossier_hour_value) { '17' }
|
|
|
|
let(:dossier_minute_value) { '00' }
|
2017-09-08 11:01:31 +02:00
|
|
|
let(:dossier_datetime_champ_id) { dossier.champs.find { |c| c.type_champ == "datetime" }.id }
|
|
|
|
let(:dossier_text_champ_id) { dossier.champs.find { |c| c.type_champ == "text" }.id }
|
|
|
|
let(:params) {
|
|
|
|
{
|
|
|
|
dossier_id: dossier_id,
|
|
|
|
champs: {
|
2018-01-11 15:37:33 +01:00
|
|
|
"'#{dossier_text_champ_id}'" => dossier_text_value,
|
2017-09-08 11:01:31 +02:00
|
|
|
"'#{dossier_datetime_champ_id}'" => dossier_date_value
|
|
|
|
},
|
|
|
|
time_hour: {
|
|
|
|
"'#{dossier_datetime_champ_id}'" => dossier_hour_value,
|
|
|
|
},
|
|
|
|
time_minute: {
|
|
|
|
"'#{dossier_datetime_champ_id}'" => dossier_minute_value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-14 16:36:01 +02:00
|
|
|
|
|
|
|
before do
|
2017-09-08 11:01:31 +02:00
|
|
|
post :update, params: params
|
2016-09-14 16:36:01 +02:00
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
2017-09-08 11:01:31 +02:00
|
|
|
it { expect(dossier.champs.find(dossier_text_champ_id).value).to eq(dossier_text_value) }
|
2016-09-14 16:36:01 +02:00
|
|
|
it { expect(response).to redirect_to users_dossier_recapitulatif_path }
|
|
|
|
|
|
|
|
context 'when champs is type_de_champ datetime' do
|
2018-01-15 21:41:16 +01:00
|
|
|
it { expect(dossier.champs.find(dossier_datetime_champ_id).value).to eq("#{dossier_date_value} #{dossier_hour_value}:#{dossier_minute_value}") }
|
2016-09-14 16:36:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when champs value is empty' do
|
2017-09-08 11:01:31 +02:00
|
|
|
let(:dossier_text_value) { '' }
|
2016-09-14 16:36:01 +02:00
|
|
|
|
2017-09-08 11:01:31 +02:00
|
|
|
it { expect(dossier.champs.find(dossier_text_champ_id).value).to eq(dossier_text_value) }
|
2016-09-14 16:36:01 +02:00
|
|
|
it { expect(response).to redirect_to users_dossier_recapitulatif_path }
|
|
|
|
|
|
|
|
context 'when champs is mandatory' do
|
|
|
|
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ_mandatory, :with_datetime, cerfa_flag: true) }
|
|
|
|
|
|
|
|
it { expect(response).not_to redirect_to users_dossier_recapitulatif_path }
|
|
|
|
it { expect(flash[:alert]).to be_present }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-11 15:37:33 +01:00
|
|
|
context 'Sauvegarde des pièces justificatives', vcr: { cassette_name: 'controllers_users_description_controller_sauvegarde_pj' } do
|
2016-09-14 16:36:01 +02:00
|
|
|
let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids }
|
|
|
|
before do
|
2018-01-15 15:34:26 +01:00
|
|
|
post :update, params: {
|
|
|
|
dossier_id: dossier_id,
|
|
|
|
'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0,
|
|
|
|
'piece_justificative_' + all_pj_type[1].to_s => piece_justificative_1
|
|
|
|
}
|
2016-09-14 16:36:01 +02:00
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
2018-01-11 15:37:33 +01:00
|
|
|
describe 'clamav anti-virus presence', vcr: { cassette_name: 'controllers_users_description_controller_clamav_presence' } do
|
2016-09-14 16:36:01 +02:00
|
|
|
it 'ClamavService safe_file? is call' do
|
|
|
|
expect(ClamavService).to receive(:safe_file?).twice
|
|
|
|
|
2018-01-15 15:34:26 +01:00
|
|
|
post :update, params: {
|
|
|
|
dossier_id: dossier_id,
|
|
|
|
'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0,
|
|
|
|
'piece_justificative_' + all_pj_type[1].to_s => piece_justificative_1
|
|
|
|
}
|
2016-09-14 16:36:01 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for piece 0' do
|
|
|
|
subject { dossier.retrieve_last_piece_justificative_by_type all_pj_type[0].to_s }
|
|
|
|
it { expect(subject.content).not_to be_nil }
|
|
|
|
it { expect(subject.user).to eq user }
|
|
|
|
end
|
|
|
|
context 'for piece 1' do
|
|
|
|
subject { dossier.retrieve_last_piece_justificative_by_type all_pj_type[1].to_s }
|
|
|
|
it { expect(subject.content).not_to be_nil }
|
|
|
|
it { expect(subject.user).to eq user }
|
|
|
|
end
|
|
|
|
end
|
2017-03-06 14:29:01 +01:00
|
|
|
|
|
|
|
context 'La procédure est archivée' do
|
2017-07-10 23:42:33 +02:00
|
|
|
let(:archived_at) { Time.now }
|
2017-03-06 14:29:01 +01:00
|
|
|
|
|
|
|
before do
|
|
|
|
post :update, params: { dossier_id: dossier.id }
|
|
|
|
end
|
|
|
|
|
2017-03-06 15:03:51 +01:00
|
|
|
it { expect(response.status).to eq(302) }
|
|
|
|
|
|
|
|
context 'Le dossier est en brouillon' do
|
2017-12-04 16:17:15 +01:00
|
|
|
let(:state) { 'brouillon' }
|
2017-03-06 15:03:51 +01:00
|
|
|
|
|
|
|
it { expect(response.status).to eq(403) }
|
|
|
|
end
|
2017-03-06 14:29:01 +01:00
|
|
|
end
|
2016-09-14 16:36:01 +02:00
|
|
|
end
|
|
|
|
|
2018-01-11 15:37:33 +01:00
|
|
|
describe 'POST #pieces_justificatives', vcr: { cassette_name: 'controllers_users_description_controller_pieces_justificatives' } do
|
2016-09-14 16:36:01 +02:00
|
|
|
let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids }
|
|
|
|
|
2018-01-15 15:34:26 +01:00
|
|
|
subject {
|
|
|
|
patch :pieces_justificatives, params: {
|
|
|
|
dossier_id: dossier.id,
|
|
|
|
'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0,
|
|
|
|
'piece_justificative_' + all_pj_type[1].to_s => piece_justificative_1
|
|
|
|
}
|
2017-06-12 14:10:49 +02:00
|
|
|
}
|
2016-09-14 16:36:01 +02:00
|
|
|
|
|
|
|
context 'when user is a guest' do
|
|
|
|
let(:guest) { create :user }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create :invite, dossier: dossier, email: guest.email, user: guest
|
|
|
|
|
|
|
|
sign_in guest
|
|
|
|
end
|
|
|
|
|
2016-12-26 11:42:02 +01:00
|
|
|
it 'Notification interne is create' do
|
|
|
|
expect { subject }.to change(Notification, :count).by (1)
|
|
|
|
end
|
|
|
|
|
2016-09-14 16:36:01 +02:00
|
|
|
context 'when PJ have no documents' do
|
|
|
|
it { expect(dossier.pieces_justificatives.size).to eq 0 }
|
|
|
|
|
|
|
|
context 'when upload two PJ' do
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(dossier.pieces_justificatives.size).to eq 2 }
|
|
|
|
it { expect(flash[:notice]).to be_present }
|
|
|
|
it { is_expected.to redirect_to users_dossiers_invite_path(id: guest.invites.find_by_dossier_id(dossier.id).id) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when PJ have already a document' do
|
|
|
|
before do
|
|
|
|
create :piece_justificative, :rib, dossier: dossier, type_de_piece_justificative_id: all_pj_type[0]
|
|
|
|
create :piece_justificative, :contrat, dossier: dossier, type_de_piece_justificative_id: all_pj_type[1]
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(dossier.pieces_justificatives.size).to eq 2 }
|
|
|
|
|
2018-01-11 15:37:33 +01:00
|
|
|
context 'when upload two PJ', vcr: { cassette_name: 'controllers_users_description_controller_upload_2pj' } do
|
2016-09-14 16:36:01 +02:00
|
|
|
before do
|
|
|
|
subject
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(dossier.pieces_justificatives.size).to eq 4 }
|
|
|
|
it { expect(flash[:notice]).to be_present }
|
|
|
|
it { is_expected.to redirect_to users_dossiers_invite_path(id: guest.invites.find_by_dossier_id(dossier.id).id) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when one of PJs is not valid' do
|
|
|
|
let(:piece_justificative_0) { Rack::Test::UploadedFile.new("./spec/support/files/entreprise.json", 'application/json') }
|
|
|
|
|
|
|
|
it { expect(dossier.pieces_justificatives.size).to eq 0 }
|
|
|
|
|
|
|
|
context 'when upload two PJ' do
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(dossier.pieces_justificatives.size).to eq 1 }
|
|
|
|
it { expect(flash[:alert]).to be_present }
|
|
|
|
it { is_expected.to redirect_to users_dossiers_invite_path(id: guest.invites.find_by_dossier_id(dossier.id).id) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'description_controller_spec_POST_piece_justificatives_for_owner' do
|
|
|
|
let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids }
|
|
|
|
|
2018-01-15 15:34:26 +01:00
|
|
|
subject {
|
|
|
|
patch :pieces_justificatives, params: {
|
|
|
|
dossier_id: dossier.id,
|
|
|
|
'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0,
|
|
|
|
'piece_justificative_' + all_pj_type[1].to_s => piece_justificative_1
|
|
|
|
}
|
2017-06-12 14:10:49 +02:00
|
|
|
}
|
2016-09-14 16:36:01 +02:00
|
|
|
|
2018-01-11 15:37:33 +01:00
|
|
|
context 'when user is the owner', vcr: { cassette_name: 'controllers_users_description_controller_pieces_justificatives' } do
|
2016-09-14 16:36:01 +02:00
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when PJ have no documents' do
|
|
|
|
it { expect(dossier.pieces_justificatives.size).to eq 0 }
|
|
|
|
|
|
|
|
context 'when upload two PJ' do
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(dossier.pieces_justificatives.size).to eq 2 }
|
|
|
|
it { expect(flash[:notice]).to be_present }
|
|
|
|
it { is_expected.to redirect_to recapitulatif_path }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-11 15:37:33 +01:00
|
|
|
context 'when PJ have already a document', vcr: { cassette_name: 'controllers_users_description_controller_pj_already_exist' } do
|
2016-09-14 16:36:01 +02:00
|
|
|
before do
|
|
|
|
create :piece_justificative, :rib, dossier: dossier, type_de_piece_justificative_id: all_pj_type[0]
|
|
|
|
create :piece_justificative, :contrat, dossier: dossier, type_de_piece_justificative_id: all_pj_type[1]
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(dossier.pieces_justificatives.size).to eq 2 }
|
|
|
|
|
2018-01-11 15:37:33 +01:00
|
|
|
context 'when upload two PJ', vcr: { cassette_name: 'controllers_users_description_controller_pj_already_exist_upload_2pj' } do
|
2016-09-14 16:36:01 +02:00
|
|
|
before do
|
|
|
|
subject
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(dossier.pieces_justificatives.size).to eq 4 }
|
|
|
|
it { expect(flash[:notice]).to be_present }
|
|
|
|
it { is_expected.to redirect_to recapitulatif_path }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when one of PJs is not valid' do
|
|
|
|
let(:piece_justificative_0) { Rack::Test::UploadedFile.new("./spec/support/files/entreprise.json", 'application/json') }
|
|
|
|
|
|
|
|
it { expect(dossier.pieces_justificatives.size).to eq 0 }
|
|
|
|
|
|
|
|
context 'when upload two PJ' do
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(dossier.pieces_justificatives.size).to eq 1 }
|
|
|
|
it { expect(flash[:alert]).to be_present }
|
|
|
|
it { is_expected.to redirect_to recapitulatif_path }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|