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

Refactor check uk visa #6558

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
147 changes: 69 additions & 78 deletions app/flows/check_uk_visa_flow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,13 @@ def define

next_node do
if calculator.travelling_to_channel_islands_or_isle_of_man?
next question(:channel_islands_or_isle_of_man?)
next question :channel_islands_or_isle_of_man?
elsif calculator.has_passport_requiring_no_visa?
next outcome :outcome_no_visa_needed
elsif calculator.travelling_to_ireland?
if (calculator.passport_country_in_non_visa_national_list? ||
calculator.passport_country_in_eea? ||
calculator.passport_country_in_british_overseas_territories_list?) &&
!calculator.travel_document?
next outcome(:outcome_no_visa_needed)
else
next outcome(:outcome_transit_to_the_republic_of_ireland)
end
next outcome :outcome_transit_to_the_republic_of_ireland
elsif calculator.travelling_to_elsewhere?
if (calculator.passport_country_in_non_visa_national_list? ||
calculator.passport_country_in_eea? ||
calculator.passport_country_in_british_overseas_territories_list?) &&
!calculator.travel_document?
next outcome(:outcome_no_visa_needed)
else
next question(:passing_through_uk_border_control?)
end
next question :passing_through_uk_border_control?
end
end
end
Expand Down Expand Up @@ -153,26 +141,21 @@ def define
end

next_node do
if calculator.passing_through_uk_border_control?
if calculator.passport_country_is_taiwan?
outcome :outcome_transit_taiwan_through_border_control
elsif calculator.passport_country_in_visa_national_list? ||
calculator.passport_country_in_electronic_visa_waiver_list? ||
calculator.travel_document?
outcome :outcome_transit_leaving_airport
elsif calculator.passport_country_in_direct_airside_transit_visa_list?
outcome :outcome_transit_leaving_airport_direct_airside_transit_visa
end
if calculator.passing_through_uk_border_control? && calculator.passport_country_is_taiwan?
outcome :outcome_transit_taiwan_through_border_control
elsif calculator.passing_through_uk_border_control? && calculator.requires_a_visitor_in_transit_visa?
outcome :outcome_transit_leaving_airport
elsif calculator.passing_through_uk_border_control? && calculator.requires_a_direct_airside_transit_visa?
outcome :outcome_transit_leaving_airport_direct_airside_transit_visa
elsif calculator.passport_country_is_taiwan?
outcome :outcome_transit_taiwan
elsif calculator.passport_country_is_venezuela?
outcome :outcome_no_visa_needed
elsif calculator.applicant_is_stateless_or_a_refugee?
outcome :outcome_transit_refugee_not_leaving_airport
elsif calculator.passport_country_in_direct_airside_transit_visa_list?
elsif calculator.requires_a_direct_airside_transit_visa?
outcome :outcome_transit_not_leaving_airport
elsif calculator.passport_country_in_visa_national_list? ||
calculator.travel_document?
elsif calculator.no_transit_visa_is_required?
outcome :outcome_no_visa_needed
end
end
Expand All @@ -188,40 +171,14 @@ def define
end

next_node do
if calculator.staying_for_over_six_months?
if calculator.study_visit?
outcome :outcome_study_y # outcome 2 study y
elsif calculator.work_visit?
question :what_type_of_work?
end
elsif calculator.staying_for_six_months_or_less?
if calculator.study_visit?
if calculator.passport_country_in_electronic_visa_waiver_list?
outcome :outcome_study_waiver
elsif calculator.passport_country_is_taiwan?
outcome :outcome_study_waiver_taiwan
elsif calculator.passport_country_in_direct_airside_transit_visa_list? ||
calculator.passport_country_in_visa_national_list? ||
calculator.travel_document?
outcome :outcome_study_m # outcome 3 study m visa needed short courses
elsif calculator.passport_country_in_british_overseas_territories_list? || calculator.passport_country_in_non_visa_national_list? || calculator.passport_country_in_eea?
outcome :outcome_study_no_visa_needed # outcome 1 no visa needed
end
elsif calculator.work_visit?
if calculator.passport_country_in_electronic_visa_waiver_list?
outcome :outcome_work_waiver
elsif (calculator.passport_country_in_british_overseas_territories_list? ||
calculator.passport_country_is_taiwan? ||
calculator.passport_country_in_non_visa_national_list? ||
calculator.passport_country_in_eea?) &&
!calculator.travel_document?
# outcome 5.5 work N no visa needed
outcome :outcome_work_n
else
# outcome 5 work m visa needed short courses
outcome :outcome_work_m
end
end
if calculator.work_visit? && calculator.staying_for_over_six_months?
question :what_type_of_work?
elsif calculator.work_visit?
work_outcome = flow.work_visit_outcome_lambda.call calculator
outcome work_outcome unless work_outcome.nil?
elsif calculator.study_visit?
study_outcome = flow.study_visit_lambda.call calculator
outcome study_outcome unless study_outcome.nil?
end
end
end
Expand Down Expand Up @@ -339,41 +296,35 @@ def travel_response_next_route(node)
end

if calculator.school_visit?
if calculator.passport_country_in_electronic_visa_waiver_list?
if calculator.has_passport_requiring_electronic_visa_waiver_list?
next outcome(:outcome_school_waiver)
elsif calculator.passport_country_is_taiwan?
next outcome(:outcome_study_waiver_taiwan)
elsif calculator.passport_country_in_non_visa_national_list? || calculator.passport_country_in_british_overseas_territories_list? || calculator.passport_country_in_eea?
elsif calculator.has_passport_allowing_school_visits?
next outcome(:outcome_school_n)
else
next outcome(:outcome_school_y)
end
end

if calculator.medical_visit?
if calculator.passport_country_in_electronic_visa_waiver_list?
if calculator.has_passport_requiring_electronic_visa_waiver_list?
next outcome(:outcome_visit_waiver)
elsif calculator.passport_country_is_taiwan?
next outcome(:outcome_visit_waiver_taiwan)
elsif (calculator.passport_country_in_non_visa_national_list? ||
calculator.passport_country_in_eea? ||
calculator.passport_country_in_british_overseas_territories_list?) &&
!calculator.travel_document?
elsif calculator.has_passport_requiring_no_visa?
next outcome(:outcome_medical_n)
else
next outcome(:outcome_medical_y)
end
end

if calculator.tourism_visit?
if calculator.passport_country_in_electronic_visa_waiver_list?
if calculator.has_passport_requiring_electronic_visa_waiver_list?
next outcome(:outcome_visit_waiver)
elsif calculator.passport_country_is_taiwan?
next outcome(:outcome_visit_waiver_taiwan)
elsif (calculator.passport_country_in_non_visa_national_list? ||
calculator.passport_country_in_eea? ||
calculator.passport_country_in_british_overseas_territories_list?) &&
!calculator.travel_document?
elsif calculator.has_passport_requiring_no_visa?
next outcome(:outcome_tourism_n)
else
next question(:travelling_visiting_partner_family_member?)
Expand All @@ -385,11 +336,11 @@ def travel_response_next_route(node)
next outcome(:outcome_marriage_nvn_british_overseas_territories)
elsif calculator.passport_country_in_non_visa_national_list? || calculator.passport_country_in_british_overseas_territories_list?
next outcome(:outcome_marriage_nvn_british_overseas_territories)
elsif calculator.passport_country_in_electronic_visa_waiver_list?
elsif calculator.has_passport_requiring_electronic_visa_waiver_list?
next outcome(:outcome_marriage_electronic_visa_waiver)
elsif calculator.passport_country_is_taiwan?
next outcome(:outcome_marriage_taiwan)
elsif calculator.passport_country_in_direct_airside_transit_visa_list? || calculator.passport_country_in_visa_national_list?
elsif calculator.requires_a_direct_airside_transit_visa? || calculator.passport_country_in_visa_national_list?
next outcome(:outcome_marriage_visa_nat_direct_airside_transit_visa)
end
end
Expand All @@ -407,4 +358,44 @@ def travel_response_next_route(node)
end
end
end

def study_visit_lambda
lambda { |calculator|
if calculator.staying_for_over_six_months?
return :outcome_study_y # outcome 2 study y
elsif calculator.staying_for_six_months_or_less? && calculator.has_passport_requiring_electronic_visa_waiver_list?
return :outcome_study_waiver
elsif calculator.staying_for_six_months_or_less? && calculator.passport_country_is_taiwan?
return :outcome_study_waiver_taiwan
elsif calculator.staying_for_six_months_or_less? &&
(calculator.requires_a_direct_airside_transit_visa? ||
calculator.passport_country_in_visa_national_list? ||
calculator.travel_document?)

return :outcome_study_m # outcome 3 study m visa needed short courses
elsif calculator.staying_for_six_months_or_less? &&
(calculator.passport_country_in_british_overseas_territories_list? ||
calculator.passport_country_in_non_visa_national_list? ||
calculator.passport_country_in_eea?)

return :outcome_study_no_visa_needed # outcome 1 no visa needed
else
return nil
end
}
end

def work_visit_outcome_lambda
lambda { |calculator|
if calculator.staying_for_six_months_or_less? && calculator.has_passport_requiring_electronic_visa_waiver_list?
return :outcome_work_waiver
elsif calculator.staying_for_six_months_or_less? && calculator.short_work_visits_are_approved?
return :outcome_work_n # outcome 5.5 work N no visa needed
elsif calculator.staying_for_six_months_or_less?
return :outcome_work_m # outcome 5 work m visa needed short courses
else
return nil
end
}
end
end
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<% text_for :title do %>
<% if calculator.passport_country_in_electronic_visa_waiver_list? %>
<% if calculator.has_passport_requiring_electronic_visa_waiver_list? %>
You’ll need an electronic visa waiver (EVW) or a Visitor in Transit visa
<% else %>
You’ll need a visa to pass through the UK in transit
<% end %>
<% end %>

<% govspeak_for :body do %>
<% if calculator.passport_country_in_electronic_visa_waiver_list? %>
<% if calculator.has_passport_requiring_electronic_visa_waiver_list? %>
You must either apply for:

- an [electronic visa waiver](/get-electronic-visa-waiver)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% text_for :title do %>
<% if calculator.passport_country_is_taiwan? %>
You will not need a visa if your passport has a personal ID number on the bio data page.
<% elsif calculator.passport_country_in_electronic_visa_waiver_list? %>
<% elsif calculator.has_passport_requiring_electronic_visa_waiver_list? %>
You’ll need an electronic visa waiver (EVW) or a Standard Visitor visa
<% else %>
You’ll need a visa to pass through the UK (unless you’re exempt)
Expand All @@ -16,7 +16,7 @@
[Check what documents you need to bring](/government/publications/visitor-visa-guide-to-supporting-documents) to show officers at the UK border.

If your passport does not have a personal ID number on the bio data page you’ll usually need to apply for a [Standard Visitor visa](/standard-visitor).
<% elsif calculator.passport_country_in_electronic_visa_waiver_list? %>
<% elsif calculator.has_passport_requiring_electronic_visa_waiver_list? %>

You must either apply for:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<% if calculator.passport_country_in_british_overseas_territories_list? ||
calculator.passport_country_in_non_visa_national_list? %>
You might need a UK visa if you don’t have a visa (or a wet ink stamp) for the Channel Islands or the Isle of Man.
<% elsif calculator.passport_country_in_electronic_visa_waiver_list? %>
<% elsif calculator.has_passport_requiring_electronic_visa_waiver_list? %>
You’ll need a UK visa or an [Electronic Visa Waiver](/get-electronic-visa-waiver) if you don’t have a visa (or wet ink stamp) for the Channel Islands or the Isle of Man.
<% elsif calculator.passport_country_in_direct_airside_transit_visa_list? ||
<% elsif calculator.requires_a_direct_airside_transit_visa? ||
calculator.passport_country_in_visa_national_list? %>
You’ll need a UK visa if you don’t have a visa (or a wet ink stamp) for the Channel Islands or the Isle of Man.
<% else %>
Expand Down
38 changes: 32 additions & 6 deletions lib/smart_answer/calculators/uk_visa_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ def visas_for_outcome
}.compact
end

def visa_types_for_outcome
visas_for_outcome.map { |visa| visa["name"] }
end

def number_of_visas_for_outcome
@number_of_visas_for_outcome ||= visas_for_outcome.count
end
Expand All @@ -62,7 +58,7 @@ def passport_country_in_british_overseas_territories_list?
COUNTRY_GROUP_BRITISH_OVERSEAS_TERRITORIES.include?(@passport_country)
end

def passport_country_in_direct_airside_transit_visa_list?
def requires_a_direct_airside_transit_visa?
COUNTRY_GROUP_DIRECT_AIRSIDE_TRANSIT_VISA.include?(@passport_country)
end

Expand All @@ -74,7 +70,7 @@ def passport_country_in_uk_ancestry_visa_list?
COUNTRY_GROUP_UK_ANCESTRY_VISA.include?(@passport_country)
end

def passport_country_in_electronic_visa_waiver_list?
def has_passport_requiring_electronic_visa_waiver_list?
COUNTRY_GROUP_ELECTRONIC_VISA_WAIVER.include?(@passport_country)
end

Expand Down Expand Up @@ -206,6 +202,36 @@ def travelling_visiting_partner_family_member?
@travelling_visiting_partner_family_member_answer == "yes"
end

def short_work_visits_are_approved?
(passport_country_in_british_overseas_territories_list? ||
passport_country_is_taiwan? ||
passport_country_in_non_visa_national_list? ||
passport_country_in_eea?) &&
!travel_document?
end

def has_passport_requiring_no_visa?
(passport_country_in_non_visa_national_list? ||
passport_country_in_eea? ||
passport_country_in_british_overseas_territories_list?) &&
!travel_document?
end

def no_transit_visa_is_required?
passport_country_in_visa_national_list? ||
travel_document?
end

def requires_a_visitor_in_transit_visa?
passport_country_in_visa_national_list? ||
has_passport_requiring_electronic_visa_waiver_list? ||
travel_document?
end

def has_passport_allowing_school_visits?
passport_country_in_non_visa_national_list? || passport_country_in_british_overseas_territories_list? || passport_country_in_eea?
end

def study_or_work
if study_visit?
"study"
Expand Down
Loading