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

Generate undergraduate test applications #9876

Merged
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
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
Loading