Include autenticazione, progetti isolati, mail marketing HTML con SMTP, test A/B e editor WYSIWYG. Co-authored-by: Cursor <cursoragent@cursor.com>
108 lines
3.6 KiB
Ruby
108 lines
3.6 KiB
Ruby
require "test_helper"
|
|
|
|
class MailingsControllerTest < ActionDispatch::IntegrationTest
|
|
setup do
|
|
@project = projects(:matchlivetv)
|
|
@identity = create_mail_identity
|
|
opportunities(:deal).update!(send_status: "to_send", pipeline_stage: "to_contact")
|
|
end
|
|
|
|
test "lists mailings in project space" do
|
|
login_as users(:admin)
|
|
follow_redirect! if response.redirect?
|
|
|
|
get mailings_path(project_code: @project.code)
|
|
assert_response :success
|
|
assert_match(/Email/, response.body)
|
|
end
|
|
|
|
test "creates a draft and builds recipients" do
|
|
login_as users(:admin)
|
|
follow_redirect! if response.redirect?
|
|
|
|
assert_difference -> { Mailing.count } => 1, -> { MailingRecipient.count } => 1 do
|
|
post mailings_path(project_code: @project.code), params: {
|
|
mailing: {
|
|
name: "Lancio",
|
|
mail_identity_id: @identity.id,
|
|
audience: "to_send",
|
|
subject: "Ciao {{societa}}",
|
|
body_html: "<p>Ciao {{contatto_nome}}</p>",
|
|
interval_seconds: 0
|
|
}
|
|
}
|
|
end
|
|
mailing = Mailing.last
|
|
assert_redirected_to mailing_path(mailing, project_code: @project.code)
|
|
assert_equal "pending", mailing.mailing_recipients.first.status
|
|
end
|
|
|
|
test "check recipients then queue send" do
|
|
login_as users(:admin)
|
|
follow_redirect! if response.redirect?
|
|
mailing = create_mailing(identity: @identity, audience: "to_send")
|
|
mailing.rebuild_recipients!
|
|
recipient = mailing.mailing_recipients.first
|
|
|
|
patch update_recipients_mailing_path(mailing, project_code: @project.code), params: { pending_ids: [recipient.id] }
|
|
assert_redirected_to mailing_path(mailing, project_code: @project.code)
|
|
assert_equal "pending", recipient.reload.status
|
|
|
|
perform_enqueued_jobs do
|
|
post queue_mailing_path(mailing, project_code: @project.code)
|
|
end
|
|
|
|
assert_equal "sent", mailing.reload.status
|
|
assert_equal "sent", recipient.reload.status
|
|
assert_equal "sent", opportunities(:deal).reload.send_status
|
|
assert_equal "contacted", opportunities(:deal).pipeline_stage
|
|
assert_equal 1, ActionMailer::Base.deliveries.size
|
|
assert_equal "Ciao ASD Test Calcio", ActionMailer::Base.deliveries.last.subject
|
|
end
|
|
|
|
test "test send goes to current user" do
|
|
login_as users(:admin)
|
|
follow_redirect! if response.redirect?
|
|
mailing = create_mailing(identity: @identity, audience: "all")
|
|
mailing.rebuild_recipients!
|
|
|
|
assert_emails 1 do
|
|
post test_send_mailing_path(mailing, project_code: @project.code)
|
|
end
|
|
mail = ActionMailer::Base.deliveries.last
|
|
assert_equal [users(:admin).email], mail.to
|
|
assert_match(/\[TEST\]/, mail.subject)
|
|
end
|
|
|
|
test "creates an A/B mailing and sends variant B as test" do
|
|
login_as users(:admin)
|
|
follow_redirect! if response.redirect?
|
|
|
|
post mailings_path(project_code: @project.code), params: {
|
|
mailing: {
|
|
name: "AB lancio",
|
|
mail_identity_id: @identity.id,
|
|
audience: "to_send",
|
|
ab_test: "1",
|
|
ab_assignment: "from_record",
|
|
subject: "Oggetto A {{societa}}",
|
|
body_html: "<p>Versione A</p>",
|
|
subject_b: "Oggetto B {{societa}}",
|
|
body_html_b: "<p>Versione B</p>",
|
|
interval_seconds: 0
|
|
}
|
|
}
|
|
mailing = Mailing.last
|
|
assert mailing.ab_test?
|
|
assert_equal "A", mailing.mailing_recipients.first.ab_variant
|
|
|
|
assert_emails 1 do
|
|
post test_send_mailing_path(mailing, project_code: @project.code, variant: "B")
|
|
end
|
|
mail = ActionMailer::Base.deliveries.last
|
|
assert_match(/\[TEST B\] Oggetto B ASD Test Calcio/, mail.subject)
|
|
body = (mail.html_part || mail).body.to_s
|
|
assert_match(/Versione B/, body)
|
|
end
|
|
end
|