From 3de52b653fab63d4016915e87c829bfb6a57d817 Mon Sep 17 00:00:00 2001 From: Felix Marcus Millne Date: Wed, 20 Sep 2023 14:17:51 +0100 Subject: [PATCH] convert check-uk-visa study and work flow blocks to lambdas - working around the edges of ruby method structures --- app/flows/check_uk_visa_flow.rb | 77 +++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/app/flows/check_uk_visa_flow.rb b/app/flows/check_uk_visa_flow.rb index 205cbeeea2d..85bf667ebfd 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_return flow.work_visit_outcome_lambda.call calculator + outcome work_outcome unless nil? + elsif calculator.study_visit? + study_return flow.study_visit_lambda.call calculator + outcome study_outcome unless 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? + 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 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? + 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