Include autenticazione, progetti isolati, mail marketing HTML con SMTP, test A/B e editor WYSIWYG. Co-authored-by: Cursor <cursoragent@cursor.com>
76 lines
2.6 KiB
Ruby
76 lines
2.6 KiB
Ruby
require "test_helper"
|
|
|
|
class MailingsRecipientBuilderTest < ActiveSupport::TestCase
|
|
setup do
|
|
opportunities(:deal).update!(send_status: "to_send", ab_variant: "A")
|
|
end
|
|
|
|
test "audience to_send includes only pending campaign orgs with valid email" do
|
|
mailing = create_mailing(audience: "to_send")
|
|
mailing.rebuild_recipients!
|
|
|
|
recipient = mailing.mailing_recipients.find_by!(organization: organizations(:acme))
|
|
assert_equal "pending", recipient.status
|
|
assert_equal "mario@asdtest.example.it", recipient.email
|
|
end
|
|
|
|
test "skips organizations without email" do
|
|
org = organizations(:acme)
|
|
org.update!(email: nil)
|
|
org.contacts.update_all(email: nil)
|
|
|
|
mailing = create_mailing(audience: "all")
|
|
mailing.rebuild_recipients!
|
|
|
|
recipient = mailing.mailing_recipients.find_by!(organization: org)
|
|
assert_equal "skipped", recipient.status
|
|
assert_equal "manca email", recipient.skip_reason
|
|
end
|
|
|
|
test "audience test_a filters by variant" do
|
|
mailing = create_mailing(audience: "test_a")
|
|
mailing.rebuild_recipients!
|
|
assert_equal 1, mailing.mailing_recipients.count
|
|
|
|
mailing.update!(audience: "test_b")
|
|
mailing.rebuild_recipients!
|
|
assert_equal 0, mailing.mailing_recipients.count
|
|
end
|
|
|
|
test "ab test from_record uses opportunity variant" do
|
|
create_campaign_org(name: "Beta Volley", email: "beta@example.com", ab_variant: "B", list_position: 2)
|
|
mailing = create_mailing(
|
|
audience: "all",
|
|
ab_test: true,
|
|
ab_assignment: "from_record",
|
|
subject_b: "Offerta B {{societa}}",
|
|
body_html_b: "<p>Versione B</p>"
|
|
)
|
|
mailing.rebuild_recipients!
|
|
|
|
acme = mailing.mailing_recipients.find_by!(organization: organizations(:acme))
|
|
beta = mailing.mailing_recipients.joins(:organization).find_by!(organizations: { name: "Beta Volley" })
|
|
assert_equal "A", acme.ab_variant
|
|
assert_equal "B", beta.ab_variant
|
|
assert_match(/Ciao Mario Rossi/, acme.rendered_html)
|
|
assert_equal "Offerta B Beta Volley", beta.rendered_subject_line
|
|
assert_match(/Versione B/, beta.rendered_html)
|
|
end
|
|
|
|
test "ab test split alternates A and B" do
|
|
create_campaign_org(name: "Beta Volley", email: "beta@example.com", ab_variant: "A", list_position: 2)
|
|
organizations(:acme).update!(list_position: 1)
|
|
mailing = create_mailing(
|
|
audience: "all",
|
|
ab_test: true,
|
|
ab_assignment: "split",
|
|
subject_b: "B {{societa}}",
|
|
body_html_b: "<p>B</p>"
|
|
)
|
|
mailing.rebuild_recipients!
|
|
|
|
variants = mailing.mailing_recipients.pending.ordered.map(&:ab_variant)
|
|
assert_equal %w[A B], variants
|
|
end
|
|
end
|