2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2022-11-15 16:12:45 +01:00
|
|
|
|
include ActionView::Helpers::SanitizeHelper
|
|
|
|
|
|
|
|
|
|
describe Manager::DossiersController, type: :controller do
|
|
|
|
|
let(:super_admin) { create(:super_admin) }
|
|
|
|
|
before do
|
|
|
|
|
sign_in super_admin
|
|
|
|
|
procedure = create(:procedure, :published, types_de_champ_public: types_de_champ)
|
|
|
|
|
@dossier = create(:dossier, :en_construction, :with_populated_champs, procedure:)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:types_de_champ) { [] }
|
|
|
|
|
|
|
|
|
|
render_views
|
|
|
|
|
|
|
|
|
|
describe 'GET #index' do
|
|
|
|
|
it "should list dossiers" do
|
|
|
|
|
get :index
|
|
|
|
|
expect(response.body).to include(@dossier.procedure.libelle)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "GET #show" do
|
|
|
|
|
let(:types_de_champ) {
|
|
|
|
|
[
|
|
|
|
|
{ libelle: "Nom", mandatory: true }
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
get :show, params: { id: @dossier.id }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
subject { strip_tags(response.body) }
|
|
|
|
|
|
2022-11-28 17:41:46 +01:00
|
|
|
|
it { expect(subject).to match(%r{Nom\s+\*\s+Texte court\s+🟢\s+rempli}) }
|
2022-11-15 16:12:45 +01:00
|
|
|
|
end
|
2023-11-27 11:19:32 +01:00
|
|
|
|
|
|
|
|
|
describe "POST #transfer" do
|
2024-01-24 16:02:09 +01:00
|
|
|
|
subject do
|
2023-11-27 11:19:32 +01:00
|
|
|
|
post :transfer, params: { id: @dossier.id, email: }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with valid email' do
|
|
|
|
|
let(:email) { "chouette.gars@laposte.net" }
|
|
|
|
|
|
2024-01-24 16:02:09 +01:00
|
|
|
|
it do
|
|
|
|
|
expect { subject }.to have_enqueued_mail(DossierMailer, :notify_transfer)
|
|
|
|
|
expect(flash[:success]).to eq("Une invitation de transfert a été envoyée à chouette.gars@laposte.net")
|
|
|
|
|
end
|
2023-11-27 11:19:32 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with invalid email' do
|
|
|
|
|
let(:email) { "chouette" }
|
|
|
|
|
|
2024-01-24 16:02:09 +01:00
|
|
|
|
it do
|
|
|
|
|
expect { subject }.not_to have_enqueued_mail
|
2024-07-25 12:14:52 +02:00
|
|
|
|
expect(flash[:alert]).to eq("L’adresse email est invalide. Saisir une adresse électronique valide, exemple : adresse@mail.com")
|
2024-01-24 16:02:09 +01:00
|
|
|
|
end
|
2023-11-27 11:19:32 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2023-11-28 09:04:36 +01:00
|
|
|
|
|
|
|
|
|
describe "DELETE #transfer_destroy" do
|
|
|
|
|
before do
|
|
|
|
|
DossierTransfer.create(email: 'coucou@laposte.net', dossiers: [@dossier])
|
|
|
|
|
delete :transfer_destroy, params: { id: @dossier.id }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(@dossier.transfer).to be_nil }
|
|
|
|
|
it { expect(flash[:notice]).to eq "La demande de transfert a été supprimée avec succès" }
|
|
|
|
|
end
|
2022-11-15 16:12:45 +01:00
|
|
|
|
end
|