Skip to content

Commit

Permalink
Merge pull request #9876 from DFE-Digital/2354-tda-setup-the-right-co…
Browse files Browse the repository at this point in the history
…urses-data-for-find-apply

Generate undergraduate test applications
  • Loading branch information
tomas-stefano authored Sep 30, 2024
2 parents afd21f1 + 826a10b commit 0fd8e7d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
34 changes: 34 additions & 0 deletions app/workers/generate_test_applications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def perform(next_cycle_applications = false)

current_cycle = RecruitmentCycle.current_year
current_cycle_courses = courses_from_cycle(current_cycle)
current_cycle_undergraduate_courses = undergraduate_courses_from_cycle(current_cycle)
previous_cycle = RecruitmentCycle.previous_year
previous_cycle_courses = courses_from_cycle(previous_cycle)
next_cycle = RecruitmentCycle.next_year
Expand Down Expand Up @@ -89,6 +90,12 @@ def perform(next_cycle_applications = false)
courses_to_apply_to: current_cycle_courses,
states:,
)

create(
recruitment_cycle_year: current_cycle,
courses_to_apply_to: current_cycle_undergraduate_courses,
states:,
)
end

create(recruitment_cycle_year: current_cycle, states: %i[unsubmitted], course_full: true, courses_to_apply_to: current_cycle_courses)
Expand Down Expand Up @@ -152,6 +159,33 @@ def courses_from_cycle(year)
courses.distinct
end

def undergraduate_courses_from_cycle(year)
recruitment_cycle_year = [RecruitmentCycle.current_year, year].min
courses = Course
.teacher_degree_apprenticeship
.with_course_options
.in_cycle(recruitment_cycle_year)

if courses.count.zero?
common_used_provider_code = '1TZ'
provider = Provider.find_by(code: common_used_provider_code) ||
Provider.all.sample(10).sample ||
FactoryBot.create(:provider)

FactoryBot.create_list(
:course,
10,
:teacher_degree_apprenticeship,
:with_course_options,
:open,
recruitment_cycle_year:,
provider:,
)
end

courses.distinct
end

def continuous_application_choices_states
[
%i[inactive],
Expand Down
28 changes: 28 additions & 0 deletions spec/workers/generate_test_applications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,34 @@
expect(ApplicationForm.joins(:application_choices).where('application_choices.status': 'offer', phase: 'apply_1').where.not(previous_application_form_id: nil)).not_to be_empty
end

it 'generates undergraduate test applications', :sidekiq, time: mid_cycle do
current_cycle = RecruitmentCycle.current_year
previous_cycle = RecruitmentCycle.previous_year
provider = create(:provider)

create(:course_option, course: create(:course, :open, recruitment_cycle_year: previous_cycle))

create(:course_option, course: create(:course, :open, recruitment_cycle_year: previous_cycle))
create(:course_option, course: create(:course, :open, recruitment_cycle_year: previous_cycle))
create(:course_option, course: create(:course, :open, recruitment_cycle_year: previous_cycle))

create(:course_option, course: create(:course, :open, recruitment_cycle_year: current_cycle, provider:))
create(:course_option, course: create(:course, :open, recruitment_cycle_year: current_cycle, provider:))
create(:course_option, course: create(:course, :open, recruitment_cycle_year: current_cycle, provider:))
create(:course_option, course: create(:course, :open, recruitment_cycle_year: current_cycle, provider:))
create(:course_option, course: create(:course, :open, recruitment_cycle_year: current_cycle, provider:))

ClimateControl.modify(STATE_CHANGE_SLACK_URL: 'https://example.com') do
described_class.new.perform
end

expect(
ApplicationForm
.joins(application_choices: { course_option: :course })
.where("courses.program_type = 'TDA'"),
).not_to be_empty
end

it 'generates test applications for the next cycle', :sidekiq, time: mid_cycle do
current_cycle = RecruitmentCycle.current_year
provider = create(:provider)
Expand Down

0 comments on commit 0fd8e7d

Please sign in to comment.