diff --git a/app/flows/check_uk_visa_flow.rb b/app/flows/check_uk_visa_flow.rb index 205cbeeea2d..8b554f10b1b 100644 --- a/app/flows/check_uk_visa_flow.rb +++ b/app/flows/check_uk_visa_flow.rb @@ -143,7 +143,7 @@ def define next_node do 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? && requires_a_visitor_in_transit_visa? + 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 @@ -171,10 +171,14 @@ def define end next_node do - if calculator.study_visit? - flow.outcome_study_visit + if calculator.work_visit? && calculator.staying_for_over_six_months? + question :what_type_of_work? elsif calculator.work_visit? - flow.next_node_for_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 @@ -355,36 +359,43 @@ def travel_response_next_route(node) end end -private - - - def next_node_for_work_visit - if calculator.staying_for_over_six_months? - question :what_type_of_work? - elsif calculator.staying_for_six_months_or_less? && calculator.has_passport_requiring_electronic_visa_waiver_list? - outcome :outcome_work_waiver - elsif calculator.staying_for_six_months_or_less? && calculator.short_work_visits_are_approved? - # outcome 5.5 work N no visa needed - outcome :outcome_work_n - elsif calculator.staying_for_six_months_or_less? - # outcome 5 work m visa needed short courses - outcome :outcome_work_m - end + def study_visit_lambda + lambda { |calculator| + if calculator.staying_for_over_six_months? + outcome = :outcome_study_y # outcome 2 study y + elsif calculator.staying_for_six_months_or_less? && calculator.has_passport_requiring_electronic_visa_waiver_list? + outcome = :outcome_study_waiver + elsif calculator.staying_for_six_months_or_less? && calculator.passport_country_is_taiwan? + outcome = :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?) + outcome = :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?) + outcome = :outcome_study_no_visa_needed # outcome 1 no visa needed + else + outcome = nil + end + return outcome + } end - def outcome_study_visit - if calculator.staying_for_over_six_months? - outcome :outcome_study_y # outcome 2 study y - elsif calculator.staying_for_six_months_or_less? && calculator.has_passport_requiring_electronic_visa_waiver_list? - outcome :outcome_study_waiver - elsif calculator.staying_for_six_months_or_less? && calculator.passport_country_is_taiwan? - outcome :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?) - outcome :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?) - outcome :outcome_study_no_visa_needed # outcome 1 no visa needed - end + def work_visit_outcome_lambda + lambda { |calculator| + if calculator.staying_for_six_months_or_less? && + calculator.has_passport_requiring_electronic_visa_waiver_list? + outcome = :outcome_work_waiver + elsif calculator.staying_for_six_months_or_less? && + calculator.short_work_visits_are_approved? + # outcome 5.5 work N no visa needed + outcome = :outcome_work_n + elsif calculator.staying_for_six_months_or_less? + # outcome 5 work m visa needed short courses + outcome = :outcome_work_m + else + outcome = nil + end + return outcome + } end end