2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-07-31 16:20:49 +02:00
|
|
|
|
describe ContactController, question_type: :controller do
|
2018-08-29 11:44:12 +02:00
|
|
|
|
render_views
|
|
|
|
|
|
|
|
|
|
context 'signed in' do
|
|
|
|
|
before do
|
|
|
|
|
sign_in user
|
|
|
|
|
end
|
2019-01-21 17:34:19 +01:00
|
|
|
|
|
2018-08-29 11:44:12 +02:00
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
2018-08-30 15:08:26 +02:00
|
|
|
|
it 'should not have email field' do
|
|
|
|
|
get :index
|
|
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
2024-07-24 17:18:02 +02:00
|
|
|
|
expect(response.body).not_to have_content("Votre adresse email")
|
2018-08-30 15:08:26 +02:00
|
|
|
|
end
|
|
|
|
|
|
2018-08-29 11:44:12 +02:00
|
|
|
|
describe "with dossier" do
|
|
|
|
|
let(:user) { dossier.user }
|
|
|
|
|
let(:dossier) { create(:dossier) }
|
|
|
|
|
|
|
|
|
|
it 'should fill dossier_id' do
|
|
|
|
|
get :index, params: { dossier_id: dossier.id }
|
|
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
2018-10-01 14:03:05 +02:00
|
|
|
|
expect(response.body).to include((dossier.id).to_s)
|
2018-08-29 11:44:12 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-08-30 15:08:26 +02:00
|
|
|
|
describe "with tag" do
|
2018-08-29 11:44:12 +02:00
|
|
|
|
let(:tag) { 'yolo' }
|
|
|
|
|
|
|
|
|
|
it 'should fill tags' do
|
|
|
|
|
get :index, params: { tags: [tag] }
|
|
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
expect(response.body).to include(tag)
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-08-30 13:48:03 +02:00
|
|
|
|
|
|
|
|
|
describe "with multiple tags" do
|
|
|
|
|
let(:tags) { ['yolo', 'toto'] }
|
|
|
|
|
|
|
|
|
|
it 'should fill tags' do
|
|
|
|
|
get :index, params: { tags: tags }
|
|
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
2024-07-30 19:14:04 +02:00
|
|
|
|
expect(response.body).to include("value=\"yolo\"")
|
|
|
|
|
expect(response.body).to include("value=\"toto\"")
|
2018-08-30 13:48:03 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2018-08-30 16:12:40 +02:00
|
|
|
|
|
|
|
|
|
describe "send form" do
|
2019-01-21 17:34:19 +01:00
|
|
|
|
subject do
|
2024-07-30 19:14:04 +02:00
|
|
|
|
post :create, params: { contact_form: params }
|
2019-01-21 17:34:19 +01:00
|
|
|
|
end
|
|
|
|
|
|
2021-12-29 14:00:47 +01:00
|
|
|
|
context "when invisible captcha is ignored" do
|
2024-07-30 19:14:04 +02:00
|
|
|
|
let(:params) { { subject: 'bonjour', text: 'un message', question_type: 'procedure_info' } }
|
2019-01-21 17:34:19 +01:00
|
|
|
|
|
|
|
|
|
it 'creates a conversation on HelpScout' do
|
2024-06-13 13:27:32 +02:00
|
|
|
|
expect { subject }.to \
|
|
|
|
|
change(Commentaire, :count).by(0).and \
|
2024-07-30 19:14:04 +02:00
|
|
|
|
change(ContactForm, :count).by(1)
|
|
|
|
|
|
|
|
|
|
contact_form = ContactForm.last
|
|
|
|
|
expect(HelpscoutCreateConversationJob).to have_been_enqueued.with(contact_form)
|
|
|
|
|
|
|
|
|
|
expect(contact_form.subject).to eq("bonjour")
|
|
|
|
|
expect(contact_form.text).to eq("un message")
|
|
|
|
|
expect(contact_form.tags).to include("procedure_info")
|
2018-08-30 16:12:40 +02:00
|
|
|
|
|
|
|
|
|
expect(flash[:notice]).to match('Votre message a été envoyé.')
|
2024-07-24 17:18:02 +02:00
|
|
|
|
expect(response).to redirect_to root_path
|
2018-08-30 16:12:40 +02:00
|
|
|
|
end
|
2019-01-21 17:34:19 +01:00
|
|
|
|
|
2021-12-29 14:00:47 +01:00
|
|
|
|
context 'when a drafted dossier is mentionned' do
|
|
|
|
|
let(:dossier) { create(:dossier) }
|
|
|
|
|
let(:user) { dossier.user }
|
|
|
|
|
|
2024-07-24 17:18:02 +02:00
|
|
|
|
let(:params) do
|
|
|
|
|
{
|
2021-12-29 14:00:47 +01:00
|
|
|
|
dossier_id: dossier.id,
|
2024-07-30 19:14:04 +02:00
|
|
|
|
question_type: ContactForm::TYPE_INSTRUCTION,
|
2021-12-29 14:00:47 +01:00
|
|
|
|
subject: 'bonjour',
|
|
|
|
|
text: 'un message'
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'creates a conversation on HelpScout' do
|
2024-06-13 13:27:32 +02:00
|
|
|
|
expect { subject }.to \
|
|
|
|
|
change(Commentaire, :count).by(0).and \
|
2024-07-30 19:14:04 +02:00
|
|
|
|
change(ContactForm, :count).by(1)
|
|
|
|
|
|
|
|
|
|
contact_form = ContactForm.last
|
|
|
|
|
expect(HelpscoutCreateConversationJob).to have_been_enqueued.with(contact_form)
|
|
|
|
|
expect(contact_form.dossier_id).to eq(dossier.id)
|
2021-12-29 14:00:47 +01:00
|
|
|
|
|
|
|
|
|
expect(flash[:notice]).to match('Votre message a été envoyé.')
|
2024-07-24 17:18:02 +02:00
|
|
|
|
expect(response).to redirect_to root_path
|
2021-12-29 14:00:47 +01:00
|
|
|
|
end
|
2019-01-21 17:34:19 +01:00
|
|
|
|
end
|
2018-08-30 16:12:40 +02:00
|
|
|
|
|
2021-12-29 14:00:47 +01:00
|
|
|
|
context 'when a submitted dossier is mentionned' do
|
|
|
|
|
let(:dossier) { create(:dossier, :en_construction) }
|
|
|
|
|
let(:user) { dossier.user }
|
|
|
|
|
|
2024-07-24 17:18:02 +02:00
|
|
|
|
let(:params) do
|
|
|
|
|
{
|
2021-12-29 14:00:47 +01:00
|
|
|
|
dossier_id: dossier.id,
|
2024-07-30 19:14:04 +02:00
|
|
|
|
question_type: ContactForm::TYPE_INSTRUCTION,
|
2021-12-29 14:00:47 +01:00
|
|
|
|
subject: 'bonjour',
|
|
|
|
|
text: 'un message'
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'posts the message to the dossier messagerie' do
|
|
|
|
|
expect { subject }.to change(Commentaire, :count).by(1)
|
2024-06-13 13:27:32 +02:00
|
|
|
|
assert_no_enqueued_jobs(only: HelpscoutCreateConversationJob)
|
2018-08-30 16:12:40 +02:00
|
|
|
|
|
2021-12-29 14:00:47 +01:00
|
|
|
|
expect(Commentaire.last.email).to eq(user.email)
|
|
|
|
|
expect(Commentaire.last.dossier).to eq(dossier)
|
|
|
|
|
expect(Commentaire.last.body).to include('[bonjour]')
|
|
|
|
|
expect(Commentaire.last.body).to include('un message')
|
|
|
|
|
|
|
|
|
|
expect(flash[:notice]).to match('Votre message a été envoyé sur la messagerie de votre dossier.')
|
|
|
|
|
expect(response).to redirect_to messagerie_dossier_path(dossier)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-08-30 16:12:40 +02:00
|
|
|
|
|
2021-12-29 14:00:47 +01:00
|
|
|
|
context "when invisible captcha is filled" do
|
2024-07-24 17:18:02 +02:00
|
|
|
|
subject do
|
|
|
|
|
post :create, params: {
|
2024-07-30 19:14:04 +02:00
|
|
|
|
contact_form: { subject: 'bonjour', text: 'un message', question_type: 'procedure_info' },
|
2024-07-24 17:18:02 +02:00
|
|
|
|
InvisibleCaptcha.honeypots.sample => 'boom'
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2021-12-29 14:00:47 +01:00
|
|
|
|
it 'does not create a conversation on HelpScout' do
|
|
|
|
|
expect { subject }.not_to change(Commentaire, :count)
|
2022-07-28 12:31:55 +02:00
|
|
|
|
expect(flash[:alert]).to eq(I18n.t('invisible_captcha.sentence_for_humans'))
|
2018-08-30 16:12:40 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-08-29 11:44:12 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'signed out' do
|
|
|
|
|
describe "with dossier" do
|
|
|
|
|
it 'should have email field' do
|
|
|
|
|
get :index
|
|
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
2024-07-24 17:18:02 +02:00
|
|
|
|
expect(response.body).to have_text("Votre adresse email")
|
2018-08-29 11:44:12 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "with dossier" do
|
|
|
|
|
let(:tag) { 'yolo' }
|
|
|
|
|
|
|
|
|
|
it 'should fill tags' do
|
|
|
|
|
get :index, params: { tags: [tag] }
|
|
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
expect(response.body).to include(tag)
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-07-24 17:18:02 +02:00
|
|
|
|
|
|
|
|
|
describe 'send form' do
|
|
|
|
|
subject do
|
2024-07-30 19:14:04 +02:00
|
|
|
|
post :create, params: { contact_form: params }
|
2024-07-24 17:18:02 +02:00
|
|
|
|
end
|
|
|
|
|
|
2024-07-30 19:14:04 +02:00
|
|
|
|
let(:params) { { subject: 'bonjour', email: "me@rspec.net", text: 'un message', question_type: 'procedure_info' } }
|
2024-07-24 17:18:02 +02:00
|
|
|
|
|
|
|
|
|
it 'creates a conversation on HelpScout' do
|
|
|
|
|
expect { subject }.to \
|
|
|
|
|
change(Commentaire, :count).by(0).and \
|
2024-07-30 19:14:04 +02:00
|
|
|
|
change(ContactForm, :count).by(1)
|
|
|
|
|
|
|
|
|
|
contact_form = ContactForm.last
|
|
|
|
|
expect(HelpscoutCreateConversationJob).to have_been_enqueued.with(contact_form)
|
|
|
|
|
expect(contact_form.email).to eq("me@rspec.net")
|
2024-07-24 17:18:02 +02:00
|
|
|
|
|
|
|
|
|
expect(flash[:notice]).to match('Votre message a été envoyé.')
|
|
|
|
|
expect(response).to redirect_to root_path
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "when email is invalid" do
|
|
|
|
|
let(:params) { super().merge(email: "me@rspec") }
|
|
|
|
|
|
|
|
|
|
it 'creates a conversation on HelpScout' do
|
|
|
|
|
expect { subject }.not_to have_enqueued_job(HelpscoutCreateConversationJob)
|
|
|
|
|
expect(response.body).to include("Le champ « Votre adresse email » est invalide")
|
|
|
|
|
expect(response.body).to include("bonjour")
|
|
|
|
|
expect(response.body).to include("un message")
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-11-19 16:29:19 +01:00
|
|
|
|
|
|
|
|
|
context "with an invalid attachment type" do
|
|
|
|
|
let(:params) { super().merge(piece_jointe: "not_a_file") }
|
|
|
|
|
|
|
|
|
|
it "returns unprocessable entity status" do
|
|
|
|
|
subject
|
|
|
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
|
|
|
|
expect(response.body).to include("La pièce jointe doit être un fichier")
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-07-24 17:18:02 +02:00
|
|
|
|
end
|
2018-08-29 11:44:12 +02:00
|
|
|
|
end
|
2022-09-05 15:30:59 +02:00
|
|
|
|
|
|
|
|
|
context 'contact admin' do
|
2024-07-30 19:14:04 +02:00
|
|
|
|
context 'index' do
|
|
|
|
|
it 'should have professionnal email field' do
|
|
|
|
|
get :admin
|
|
|
|
|
expect(response.body).to have_text('Votre adresse email professionnelle')
|
|
|
|
|
expect(response.body).to have_text('téléphone')
|
|
|
|
|
expect(response.body).to include('for_admin')
|
|
|
|
|
end
|
2022-09-05 15:30:59 +02:00
|
|
|
|
end
|
|
|
|
|
|
2024-07-30 19:14:04 +02:00
|
|
|
|
context 'create' do
|
|
|
|
|
subject do
|
|
|
|
|
post :create, params: { contact_form: params }
|
2022-09-05 15:30:59 +02:00
|
|
|
|
end
|
2024-06-13 13:27:32 +02:00
|
|
|
|
|
2024-07-30 19:14:04 +02:00
|
|
|
|
let(:params) { { for_admin: "true", email: "email@pro.fr", subject: 'bonjour', text: 'un message', question_type: 'admin question', phone: '06' } }
|
2024-06-13 13:27:32 +02:00
|
|
|
|
|
2024-07-30 19:14:04 +02:00
|
|
|
|
describe "when form is filled" do
|
|
|
|
|
it "creates a conversation on HelpScout" do
|
|
|
|
|
expect { subject }.to change(ContactForm, :count).by(1)
|
|
|
|
|
|
|
|
|
|
contact_form = ContactForm.last
|
|
|
|
|
expect(HelpscoutCreateConversationJob).to have_been_enqueued.with(contact_form)
|
|
|
|
|
expect(contact_form.email).to eq(params[:email])
|
|
|
|
|
expect(contact_form.phone).to eq("06")
|
|
|
|
|
expect(contact_form.tags).to match_array(["admin question", "contact form"])
|
|
|
|
|
|
|
|
|
|
expect(flash[:notice]).to match('Votre message a été envoyé.')
|
2024-06-13 13:27:32 +02:00
|
|
|
|
end
|
2022-09-05 15:30:59 +02:00
|
|
|
|
|
2024-07-30 19:14:04 +02:00
|
|
|
|
context "with a piece justificative" do
|
|
|
|
|
let(:logo) { fixture_file_upload('spec/fixtures/files/white.png', 'image/png') }
|
|
|
|
|
let(:params) { super().merge(piece_jointe: logo) }
|
|
|
|
|
|
|
|
|
|
it "create blob and pass it to conversation job" do
|
|
|
|
|
expect { subject }.to change(ContactForm, :count).by(1)
|
|
|
|
|
|
|
|
|
|
contact_form = ContactForm.last
|
|
|
|
|
expect(contact_form.piece_jointe).to be_attached
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-07-24 17:18:02 +02:00
|
|
|
|
end
|
2022-09-05 15:30:59 +02:00
|
|
|
|
|
2024-07-30 19:14:04 +02:00
|
|
|
|
describe "when invisible captcha is filled" do
|
|
|
|
|
subject do
|
|
|
|
|
post :create, params: { contact_form: params, InvisibleCaptcha.honeypots.sample => 'boom' }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'does not create a conversation on HelpScout' do
|
|
|
|
|
subject
|
|
|
|
|
expect(flash[:alert]).to eq(I18n.t('invisible_captcha.sentence_for_humans'))
|
|
|
|
|
end
|
2022-09-05 15:30:59 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-08-29 11:44:12 +02:00
|
|
|
|
end
|