Skip to content

Commit 7dff108

Browse files
[Tbt-394] expand csv export (#345)
* move csv_export_ready from billing to plan mailer * use from method * small template changes * remove csv export from billing mailer add specs
1 parent feba07d commit 7dff108

File tree

7 files changed

+97
-304
lines changed

7 files changed

+97
-304
lines changed

lib/travis/addons/billing/mailer/billing_mailer.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ def subscription_cancellation_requested(receivers, subscription, owner, charge,
6060
mail(from: cancellation_email, to: receivers, subject: subject, template_path: 'billing_mailer')
6161
end
6262

63-
def csv_export_ready(receivers, subscription_or_report, owner, charge, event, report_or_other, cc_last_digits)
64-
@report = subscription_or_report
65-
@owner = owner
66-
subject = "Travis CI: Your #{@report[:type]&.capitalize} Report is Ready"
67-
68-
mail(from: travis_email, to: receivers, subject: subject, template_path: 'billing_mailer')
69-
end
70-
7163
private
7264

7365
def travis_email

lib/travis/addons/billing/mailer/views/billing_mailer/csv_export_ready.html.erb

Lines changed: 0 additions & 233 deletions
This file was deleted.

lib/travis/addons/billing/task.rb

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,13 @@ def cc_last_digits
3939
params[:cc_last_digits]
4040
end
4141

42-
def report
43-
params[:report]
44-
end
45-
4642
private
4743

48-
def send_email
49-
Mailer::BillingMailer.public_send(
50-
params[:email_type],
51-
recipients,
52-
params[:email_type] == 'csv_export_ready' ? report : subscription,
53-
owner,
54-
charge,
55-
event,
56-
invoice,
57-
cc_last_digits
58-
).deliver
59-
emails = recipients.map { |r| 'email=' + obfuscate_email_address(r) }.join(' ')
60-
info "type=#{type} status=sent msg='email sent #{emails}'"
61-
end
44+
def send_email
45+
Mailer::BillingMailer.public_send(params[:email_type], recipients, subscription, owner, charge, event, invoice, cc_last_digits).deliver
46+
emails = recipients.map { |r| 'email=' + obfuscate_email_address(r) }.join(' ')
47+
info "type=#{type} status=sent msg='email sent #{emails}'"
48+
end
6249
end
6350
end
6451
end

lib/travis/addons/plan/mailer/plan_mailer.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ def shared_plan_no_admin(receivers, owner, params)
9393
mail(from: from, to: @recipients, subject: subject, template_path: 'plan_mailer')
9494
end
9595

96+
def csv_export_ready(receivers, owner, params)
97+
@owner = owner
98+
@report = params.fetch(:report)
99+
subject = "Travis CI: Your Credits Consumption Report is Ready"
100+
101+
mail(from: from, to: receivers, subject: subject, template_path: 'plan_mailer')
102+
end
96103
private
97104

98105
def from
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!-- Plan Message Section -->
2+
<tr>
3+
<td id="plan-message-section" align="center" valign="top" style="padding-bottom: 40px;">
4+
<h1 id="plan-message-header">
5+
Report is Ready!
6+
</h1>
7+
<p style="margin: 0px; font-size: 18px; margin-bottom: 10px;">
8+
Hello,
9+
</p>
10+
<p style="margin: 0px; font-size: 18px; margin-bottom: 20px;">
11+
Your credits consumption report for
12+
<span id="plan-message-github-name" style="color: #15B75E;">
13+
<%= @owner && (@owner[:name] || @owner[:login]) || 'your account' %>
14+
</span>
15+
is now ready for download.
16+
</p>
17+
18+
<% if @report && @report[:date_range] %>
19+
<p style="margin: 0px; font-size: 18px; margin-bottom: 20px;">
20+
This report contains data <%= @report[:date_range] %>.
21+
</p>
22+
<% end %>
23+
24+
<p style="margin: 0px; font-size: 18px; margin-bottom: 20px;">
25+
<% if @report && @report[:expires_at] %>
26+
This download link will expire on <%= Time.parse(@report[:expires_at]).strftime('%B %d, %Y at %H:%M %Z') rescue 'the expiration date' %>.
27+
<% else %>
28+
This download link will expire in 24 hours.
29+
<% end %>
30+
</p>
31+
32+
<p style="margin: 0px; font-size: 18px; margin-bottom: 30px; margin-top: 30px;">
33+
<a href="<%= @report && @report[:download_url] || '#' %>" style="font: bold 14px Arial; color: #FFFFFF; background-color: #32D282; text-decoration: none; padding: 12px 30px; border-radius: 3px;">
34+
DOWNLOAD REPORT
35+
</a>
36+
</p>
37+
</td>
38+
</tr>
39+
<tr>
40+
<td id="closing-message-section" align="center" valign="top" style="padding: 0px 30px 20px 30px;">
41+
<p style="margin: 0px; font-size: 18px;">Happy building!</p>
42+
<p style="margin: 0px; font-size: 18px;">
43+
<strong>Travis CI Team</strong>
44+
</p>
45+
</td>
46+
</tr>

spec/addons/billing/mailer/billing_mailer_spec.rb

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -281,49 +281,4 @@
281281

282282
end
283283
end
284-
285-
describe '#csv_export_ready' do
286-
subject(:mail) do
287-
described_class.csv_export_ready(
288-
[recipient],
289-
report,
290-
owner,
291-
charge,
292-
event,
293-
report_or_other = nil,
294-
options
295-
)
296-
end
297-
298-
let(:recipient) { 'nikola.granit@yahoo.com' }
299-
let(:owner) { { name: 'Ruby Monsters', login: 'rubymonsters', vcs_type: 'GithubUser', owner_type: 'User' } }
300-
let(:charge) { nil }
301-
let(:event) { nil }
302-
let(:report) { { type: 'usage', download_url: download_url, expires_at: (Time.now + 86400).iso8601 } }
303-
let(:download_url) { 'https://example.com/report.csv' }
304-
let(:options) { {} }
305-
306-
it 'is addressed to the user' do
307-
expect(mail.to).to eq([recipient])
308-
end
309-
310-
it 'comes from Travis' do
311-
expect(mail.from).to eq(['success@travis-ci.com'])
312-
end
313-
314-
it 'has the right subject' do
315-
expect(mail.subject).to eq('Travis CI: Your Usage Report is Ready')
316-
end
317-
318-
it 'contains the download link' do
319-
html = Capybara.string(mail.body.to_s)
320-
expect(html).to have_link('Download Report', href: download_url)
321-
end
322-
323-
it 'shows the report type' do
324-
html = Capybara.string(mail.body.to_s)
325-
expect(html).to have_text('Your usage report for')
326-
expect(html).to have_text('is now ready for download.')
327-
end
328-
end
329284
end

0 commit comments

Comments
 (0)