Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow providers to csv export all their application choices #10352

Merged
merged 3 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def export
current_course_option: %i[course site],
application_form: %i[candidate english_proficiency application_qualifications],
],
recruitment_cycle_year: RecruitmentCycleTimetable.pluck(:recruitment_cycle_year),
CatalinVoineag marked this conversation as resolved.
Show resolved Hide resolved
)

application_choices = FilterApplicationChoicesForProviders.call(
Expand Down
8 changes: 8 additions & 0 deletions app/forms/provider_interface/application_data_export_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ def selected_years
recruitment_cycle_years.compact_blank
end

def years_to_export
choices = GetApplicationChoicesForProviders.call(
providers: providers_that_actor_belongs_to,
recruitment_cycle_year: RecruitmentCycleTimetable.pluck(:recruitment_cycle_year),
)
choices.map(&:current_recruitment_cycle_year).uniq.sort
end

def providers_that_actor_belongs_to
@_providers_that_actor_belongs_to ||= current_provider_user.providers
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
<%= t('page_titles.provider.export_application_data') %>
</h1>

<%= f.govuk_check_boxes_fieldset :recruitment_cycle_years, legend: { text: 'Recruitment cycle', size: 'm' } do %>
<% RecruitmentCycle.years_visible_to_providers.each_with_index do |year, index| %>
<%= f.govuk_check_box :recruitment_cycle_years, year.to_s, label: { text: RecruitmentCycle.cycle_string(year) }, link_errors: index.zero? %>
<% if @application_data_export_form.years_to_export.any? %>
<%= f.govuk_check_boxes_fieldset :recruitment_cycle_years, legend: { text: 'Recruitment cycle', size: 'm' } do %>
<% @application_data_export_form.years_to_export.each_with_index do |year, index| %>
<%= f.govuk_check_box :recruitment_cycle_years, year.to_s, label: { text: RecruitmentCycle.cycle_string(year) }, link_errors: index.zero? %>
<% end %>
<% end %>
<% end %>

Expand Down
3 changes: 3 additions & 0 deletions lib/tasks/local_dev.rake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ task setup_local_dev_data: %i[environment copy_feature_flags_from_production syn
email_address: candidate.email_address,
)

puts 'Creating all RecruitmentCycleTimetables'
DataMigrations::AddAllRecruitmentCycleTimetablesToDatabase.new.change
CatalinVoineag marked this conversation as resolved.
Show resolved Hide resolved

puts 'Creating various provider users...'
CreateExampleProviderUsersWithPermissions.call

Expand Down
3 changes: 3 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
exit 1
end

# Run data migrations before specs
DataMigrations::AddAllRecruitmentCycleTimetablesToDatabase.new.change
CatalinVoineag marked this conversation as resolved.
Show resolved Hide resolved

Faker::Config.locale = 'en-GB'

RSpec::Matchers.define_negated_matcher :not_change, :change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
then_the_downloaded_file_includes_applications_all_years_of_deferred_and_accepted_offers_for_the_first_provider
end

scenario 'downloads a CSV of old applications' do
given_i_am_a_provider_user_with_permissions_to_see_applications_for_my_provider
and_my_organisation_has_old_courses_with_applications
and_i_sign_in_to_the_provider_interface

when_i_visit_the_export_applications_page

and_i_fill_out_the_form_for_2022_applications
then_the_downloaded_file_includes_2022_applications
end

scenario 'experiences an error during the download' do
given_i_am_a_provider_user_with_permissions_to_see_applications_for_my_provider
and_my_organisation_has_courses_with_applications
Expand Down Expand Up @@ -88,6 +99,22 @@ def and_my_organisation_has_courses_with_applications
current_course_option: create(:course_option, course: course))
end

def and_my_organisation_has_old_courses_with_applications
@current_provider_user = ProviderUser.last
providers = @current_provider_user.providers
course_2022 = create(:course, provider: providers.first, recruitment_cycle_year: 2022)
course_option = create(:course_option, course: course_2022)

@application_accepted_2022 = create(:application_choice, :accepted, course_option:)

course_2021 = create(:course, recruitment_cycle_year: 2021, provider: providers.first)
@application_deferred_submitted_2021_previous_cycle_offered_2022 =
create(:application_choice,
:accepted,
course_option: create(:course_option, course: course_2021),
current_course_option: create(:course_option, course: course_2022))
end

def when_i_visit_the_export_applications_page
visit provider_interface_new_application_data_export_path
end
Expand All @@ -114,6 +141,14 @@ def and_i_fill_out_the_form_for_applications_this_year_of_any_status_for_the_fir
click_export_data
end

def and_i_fill_out_the_form_for_2022_applications
check 2022
choose 'All statuses'
check @current_provider_user.providers.first.name

click_export_data
end

def then_the_downloaded_file_includes_applications_this_year_of_any_status_for_the_first_provider
csv_data = CSV.parse(page.body, headers: true)
expect_export_to_include_data_for_application(csv_data, @application_accepted)
Expand All @@ -125,6 +160,12 @@ def then_the_downloaded_file_includes_applications_this_year_of_any_status_for_t
expect(csv_data['Application number']).not_to include(@application_second_provider.id.to_s)
end

def then_the_downloaded_file_includes_2022_applications
csv_data = CSV.parse(page.body, headers: true)
expect_export_to_include_data_for_application(csv_data, @application_accepted_2022)
expect_export_to_include_data_for_application(csv_data, @application_deferred_submitted_2021_previous_cycle_offered_2022)
end

def and_i_fill_out_the_form_for_applications_all_years_of_deferred_and_accepted_offers_for_the_first_provider
RecruitmentCycle.years_visible_to_providers.each do |year|
check RecruitmentCycle.cycle_strings[year.to_s]
Expand Down
Loading