Completa UI e test del form contatti.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe "Public contacts page", type: :request do
|
||||
let(:valid_params) do
|
||||
{
|
||||
name: "Mario Rossi",
|
||||
email: "mario@test.it",
|
||||
club_name: "Volley Club",
|
||||
topic: "commercial",
|
||||
message: "Vorremmo un preventivo per tre squadre della società.",
|
||||
accept_privacy: "1"
|
||||
}
|
||||
end
|
||||
|
||||
it "è pubblica, indicizzabile e mostra i recapiti" do
|
||||
get public_contatti_path
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include(I18n.t("pages.contacts.title", locale: :it))
|
||||
expect(response.body).to include(MatchLiveTv.support_email)
|
||||
expect(response.body).to include(MatchLiveTv.privacy_controller_email)
|
||||
expect(response.body).to include(MatchLiveTv.privacy_controller_name)
|
||||
expect(response.body).to include(MatchLiveTv.privacy_controller_address)
|
||||
expect(response.body).to include('rel="canonical"')
|
||||
expect(response.body).to include(public_contatti_path)
|
||||
expect(response.body).to include(public_support_path)
|
||||
expect(response.body).to include(public_faq_path)
|
||||
expect(response.body).to include(public_signup_path)
|
||||
expect(response.body).not_to include("translation missing")
|
||||
end
|
||||
|
||||
it "appare nel footer del sito, non nel chrome App Store" do
|
||||
get root_path
|
||||
expect(response.body).to include(public_contatti_path)
|
||||
|
||||
get public_support_path
|
||||
expect(response.body).not_to include(public_contatti_path)
|
||||
end
|
||||
|
||||
it "collega il CTA Prezzi alla pagina contatti" do
|
||||
load Rails.root.join("db/seeds/plans.rb")
|
||||
get public_prezzi_path
|
||||
|
||||
expect(response.body).to include(public_contatti_path)
|
||||
expect(response.body).not_to include("mailto:info@matchlivetv.it")
|
||||
end
|
||||
|
||||
it "include /contatti nella sitemap e reindirizza /contact" do
|
||||
get "/sitemap.xml"
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include("#{MatchLiveTv.app_public_url.chomp('/')}/contatti")
|
||||
|
||||
get "/contact"
|
||||
expect(response).to redirect_to("/contatti")
|
||||
end
|
||||
|
||||
{
|
||||
"it" => "Contatti",
|
||||
"en" => "Contact",
|
||||
"fr" => "Contact",
|
||||
"de" => "Kontakt",
|
||||
"es" => "Contacto"
|
||||
}.each do |locale, heading|
|
||||
it "renderizza correttamente in #{locale} senza translation missing" do
|
||||
cookies[:mltv_locale] = locale
|
||||
get public_contatti_path
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include(heading)
|
||||
expect(response.body).not_to include("translation missing")
|
||||
end
|
||||
end
|
||||
|
||||
it "invia la mail commerciale a info@ con reply-to del mittente" do
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
expect {
|
||||
post public_contatti_path, params: valid_params
|
||||
}.to change { ActionMailer::Base.deliveries.size }.by(1)
|
||||
|
||||
expect(response).to redirect_to(public_contatti_path)
|
||||
expect(flash[:notice]).to eq(I18n.t("flash.contacts.sent", locale: :it))
|
||||
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
expect(mail.to).to eq([MatchLiveTv.support_email])
|
||||
expect(mail.reply_to).to eq(["mario@test.it"])
|
||||
expect(mail.subject).to include("Mario Rossi")
|
||||
expect(mail.body.encoded).to include("Volley Club")
|
||||
expect(mail.body.encoded).to include("tre squadre")
|
||||
end
|
||||
|
||||
it "invia le richieste privacy all'email privacy" do
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
post public_contatti_path, params: valid_params.merge(topic: "privacy")
|
||||
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
expect(mail.to).to eq([MatchLiveTv.privacy_controller_email])
|
||||
expect(mail.subject).to include("privacy")
|
||||
end
|
||||
|
||||
it "non invia mail se il honeypot è compilato, ma risponde come successo" do
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
expect {
|
||||
post public_contatti_path, params: valid_params.merge(website: "http://spam.test")
|
||||
}.not_to change { ActionMailer::Base.deliveries.size }
|
||||
|
||||
expect(response).to redirect_to(public_contatti_path)
|
||||
end
|
||||
|
||||
it "rifiuta un modulo incompleto" do
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
post public_contatti_path, params: valid_params.merge(name: "", accept_privacy: "1")
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(ActionMailer::Base.deliveries).to be_empty
|
||||
expect(flash[:alert]).to eq(I18n.t("flash.contacts.invalid", locale: :it))
|
||||
end
|
||||
|
||||
it "rifiuta senza consenso privacy" do
|
||||
post public_contatti_path, params: valid_params.merge(accept_privacy: "0")
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(flash[:alert]).to eq(I18n.t("flash.contacts.privacy_required", locale: :it))
|
||||
end
|
||||
|
||||
it "limita gli invii ripetuti dallo stesso IP" do
|
||||
previous = Rails.cache
|
||||
Rails.cache = ActiveSupport::Cache::MemoryStore.new
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
Contacts::SubmitInquiry::LIMIT.times do
|
||||
post public_contatti_path, params: valid_params
|
||||
expect(response).to redirect_to(public_contatti_path)
|
||||
end
|
||||
|
||||
post public_contatti_path, params: valid_params.merge(email: "altro@test.it")
|
||||
|
||||
expect(response).to have_http_status(:too_many_requests)
|
||||
expect(flash[:alert]).to eq(I18n.t("flash.contacts.throttled", locale: :it))
|
||||
expect(ActionMailer::Base.deliveries.size).to eq(Contacts::SubmitInquiry::LIMIT)
|
||||
ensure
|
||||
Rails.cache = previous
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user