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

Reimplement RecruitmentCycle::CYCLE #8448

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 7 additions & 9 deletions app/models/recruitment_cycle.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
module RecruitmentCycle
CYCLES = {
'2024' => '2023 to 2024',
'2023' => '2022 to 2023',
'2022' => '2021 to 2022',
'2021' => '2020 to 2021',
'2020' => '2019 to 2020',
}.freeze

def self.cycle_string(year)
cycle = CYCLES.fetch(year.to_s)
cycle = cycle_strings.fetch(year.to_s)
current_year.to_s == year.to_s ? "#{cycle} - current" : cycle
end

def self.cycle_strings(upto = current_year)
2020.upto(upto.to_i).index_with do |year|
"#{year - 1} to #{year}"
end.stringify_keys
end

def self.real_current_year
CycleTimetable.real_current_year
end
Expand Down
4 changes: 1 addition & 3 deletions app/models/support_interface/applications_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ def filters
private

def year_filter
cycle_options = RecruitmentCycle::CYCLES.filter_map do |year, _|
next if year.to_i > RecruitmentCycle.current_year

cycle_options = RecruitmentCycle.cycle_strings(RecruitmentCycle.current_year).map do |year, _|
{
value: year,
label: RecruitmentCycle.cycle_string(year),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<%= govuk_link_to 'View in large screen mode', '?screen=1' %>
</p>

<% year_choices = RecruitmentCycle::CYCLES.map do |year, label| %>
<% year_choices = RecruitmentCycle.cycle_strings(RecruitmentCycle.current_year).map do |year, label| %>
<% { name: label, url: "?year=#{year}&screen=#{params[:screen] || 0}", current: params[:year] == year } %>
<% end %>
Expand Down
41 changes: 41 additions & 0 deletions spec/models/recruitment_cycle_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
require 'rails_helper'

RSpec.describe RecruitmentCycle, time: CycleTimetableHelper.mid_cycle(2023) do
describe '.cycle_strings' do
it 'returns an empty hash when start year is before 2020' do
expect(described_class.cycle_strings(2000)).to eq({})
end

it 'returns the cycle strings up to one year from current_year' do
expect(described_class.cycle_strings).to eq(
{ '2020' => '2019 to 2020',
'2021' => '2020 to 2021',
'2022' => '2021 to 2022',
'2023' => '2022 to 2023' },
)
end

it 'returns the cycle strings up to the arg year' do
expect(described_class.cycle_strings(2024)).to eq(
{ '2020' => '2019 to 2020',
'2021' => '2020 to 2021',
'2022' => '2021 to 2022',
'2023' => '2022 to 2023',
'2024' => '2023 to 2024' },
)
end

context 'when cycle switcher is after apply opens' do
before do
SiteSetting.set(name: 'cycle_schedule', value: 'today_is_after_apply_opens')
end

it 'returns the cycle strings up to the arg year' do
expect(described_class.cycle_strings).to eq(
{ '2020' => '2019 to 2020',
'2021' => '2020 to 2021',
'2022' => '2021 to 2022',
'2023' => '2022 to 2023',
'2024' => '2023 to 2024' },
)
end
end
end

describe '.cycle_string' do
it 'throws an error when a cycle does not exist for the specified year' do
expect { described_class.cycle_string(2000) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def then_i_get_validation_errors
end

def and_i_fill_out_the_form_for_applications_this_year_of_any_status_for_the_first_provider
check RecruitmentCycle::CYCLES[RecruitmentCycle.current_year.to_s]
check RecruitmentCycle.cycle_strings[RecruitmentCycle.current_year.to_s]
choose 'All statuses'
check @current_provider_user.providers.first.name

Expand All @@ -98,7 +98,7 @@ def then_the_downloaded_file_includes_applications_this_year_of_any_status_for_t

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::CYCLES[year.to_s]
check RecruitmentCycle.cycle_strings[year.to_s]
end
choose 'Specific statuses'
check 'Deferred'
Expand Down