hackatime/test/mailers/heartbeat_export_mailer_test.rb
Mahad Kalam d5d987a8f4
Email layout v2 (#1015)
* Better emails!

* Fix tests?

* bit o' cleanup

* add rant

* pt2

* pt3

* Update tests

* oop

* man what on earth

* ffs!!!!!

* Revert "ffs!!!!!"

This reverts commit b58bfed0f4c6288e95d0a111aeb3d7d7900ac9e7.

* Revert "man what on earth"

This reverts commit 8752cc2200eb3b852ea545d10ccbd555ab09d2b4.

* Revert "Fix tests?"

This reverts commit 810ebde73376ff7da0595e6b927f1b464d62b4a4.

* Ignore external Google Fonts link in premailer
2026-03-01 07:18:24 +00:00

40 lines
1.4 KiB
Ruby

require "test_helper"
class HeartbeatExportMailerTest < ActionMailer::TestCase
setup do
@user = User.create!(
timezone: "UTC",
slack_uid: "U#{SecureRandom.hex(5)}",
username: "mexp_#{SecureRandom.hex(4)}"
)
@recipient_email = "mailer-export-#{SecureRandom.hex(6)}@example.com"
end
test "export_ready builds recipient and includes download link" do
blob = ActiveStorage::Blob.create_and_upload!(
io: StringIO.new({ sample: true }.to_json),
filename: "heartbeats_test.zip",
content_type: "application/zip",
metadata: { "heartbeat_export" => true }
)
mail = HeartbeatExportMailer.export_ready(
@user,
recipient_email: @recipient_email,
blob_signed_id: blob.signed_id,
filename: "heartbeats_test.zip"
)
assert_equal [ @recipient_email ], mail.to
assert_equal "Your Hackatime heartbeat export is ready", mail.subject
assert_equal 0, mail.attachments.size
assert_includes mail.html_part.body.decoded, "Your heartbeat export is ready"
assert_includes mail.text_part.body.decoded, "Your heartbeat export (heartbeats_test.zip) is ready to download"
assert_includes mail.text_part.body.decoded, @user.display_name
assert_includes mail.text_part.body.decoded, "/rails/active_storage/"
assert_includes mail.text_part.body.decoded, "heartbeats_test.zip"
blob.purge
end
end