Files
eminuxCRM/test/controllers/mail_opens_controller_test.rb
eminuxandCursor 2db7504629
CI / scan_ruby (push) Failing after 12m56s
CI / scan_js (push) Successful in 12m23s
CI / lint (push) Failing after 12m15s
Aggiunge il rilevamento di invio e apertura delle email di campagna.
Ogni destinatario mostra se la mail è partita e se è stata aperta, con conteggi in dashboard.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-20 12:26:14 +02:00

52 lines
1.7 KiB
Ruby

require "test_helper"
class MailOpensControllerTest < ActionDispatch::IntegrationTest
setup do
opportunities(:deal).update!(send_status: "to_send")
@mailing = create_mailing(audience: "to_send")
@mailing.rebuild_recipients!
@recipient = @mailing.mailing_recipients.first
@recipient.update!(status: "sent", sent_at: Time.current, rendered_subject: "Ciao ASD Test Calcio")
end
test "records the first open without login and returns a gif" do
assert_difference -> { Activity.where(activity_type: "email_opened").count }, 1 do
get mail_open_path(@recipient.tracking_token)
end
assert_response :success
assert_equal "image/gif", response.media_type
@recipient.reload
assert @recipient.opened?
assert_equal 1, @recipient.open_count
assert_equal @recipient.opened_at, @recipient.last_opened_at
end
test "counts later loads without duplicating the timeline activity" do
get mail_open_path(@recipient.tracking_token)
assert_no_difference -> { Activity.where(activity_type: "email_opened").count } do
get mail_open_path(@recipient.tracking_token)
end
@recipient.reload
assert_equal 2, @recipient.open_count
assert @recipient.last_opened_at >= @recipient.opened_at
end
test "unknown token still returns a gif" do
get mail_open_path("missing-token-value-here")
assert_response :success
assert_equal "image/gif", response.media_type
end
test "does not mark pending emails as opened" do
@recipient.update!(status: "pending", sent_at: nil)
get mail_open_path(@recipient.tracking_token)
assert_response :success
@recipient.reload
assert_not @recipient.opened?
assert_equal 0, @recipient.open_count
end
end