Ogni destinatario mostra se la mail è partita e se è stata aperta, con conteggi in dashboard. Co-authored-by: Cursor <cursoragent@cursor.com>
50 lines
2.0 KiB
Ruby
50 lines
2.0 KiB
Ruby
require "test_helper"
|
|
require "base64"
|
|
|
|
class CampaignMailerTest < ActionMailer::TestCase
|
|
test "sends html with merge and attachments from the identity" do
|
|
mailing = create_mailing
|
|
mailing.rebuild_recipients!
|
|
mailing.files.attach(io: StringIO.new("brochure"), filename: "brochure.pdf", content_type: "application/pdf")
|
|
recipient = mailing.mailing_recipients.first
|
|
|
|
email = CampaignMailer.outreach(
|
|
recipient,
|
|
html: recipient.rendered_html,
|
|
subject: recipient.rendered_subject_line
|
|
)
|
|
|
|
assert_emails 1 do
|
|
email.deliver_now
|
|
end
|
|
|
|
assert_equal ["hello@example.com"], email.from
|
|
assert_equal ["mario@asdtest.example.it"], email.to
|
|
assert_equal "Ciao ASD Test Calcio", email.subject
|
|
body = (email.html_part || email).body.to_s
|
|
assert_match(/Ciao Mario Rossi di ASD Test Calcio/, body)
|
|
recipient.reload
|
|
assert_match(%r{/t/o/#{Regexp.escape(recipient.tracking_token)}\.gif}, body)
|
|
assert_equal 1, email.attachments.size
|
|
assert_equal "brochure.pdf", email.attachments.first.filename
|
|
end
|
|
|
|
test "inlines active storage images as cid attachments" do
|
|
png = Base64.decode64("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==")
|
|
blob = ActiveStorage::Blob.create_and_upload!(io: StringIO.new(png), filename: "pixel.png", content_type: "image/png")
|
|
src = Rails.application.routes.url_helpers.rails_blob_path(blob, only_path: true)
|
|
mailing = create_mailing(body_html: %(<p>Foto</p><figure><img src="#{src}" width="240" height="120"></figure>))
|
|
mailing.rebuild_recipients!
|
|
recipient = mailing.mailing_recipients.first
|
|
|
|
email = CampaignMailer.outreach(recipient, html: recipient.rendered_html, subject: "Foto")
|
|
email.deliver_now
|
|
|
|
assert email.attachments.any? { |att| att.filename.to_s.include?("pixel.png") }
|
|
body = (email.html_part || email).body.to_s
|
|
assert_match(/cid:/, body)
|
|
assert_match(/width:\s*240px/, body)
|
|
assert_no_match(/<figure/, body)
|
|
end
|
|
end
|