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

Improve example data generation #1918

Merged
merged 3 commits into from
Jan 11, 2024
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
28 changes: 18 additions & 10 deletions lib/tasks/example_data.rake
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def application_form_traits_for(region)
traits =
%i[
with_personal_information
with_completed_qualification
with_degree_qualification
with_identification_document
with_age_range
with_subjects
Expand Down Expand Up @@ -188,20 +188,28 @@ def create_requestables(application_form, assessment, state)
unless application_form.teaching_authority_provides_written_statement
assessment.verify!
end
elsif (work_history = application_form.work_histories.first) && rand(3).zero?
FactoryBot.create(:reference_request, state, assessment:, work_history:)
elsif (work_histories = application_form.work_histories).present? &&
rand(3).zero?
work_histories.each do |work_history|
FactoryBot.create(:reference_request, state, assessment:, work_history:)
end

application_form.update!(
statuses: ["#{status_prefix}_reference"],
stage: "verification",
)
assessment.verify!
elsif (qualification = application_form.qualifications.first) && rand(2).zero?
FactoryBot.create(
:qualification_request,
state,
assessment:,
qualification:,
)
elsif (qualifications = application_form.qualifications).present? &&
rand(2).zero?
qualifications.each do |qualification|
FactoryBot.create(
:qualification_request,
state,
assessment:,
qualification:,
)
end

application_form.update!(
statuses: ["#{status_prefix}_qualification"],
stage: "verification",
Expand Down
17 changes: 15 additions & 2 deletions spec/factories/application_forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
end
end

trait :with_completed_qualification do
trait :with_teaching_qualification do
after(:create) do |application_form, _evaluator|
create(
:qualification,
Expand All @@ -300,6 +300,13 @@
end
end

trait :with_degree_qualification do
with_teaching_qualification
after(:create) do |application_form, _evaluator|
create(:qualification, :completed, application_form:)
end
end

trait :with_english_language_medium_of_instruction do
english_language_proof_method { "medium_of_instruction" }

Expand Down Expand Up @@ -356,7 +363,13 @@
has_work_history { true }

after(:create) do |application_form, _evaluator|
create(:work_history, :completed, application_form:)
create(:work_history, :completed, :still_employed, application_form:)
create(
:work_history,
:completed,
:not_still_employed,
application_form:,
)
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/factories/qualifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
title { Faker::Educator.degree }
institution_name { Faker::University.name }
sequence :institution_country_code, Country::CODES.cycle
start_date { Date.new(2020, 1, 1) }
complete_date { Date.new(2021, 1, 1) }
certificate_date { Date.new(2021, 1, 1) }
start_date { Faker::Date.between(from: 30.years.ago, to: 10.years.ago) }
complete_date { start_date + 5.years }
certificate_date { complete_date + 1.year }
part_of_university_degree { true }

after(:create) do |qualification, _evaluator|
Expand Down
25 changes: 17 additions & 8 deletions spec/factories/work_histories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,25 @@
canonical_contact_email { EmailAddress.canonical(contact_email) }

trait :completed do
school_name { "School" }
city { "City" }
sequence :country_code, Country::CODES.cycle
job { "Job" }
hours_per_week { 30 }
start_date { Date.new(2020, 1, 1) }
still_employed { true }
city { Faker::Address.city }
contact_job { Faker::Job.title }
contact_name { Faker::Name.name }
contact_job { "Job" }
hours_per_week { Faker::Number.between(from: 20, to: 40) }
job { Faker::Job.title }
school_name { Faker::Educator.primary_school }
sequence :country_code, Country::CODES.cycle
sequence(:contact_email) { |n| "school#{n}@example.org" }
start_date { Faker::Date.between(from: 5.years.ago, to: 9.months.ago) }
still_employed
end

trait :still_employed do
still_employed { true }
end

trait :not_still_employed do
end_date { Faker::Date.between(from: start_date, to: 3.months.ago) }
still_employed { false }
end
end
end
2 changes: 1 addition & 1 deletion spec/lib/application_mailer_observer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
create(
:application_form,
:with_personal_information,
:with_completed_qualification,
:with_teaching_qualification,
region:,
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class CheckYourAnswers < SitePrism::Page
end

section :who_you_can_teach, "#app-application-form-who-you-can-teach" do
section :qualification_summary_list,
GovukSummaryList,
".govuk-summary-card" \
":not(#app-check-your-answers-summary-age-range)" \
":not(#app-check-your-answers-summary-subjects)",
match: :first
sections :qualification_summary_lists,
GovukSummaryList,
".govuk-summary-card" \
":not(#app-check-your-answers-summary-age-range)" \
":not(#app-check-your-answers-summary-subjects)",
match: :first
section :age_range_summary_list,
GovukSummaryList,
"#app-check-your-answers-summary-age-range"
Expand All @@ -34,9 +34,9 @@ class CheckYourAnswers < SitePrism::Page
section :add_summary_list,
GovukSummaryList,
"#app-check-your-answers-summary-add-work-history"
section :work_history_summary_list,
GovukSummaryList,
".govuk-summary-card:not(#app-check-your-answers-summary-add-work-history)"
sections :work_history_summary_lists,
GovukSummaryList,
".govuk-summary-card:not(#app-check-your-answers-summary-add-work-history)"
end

section :proof_of_recognition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def application_form
create(
:application_form,
:old_regs,
:with_completed_qualification,
:with_teaching_qualification,
:with_work_history,
:with_registration_number,
:with_personal_information,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def given_there_is_an_awardable_application_form(traits = [])
create(
:application_form,
:with_personal_information,
:with_completed_qualification,
:with_teaching_qualification,
:submitted,
*traits,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,14 @@ def application_form
induction_required: false,
references_verified: true,
)
create(:reference_request, :received, assessment:, verify_passed: false)
create(
:reference_request,
:received,
assessment:,
verify_passed: false,
work_history:
create(:work_history, :completed, school_name: "School"),
)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ def application_form
:work_history,
:completed,
application_form:,
contact_name: "John Smith",
contact_job: "Headteacher",
contact_name: "John Smith",
school_name: "School",
)
assessment =
create(
Expand Down
19 changes: 12 additions & 7 deletions spec/system/teacher_interface/check_answers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,24 @@ def when_i_click_change_links(section, summary_list, &block)
index = 0
while (
row =
teacher_check_your_answers_page
.send(section)
.send("#{summary_list}_summary_list")
.rows[
index
]
find_change_link_summary_list(section, summary_list).rows[index]
)
row.actions.link.click
block.call
index += 1
end
end

def find_change_link_summary_list(section, summary_list)
section_page_object = teacher_check_your_answers_page.send(section)

begin
section_page_object.send("#{summary_list}_summary_list")
rescue NoMethodError
section_page_object.send("#{summary_list}_summary_lists").first
end
end

def and_i_dont_need_to_upload_another_file
teacher_check_document_page.form.false_radio_item.input.click
teacher_check_document_page.form.continue_button.click
Expand All @@ -168,7 +173,7 @@ def application_form
:with_registration_number,
:with_work_history,
:with_written_statement,
:with_completed_qualification,
:with_teaching_qualification,
teacher:,
)
end
Expand Down
7 changes: 5 additions & 2 deletions spec/system/teacher_interface/reference_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,12 @@ def reference_request
create(
:work_history,
:completed,
end_date: Date.new(2023, 1, 1),
contact_name: "John Smith",
contact_job: "Headteacher",
contact_name: "John Smith",
end_date: Date.new(2023, 1, 1),
hours_per_week: 30,
school_name: "School",
start_date: Date.new(2020, 1, 1),
),
)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/system/teacher_interface/submitting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def application_form
:with_registration_number,
:with_work_history,
:with_written_statement,
:with_completed_qualification,
:with_teaching_qualification,
teacher:,
)
end
Expand Down
Loading