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

Handle navigating past the country page after selecting an ineligible… #1769

Merged
merged 2 commits into from
Nov 14, 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
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module EnforceEligibilityQuestionOrder
extend ActiveSupport::Concern

Expand All @@ -13,7 +15,7 @@ def redirect_by_status
private

def current_page_is_allowed?
order = paths.keys.index(eligibility_check&.status)
order = paths.keys.index(eligibility_check.status)
current_position = paths.values.index(request.path)
current_position && order && current_position <= order
end
Expand All @@ -28,6 +30,7 @@ def paths
qualified_for_subject: eligibility_interface_qualified_for_subject_path,
work_experience: eligibility_interface_work_experience_path,
misconduct: eligibility_interface_misconduct_path,
}
result: eligibility_interface_result_path,
}.slice(*eligibility_check.status_route)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def create
def next_url
{
eligible: eligibility_interface_qualifications_path,
ineligible: eligibility_interface_ineligible_path,
ineligible: eligibility_interface_result_path,
region: eligibility_interface_region_path,
}.fetch(eligibility_check.country_eligibility_status)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def create
@degree_form =
DegreeForm.new(degree_form_params.merge(eligibility_check:))
if @degree_form.save
redirect_to paths[:teach_children]
redirect_to eligibility_interface_teach_children_path
else
render :new, status: :unprocessable_entity
end
Expand Down
38 changes: 0 additions & 38 deletions app/controllers/eligibility_interface/finish_controller.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,14 @@ def create
@misconduct_form =
MisconductForm.new(misconduct_params.merge(eligibility_check:))
if @misconduct_form.save
redirect_to next_url
redirect_to eligibility_interface_result_path
else
render :new, status: :unprocessable_entity
end
end

private

def next_url
if eligibility_check.eligible?
eligibility_interface_eligible_path
else
eligibility_interface_ineligible_path
end
end

def misconduct_params
params.require(:eligibility_interface_misconduct_form).permit(:misconduct)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def qualification_form_params
def next_path
if eligibility_check.skip_additional_questions? &&
eligibility_check.eligible?
eligibility_interface_eligible_path
eligibility_interface_result_path
else
paths[:degree]
eligibility_interface_degree_path
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def create
qualified_for_subject_form_params.merge(eligibility_check:),
)
if @qualified_for_subject_form.save
redirect_to paths[:work_experience]
redirect_to eligibility_interface_work_experience_path
else
render :new, status: :unprocessable_entity
end
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/eligibility_interface/result_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class EligibilityInterface::ResultController < EligibilityInterface::BaseController
include EnforceEligibilityQuestionOrder

def show
eligibility_check.complete! if eligibility_check.persisted?

render eligibility_check.eligible? ? "eligible" : "ineligible"
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def create

def next_path
if eligibility_check.qualified_for_subject_required?
paths[:qualified_for_subject]
eligibility_interface_qualified_for_subject_path
else
paths[:work_experience]
eligibility_interface_work_experience_path
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create
work_experience_form_params.merge(eligibility_check:),
)
if @work_experience_form.save
redirect_to paths[:misconduct]
redirect_to eligibility_interface_misconduct_path
else
render :new, status: :unprocessable_entity
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/personas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def eligible_sign_in

session[:eligibility_check_id] = eligibility_check.id

redirect_to %i[eligibility_interface eligible]
redirect_to %i[eligibility_interface result]
end

def staff_sign_in
Expand Down
21 changes: 19 additions & 2 deletions app/models/eligibility_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def complete!
def status
return :country if country_code.blank?

return :eligibility if country_eligibility_status == :ineligible
return :result if country_eligibility_status == :ineligible

return :region if region.nil?
return :qualification if qualification.nil?
Expand All @@ -159,7 +159,24 @@ def status
return :misconduct if free_of_sanctions.nil?
end

:eligibility
:result
end

def status_route
if country_code.present? && country_eligibility_status == :ineligible
%i[country result]
elsif skip_additional_questions? && qualification
%i[country region qualification result]
else
%i[country region qualification degree teach_children] +
(
if qualified_for_subject_required?
%i[qualified_for_subject]
else
[]
end
) + %i[work_experience misconduct result]
end
end

def qualified_for_subject_required?
Expand Down
2 changes: 1 addition & 1 deletion app/views/teachers/registrations/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% content_for :page_title, I18n.t("teacher.registration.title") %>
<% content_for :back_link_url, eligibility_interface_eligible_path %>
<% content_for :back_link_url, eligibility_interface_result_path %>

<h1 class="govuk-heading-xl">
<%= I18n.t("teacher.registration.title") %>
Expand Down
3 changes: 1 addition & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@
root to: "start#root"

resource :start, controller: "start", only: %i[show create]
get "eligible", to: "finish#eligible"
get "ineligible", to: "finish#ineligible"
resource :result, controller: "result", only: %i[show]

get "countries", to: "countries#new"
post "countries", to: "countries#create"
Expand Down
4 changes: 2 additions & 2 deletions spec/models/eligibility_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,13 @@
}
end

it { is_expected.to eq(:eligibility) }
it { is_expected.to eq(:result) }
end

context "with an ineligible country" do
let(:attributes) { { country_code: "XX" } }

it { is_expected.to eq(:eligibility) }
it { is_expected.to eq(:result) }
end
end

Expand Down
3 changes: 1 addition & 2 deletions spec/requests/throttling_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
/eligibility/qualifications
/eligibility/teach-children
/eligibility/start
/eligibility/eligible
/eligibility/ineligible
/eligibility/result
/eligibility/misconduct
/support
].each { |path| include_examples "throttled", path }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

module PageObjects
module EligibilityInterface
class Eligible < SitePrism::Page
set_url "/eligibility/eligible"
set_url "/eligibility/result"

element :heading, "h1"
element :apply_button, ".govuk-button"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

module PageObjects
module EligibilityInterface
class Ineligible < SitePrism::Page
set_url "/eligibility/ineligible"
set_url "/eligibility/result"

element :heading, "h1"
element :description, ".govuk-body", match: :first
Expand Down
18 changes: 16 additions & 2 deletions spec/system/eligibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@
then_i_see_the(:eligibility_start_page)

when_i_visit_the(:eligibility_eligible_page)
then_i_see_the(:eligibility_start_page)
then_i_see_the(:eligibility_country_page)

when_i_visit_the(:eligibility_ineligible_page)
then_i_see_the(:eligibility_start_page)
then_i_see_the(:eligibility_country_page)

when_i_press_start_now
then_i_see_the(:eligibility_country_page)
Expand Down Expand Up @@ -311,6 +311,20 @@
then_i_see_the(:eligibility_ineligible_page)
end

it "ineligible path when filtering by country, not qualified in relevant subject" do
when_i_visit_the(:eligibility_start_page)
then_i_see_the(:eligibility_start_page)

when_i_press_start_now
then_i_see_the(:eligibility_country_page)

when_i_select_an_ineligible_country
then_i_see_the(:eligibility_ineligible_page)

when_i_visit_the(:eligibility_qualification_page)
then_i_see_the(:eligibility_ineligible_page)
end

private

def then_access_is_denied
Expand Down
Loading