-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into aws-eb-test
- Loading branch information
Showing
13 changed files
with
155 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
class EngagedSchoolsReportJob < ApplicationJob | ||
def perform(to, previous_year, school_group_id) | ||
AdminMailer.with(to:, csv: csv_report(previous_year, school_group_id)).engaged_schools_report.deliver | ||
end | ||
|
||
private | ||
|
||
def format_bool(bool) | ||
bool ? 'Y' : 'N' | ||
end | ||
|
||
def row | ||
{ school_group: ->(service) { service.school_group.name }, | ||
school: ->(service) { service.school.name }, | ||
funder: ->(service) { service.school.funder&.name }, | ||
country: ->(service) { service.school.country.humanize }, | ||
active: ->(service) { format_bool(service.school.active) }, | ||
data_visible: ->(service) { format_bool(service.school.data_visible?) }, | ||
admin: ->(service) { service.school.default_issues_admin_user&.name }, | ||
activities: ->(service) { service.recent_activity_count }, | ||
actions: ->(service) { service.recent_action_count }, | ||
programmes: ->(service) { service.recently_enrolled_programme_count }, | ||
target?: ->(service) { format_bool(service.active_target?) }, | ||
transport_survey?: ->(service) { format_bool(service.transport_surveys?) }, | ||
temperatures?: ->(service) { format_bool(service.temperature_recordings?) }, | ||
audit?: ->(service) { format_bool(service.audits?) }, | ||
active_users: ->(service) { service.recently_logged_in_user_count }, | ||
last_visit: ->(service) { service.most_recent_login&.iso8601 } } | ||
end | ||
|
||
def csv_report(previous_year, school_group_id) | ||
engaged_schools = Schools::EngagedSchoolService.list_schools(previous_year:, school_group_id:) | ||
CSV.generate(headers: true) do |csv| | ||
csv << row.keys.map { |header| header.to_s.titleize } | ||
engaged_schools.each do |service| | ||
csv << row.values.map { |lambda| lambda.call(service) } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<h1>Engaged Schools</h1> | ||
<p> | ||
The report is attached to this email. | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
spec/support/context_extensions_spec.rb → spec/extensions/context_extensions_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe 'Engaged Schools Report' do | ||
include ActiveJob::TestHelper | ||
|
||
let(:admin) { create(:admin) } | ||
let!(:school) do | ||
create(:school, :with_school_group, :with_points, | ||
calendar: create(:calendar, :with_previous_and_next_academic_years)) | ||
end | ||
let(:last_sign_in) { Time.zone.now } | ||
let!(:user) { create(:school_admin, school: school, last_sign_in_at: last_sign_in) } | ||
|
||
before do | ||
sign_in(admin) | ||
visit admin_reports_engaged_schools_path | ||
end | ||
|
||
def expect_email_with_report(activities: 1) | ||
email = ActionMailer::Base.deliveries.last | ||
expect(email.attachments.first.body.decoded.split("\r\n").map { |line| line.split(',') }).to eq( | ||
[['School Group', 'School', 'Funder', 'Country', 'Active', 'Data Visible', 'Admin', | ||
'Activities', 'Actions', 'Programmes', 'Target?', 'Transport Survey?', 'Temperatures?', 'Audit?', | ||
'Active Users', 'Last Visit'], | ||
[school.school_group.name, school.name, '', school.country.humanize, 'Y', 'Y', '', | ||
activities.to_s, '0', '0', 'N', 'N', 'N', 'N', | ||
'1', last_sign_in.iso8601]] | ||
) | ||
end | ||
|
||
it 'all groups' do | ||
perform_enqueued_jobs { click_on 'Email Current Year' } | ||
expect_email_with_report | ||
end | ||
|
||
it 'previous year' do | ||
perform_enqueued_jobs { click_on 'Email Previous Year' } | ||
expect_email_with_report(activities: 0) | ||
end | ||
|
||
it 'filters school group' do | ||
create(:school, :with_school_group, :with_points) | ||
select school.school_group.name, from: 'School Group' | ||
perform_enqueued_jobs { click_on 'Email Current Year' } | ||
expect_email_with_report | ||
end | ||
end |
Oops, something went wrong.