Skip to content

Commit

Permalink
Refactor created_under_new_regulations?
Browse files Browse the repository at this point in the history
This changes the method to return true if the application form was
created under the old regulations and assumes the new regulations by
default across the service.
  • Loading branch information
thomasleese committed Apr 24, 2024
1 parent 89c301c commit 2dbac37
Show file tree
Hide file tree
Showing 25 changed files with 177 additions and 367 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def form_class
if assessment_section.age_range_subjects?
CheckAgeRangeSubjectsForm
elsif assessment_section.professional_standing? &&
application_form.created_under_new_regulations? &&
!application_form.created_under_old_regulations? &&
!application_form.needs_work_history
if CountryCode.scotland?(application_form.country.code)
ScotlandFullRegistrationForm
Expand Down
20 changes: 10 additions & 10 deletions app/lib/application_form_section_status_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,16 @@ def english_language_status
def work_history_status
all_work_histories_complete = work_histories.all?(&:complete?)

if application_form.created_under_new_regulations?
if application_form.created_under_old_regulations?
return :not_started if has_work_history.nil?

if !has_work_history ||
(!work_histories.empty? && all_work_histories_complete)
:completed
else
:in_progress
end
else
return :not_started if work_histories.empty?
return :in_progress unless all_work_histories_complete

Expand All @@ -157,15 +166,6 @@ def work_history_status
).enough_for_submission?

enough_for_submission ? :completed : :in_progress
else
return :not_started if has_work_history.nil?

if !has_work_history ||
(!work_histories.empty? && all_work_histories_complete)
:completed
else
:in_progress
end
end
end

Expand Down
124 changes: 47 additions & 77 deletions app/lib/assessment_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ def personal_information_section
end
),
(
if application_form.created_under_new_regulations? &&
application_form.english_language_citizenship_exempt
if application_form.english_language_citizenship_exempt
FailureReasons::EL_EXEMPTION_BY_CITIZENSHIP_ID_UNCONFIRMED
end
),
Expand Down Expand Up @@ -87,36 +86,19 @@ def qualifications_section
"has_university_degree_transcript",
"has_additional_qualification_certificate",
"has_additional_degree_transcript",
(
if application_form.created_under_new_regulations?
"teaching_qualification_pedagogy"
end
),
(
if application_form.created_under_new_regulations?
"teaching_qualification_1_year"
end
),
"teaching_qualification_pedagogy",
"teaching_qualification_1_year",
].compact

failure_reasons = [
FailureReasons::APPLICATION_AND_QUALIFICATION_NAMES_DO_NOT_MATCH,
FailureReasons::TEACHING_QUALIFICATIONS_FROM_INELIGIBLE_COUNTRY,
FailureReasons::TEACHING_QUALIFICATIONS_NOT_AT_REQUIRED_LEVEL,
FailureReasons::TEACHING_HOURS_NOT_FULFILLED,
FailureReasons::TEACHING_QUALIFICATION_PEDAGOGY,
FailureReasons::TEACHING_QUALIFICATION_1_YEAR,
(
if application_form.created_under_new_regulations?
FailureReasons::TEACHING_QUALIFICATION_PEDAGOGY
end
),
(
if application_form.created_under_new_regulations?
FailureReasons::TEACHING_QUALIFICATION_1_YEAR
end
),
(
if application_form.created_under_new_regulations? &&
application_form.english_language_qualification_exempt
if application_form.english_language_qualification_exempt
FailureReasons::EL_EXEMPTION_BY_QUALIFICATION_DOCUMENTS_UNCONFIRMED
end
),
Expand Down Expand Up @@ -169,69 +151,57 @@ def age_range_subjects_section
end

def english_language_proficiency_section
if application_form.created_under_new_regulations?
checks =
if application_form.english_language_exempt?
[]
elsif application_form.english_language_proof_method_medium_of_instruction?
%i[english_language_valid_moi]
else
%i[english_language_valid_provider]
end

failure_reasons =
if application_form.english_language_exempt?
[]
elsif application_form.english_language_proof_method_medium_of_instruction?
[
FailureReasons::EL_MOI_NOT_TAUGHT_IN_ENGLISH,
FailureReasons::EL_MOI_INVALID_FORMAT,
]
else
[
FailureReasons::EL_QUALIFICATION_INVALID,
(
if application_form.english_language_provider_other
FailureReasons::EL_PROFICIENCY_DOCUMENT_ILLEGIBLE
else
FailureReasons::EL_UNVERIFIABLE_REFERENCE_NUMBER
end
),
FailureReasons::EL_GRADE_BELOW_B2,
FailureReasons::EL_SELT_EXPIRED,
]
end

AssessmentSection.new(
key: "english_language_proficiency",
checks:,
failure_reasons:,
)
end
end

def work_history_section
return nil unless application_form.needs_work_history

checks =
if application_form.created_under_new_regulations?
%i[verify_school_details work_history_references]
if application_form.english_language_exempt?
[]
elsif application_form.english_language_proof_method_medium_of_instruction?
%i[english_language_valid_moi]
else
%i[email_contact_current_employer satisfactory_evidence_work_history]
%i[english_language_valid_provider]
end

failure_reasons =
if application_form.created_under_new_regulations?
if application_form.english_language_exempt?
[]
elsif application_form.english_language_proof_method_medium_of_instruction?
[
FailureReasons::WORK_HISTORY_BREAK,
FailureReasons::SCHOOL_DETAILS_CANNOT_BE_VERIFIED,
FailureReasons::UNRECOGNISED_REFERENCES,
FailureReasons::WORK_HISTORY_DURATION,
FailureReasons::EL_MOI_NOT_TAUGHT_IN_ENGLISH,
FailureReasons::EL_MOI_INVALID_FORMAT,
]
else
[FailureReasons::SATISFACTORY_EVIDENCE_WORK_HISTORY]
[
FailureReasons::EL_QUALIFICATION_INVALID,
(
if application_form.english_language_provider_other
FailureReasons::EL_PROFICIENCY_DOCUMENT_ILLEGIBLE
else
FailureReasons::EL_UNVERIFIABLE_REFERENCE_NUMBER
end
),
FailureReasons::EL_GRADE_BELOW_B2,
FailureReasons::EL_SELT_EXPIRED,
]
end

AssessmentSection.new(
key: "english_language_proficiency",
checks:,
failure_reasons:,
)
end

def work_history_section
return nil unless application_form.needs_work_history

checks = %i[verify_school_details work_history_references]

failure_reasons = [
FailureReasons::WORK_HISTORY_BREAK,
FailureReasons::SCHOOL_DETAILS_CANNOT_BE_VERIFIED,
FailureReasons::UNRECOGNISED_REFERENCES,
FailureReasons::WORK_HISTORY_DURATION,
]

AssessmentSection.new(key: "work_history", checks:, failure_reasons:)
end

Expand Down
4 changes: 2 additions & 2 deletions app/lib/dqt/recognition_route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

class DQT::RecognitionRoute
class << self
def for_country_code(country_code, under_new_regulations:)
def for_country_code(country_code, under_old_regulations:)
if CountryCode.scotland?(country_code)
"Scotland"
elsif CountryCode.northern_ireland?(country_code)
"NorthernIreland"
elsif !under_new_regulations &&
elsif under_old_regulations &&
CountryCode.european_economic_area?(country_code)
"EuropeanEconomicArea"
else
Expand Down
20 changes: 9 additions & 11 deletions app/lib/dqt/trn_request_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def call
recognitionRoute:
RecognitionRoute.for_country_code(
application_form.region.country.code,
under_new_regulations:
application_form.created_under_new_regulations?,
under_old_regulations:
application_form.created_under_old_regulations?,
),
qtsDate: qts_decision_at.to_date.iso8601,
inductionRequired: induction_required,
underNewOverseasRegulations:
application_form.created_under_new_regulations?,
!application_form.created_under_old_regulations?,
}
end

Expand Down Expand Up @@ -79,19 +79,17 @@ def degree_qualification
end

def qts_decision_at
if application_form.created_under_new_regulations?
application_form.assessment.recommended_at
else
if application_form.created_under_old_regulations?
application_form.submitted_at
else
application_form.assessment.recommended_at
end
end

def induction_required
if application_form.created_under_new_regulations?
assessment.induction_required
else
false
end
return false if application_form.created_under_old_regulations?

assessment.induction_required
end
end
end
4 changes: 2 additions & 2 deletions app/models/application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ def english_language_exempt?
english_language_citizenship_exempt || english_language_qualification_exempt
end

def created_under_new_regulations?
created_at >= Date.parse(ENV.fetch("NEW_REGS_DATE", "2023-02-01"))
def created_under_old_regulations?
created_at < Date.new(2023, 2, 1)
end

def reminder_email_names
Expand Down
10 changes: 5 additions & 5 deletions app/models/assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def completed?
end

def can_award?
if application_form.created_under_new_regulations?
if application_form.created_under_old_regulations?
all_sections_or_further_information_requests_passed?
else
return false if induction_required.nil?

if verify?
Expand All @@ -108,8 +110,6 @@ def can_award?
else
false
end
else
all_sections_or_further_information_requests_passed?
end
end

Expand Down Expand Up @@ -147,7 +147,7 @@ def can_request_further_information?

def can_review?
return false unless verify?
return false unless application_form.created_under_new_regulations?
return false if application_form.created_under_old_regulations?

return false unless all_consent_requests_verified?
return false unless all_reference_requests_verified?
Expand All @@ -164,7 +164,7 @@ def can_review?

def can_verify?
return false unless unknown? || request_further_information?
return false unless application_form.created_under_new_regulations?
return false if application_form.created_under_old_regulations?

all_sections_or_further_information_requests_passed?
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/further_information_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def send_reminder_email(_name, _number_of_reminders_sent)
end

def expires_after
if !application_form.created_under_new_regulations? &&
if application_form.created_under_old_regulations? &&
FOUR_WEEK_COUNTRY_CODES.include?(application_form.country.code)
4.weeks
else
Expand Down
2 changes: 1 addition & 1 deletion app/models/work_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def complete?
values += [contact_name, contact_email]
end

if application_form.created_under_new_regulations?
unless application_form.created_under_old_regulations?
values.append(hours_per_week)

unless application_form.reduced_evidence_accepted?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def task_list_sections
%i[personal_information identification_document],
),
task_list_section(:qualifications, %i[qualifications age_range subjects]),
if application_form.created_under_new_regulations?
unless application_form.created_under_old_regulations?
task_list_section(:english_language, %i[english_language])
end,
if needs_work_history
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<% if application_form.created_under_new_regulations? %>
<%= render "shared/application_form/work_history_summary",
work_histories: application_form.work_histories.order_by_user,
highlighted_contact_emails: highlighted_work_history_contact_emails %>
<% else %>
<%= render "shared/application_form/work_history_old_regs_summary",
<% if application_form.created_under_old_regulations? %>
<%= render "shared/application_form/work_history_old_regulations_summary",
application_form:,
show_has_work_history: true,
work_histories: application_form.work_histories.order_by_user,
highlighted_contact_emails: highlighted_work_history_contact_emails,
changeable: false %>
<% else %>
<%= render "shared/application_form/work_history_summary",
work_histories: application_form.work_histories.order_by_user,
highlighted_contact_emails: highlighted_work_history_contact_emails %>
<% end %>

<% if application_form.created_under_new_regulations? %>
<% unless application_form.created_under_old_regulations? %>
<% years, months = WorkHistoryDuration.for_application_form(application_form).count_years_and_months %>

<h2 class="govuk-heading-m">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@
You have completed <%= view_object.completed_task_list_sections.count %> of <%= view_object.task_list_sections.count %> sections.
</p>

<% if view_object.application_form.created_under_new_regulations? %>
<%= govuk_inset_text do %>
<p class="govuk-body">
You started this application on <%= view_object.started_at %>.
Applications must be completed within 6 months, so you’ll need to complete it before <%= view_object.expires_at %>.
</p>
<% end %>
<%= govuk_inset_text do %>
<p class="govuk-body">
You started this application on <%= view_object.started_at %>.
Applications must be completed within 6 months, so you’ll need to complete it before <%= view_object.expires_at %>.
</p>
<% end %>

<%= render TaskList::Component.new(view_object.task_list_sections) %>
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/application_forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
withdrawn_at { Time.zone.now }
end

trait :old_regs do
trait :old_regulations do
created_at { Date.new(2023, 1, 31) }
needs_work_history do
(region.status_check_none? || region.sanction_check_none?) &&
Expand Down
Loading

0 comments on commit 2dbac37

Please sign in to comment.