Skip to content

Commit

Permalink
Add stuck submissions to mailer (#3785)
Browse files Browse the repository at this point in the history
* Add stuck submissions to mailer
move views to proper location
refactor table into partial

* Line too long
  • Loading branch information
ATeal authored Jan 15, 2020
1 parent 1d92121 commit e2a93b6
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@ class UnsuccessfulReportMailer < ApplicationMailer
[email protected]
].freeze

def build(unsuccessful_submissions, date_from, date_to)
def build(unsuccessful_submissions, stuck_submissions, date_from, date_to)
@unsuccessful_submissions = unsuccessful_submissions
@stuck_submissions = stuck_submissions
@date_from = date_from
@date_to = date_to

path = VBADocuments::Engine.root.join('app', 'mailers', 'vba_documents', 'views', 'unsuccessful_report.erb')
path = VBADocuments::Engine.root.join(
'app',
'views',
'vba_documents',
'unsuccessful_report_mailer',
'unsuccessful_report.html.erb'
)
template = File.read(path)

mail(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<h1>Unsuccessful Submissions <%= 'Summary' if @date_to.monday? %> </h1>
<hr />
<h3>From <%= @date_from %> -- <%= @date_to %> </h3>
<table>
<thead>
<tr>
Expand All @@ -14,7 +11,7 @@
</tr>
</thead>
<tbody>
<% @unsuccessful_submissions.each do |submission| %>
<% submissions.each do |submission| %>
<tr>
<td><%= submission.guid %></td>
<td><%= submission.consumer_name %></td>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>Unsuccessful Submissions <%= 'Summary' if @date_to.monday? %> </h1>
<hr />
<h3>From <%= @date_from %> -- <%= @date_to %> </h3>
<h4> Unsuccessful count: <%= @unsuccessful_submissions.count %>
<%= render partial: 'submission_table', locals: {submissions: @unsuccessful_submissions } %>

<hr>

<h4> Stuck Submissions Count: <%= @stuck_submissions.count %>
<%= render partial: 'submission_table', locals: {submissions: @stuck_submissions} unless @stuck_submissions.count.zero? %>
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ def perform
if Settings.vba_documents.unsuccessful_report_enabled
to = Time.zone.now
from = to.monday? ? 7.days.ago : 1.day.ago
submissions = VBADocuments::UploadSubmission.where(
errored_submissions = VBADocuments::UploadSubmission.where(
created_at: from..to,
status: %w[error expired]
)
VBADocuments::UnsuccessfulReportMailer.build(submissions, from, to).deliver_now
stuck_submissions = VBADocuments::UploadSubmission.where(
created_at: from..to,
status: 'uploaded'
)
VBADocuments::UnsuccessfulReportMailer.build(errored_submissions, stuck_submissions, from, to).deliver_now
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
created_at: from..to,
status: %w[error expired]
),
VBADocuments::UploadSubmission.where(
created_at: from..to,
status: 'uploaded'
),
from,
to
).and_return(double.tap do |mailer|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

RSpec.describe VBADocuments::UnsuccessfulReportMailer, type: [:mailer] do
let(:error_upload) { FactoryBot.create(:upload_submission, :status_error) }
let(:uploaded_upload) { FactoryBot.create(:upload_submission, :status_uploaded) }

describe '#build' do
subject do
described_class.build([error_upload], 7.days.ago, Time.zone.now).deliver_now
described_class.build([error_upload], [uploaded_upload], 7.days.ago, Time.zone.now).deliver_now
end

it 'sends the email' do
Expand Down

0 comments on commit e2a93b6

Please sign in to comment.