mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-19 16:38:23 +00:00
* Fix data export + Capybara * Continue? * A ton of system tests :D + test cleanup * More system tests * Add placeholder keys for tests? * Get rid of the double-query! * Speed up CI Chrome setup by avoiding snap installs * Pin CI Chrome version to reduce system test flakiness * Stabilize integrations settings system test interaction
39 lines
1.4 KiB
Ruby
39 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, body, and json attachment" do
|
|
Tempfile.create([ "heartbeat_export_mailer", ".json" ]) do |file|
|
|
file.write({ sample: true }.to_json)
|
|
file.rewind
|
|
|
|
mail = HeartbeatExportMailer.export_ready(
|
|
@user,
|
|
recipient_email: @recipient_email,
|
|
file_path: file.path,
|
|
filename: "heartbeats_test.json"
|
|
)
|
|
|
|
assert_equal [ @recipient_email ], mail.to
|
|
assert_equal "Your Hackatime heartbeat export is ready", mail.subject
|
|
assert_equal 1, mail.attachments.size
|
|
|
|
attachment = mail.attachments.first
|
|
assert_equal "heartbeats_test.json", attachment.filename
|
|
assert_equal "application/json", attachment.mime_type
|
|
assert_equal({ "sample" => true }, JSON.parse(attachment.body.decoded))
|
|
|
|
assert_includes mail.html_part.body.decoded, "Your heartbeat export is ready"
|
|
assert_includes mail.text_part.body.decoded, "Your Hackatime heartbeat export has been generated"
|
|
assert_includes mail.text_part.body.decoded, @user.display_name
|
|
end
|
|
end
|
|
end
|