Skip to content

Commit 43212fa

Browse files
committed
Merge branch 'refactor-uk-benefits-abroad-to-remove-use-of-next-node-calculation-rebased'
See #2632.
2 parents 97ef48d + 4a6a21f commit 43212fa

File tree

3 files changed

+69
-53
lines changed

3 files changed

+69
-53
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module SmartAnswer::Calculators
2+
class UkBenefitsAbroadCalculator
3+
include ActiveModel::Model
4+
5+
COUNTRIES_OF_FORMER_YUGOSLAVIA = %w(bosnia-and-herzegovina kosovo macedonia montenegro serbia).freeze
6+
7+
attr_accessor :country
8+
9+
def eea_country?
10+
%w(austria belgium bulgaria croatia cyprus czech-republic denmark estonia
11+
finland france germany gibraltar greece hungary iceland ireland italy
12+
latvia liechtenstein lithuania luxembourg malta netherlands norway
13+
poland portugal romania slovakia slovenia spain sweden switzerland).include?(country)
14+
end
15+
16+
def former_yugoslavia?
17+
COUNTRIES_OF_FORMER_YUGOSLAVIA.include?(country)
18+
end
19+
20+
def social_security_countries_jsa?
21+
(COUNTRIES_OF_FORMER_YUGOSLAVIA + %w(guernsey jersey new-zealand)).include?(country)
22+
end
23+
24+
def social_security_countries_iidb?
25+
(COUNTRIES_OF_FORMER_YUGOSLAVIA +
26+
%w(barbados bermuda guernsey jersey israel jamaica mauritius philippines turkey)).include?(country)
27+
end
28+
29+
def social_security_countries_bereavement_benefits?
30+
(COUNTRIES_OF_FORMER_YUGOSLAVIA +
31+
%w(barbados bermuda canada guernsey jersey israel jamaica mauritius new-zealand philippines turkey usa)).include?(country)
32+
end
33+
end
34+
end

lib/smart_answer_flows/uk-benefits-abroad.rb

+33-52
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ def define
99
exclude_countries = %w(british-antarctic-territory french-guiana guadeloupe holy-see martinique mayotte reunion st-maarten)
1010
additional_countries = [OpenStruct.new(slug: "jersey", name: "Jersey"), OpenStruct.new(slug: "guernsey", name: "Guernsey")]
1111

12-
countries_of_former_yugoslavia = %w(bosnia-and-herzegovina kosovo macedonia montenegro serbia).freeze
12+
countries_of_former_yugoslavia = Calculators::UkBenefitsAbroadCalculator::COUNTRIES_OF_FORMER_YUGOSLAVIA
1313

1414
# Q1
1515
multiple_choice :going_or_already_abroad? do
1616
option :going_abroad
1717
option :already_abroad
1818
save_input_as :going_or_already_abroad
1919

20+
on_response do
21+
self.calculator = Calculators::UkBenefitsAbroadCalculator.new
22+
end
23+
2024
calculate :country_question_title do
2125
if going_or_already_abroad == "going_abroad"
2226
"Which country are you moving to?"
@@ -112,59 +116,36 @@ def define
112116

113117
## Country Question - Shared
114118
country_select :which_country?, additional_countries: additional_countries, exclude_countries: exclude_countries do
115-
save_input_as :country
116-
117-
calculate :country_name do
118-
(WorldLocation.all + additional_countries).find { |c| c.slug == country }.name
119+
on_response do |response|
120+
calculator.country = response
119121
end
120122

121-
next_node_calculation :responded_with_eea_country do |response|
122-
%w(austria belgium bulgaria croatia cyprus czech-republic denmark estonia
123-
finland france germany gibraltar greece hungary iceland ireland italy
124-
latvia liechtenstein lithuania luxembourg malta netherlands norway
125-
poland portugal romania slovakia slovenia spain sweden switzerland).include?(response)
126-
end
127-
128-
next_node_calculation :responded_with_former_yugoslavia do |response|
129-
countries_of_former_yugoslavia.include?(response)
130-
end
131-
132-
next_node_calculation :social_security_countries_jsa do |response|
133-
(countries_of_former_yugoslavia + %w(guernsey jersey new-zealand)).include?(response)
134-
end
135-
136-
next_node_calculation :social_security_countries_iidb do |response|
137-
(countries_of_former_yugoslavia +
138-
%w(barbados bermuda guernsey jersey israel jamaica mauritius philippines turkey)).include?(response)
139-
end
140-
141-
next_node_calculation :social_security_countries_bereavement_benefits do |response|
142-
(countries_of_former_yugoslavia +
143-
%w(barbados bermuda canada guernsey jersey israel jamaica mauritius new-zealand philippines turkey usa)).include?(response)
123+
calculate :country_name do
124+
(WorldLocation.all + additional_countries).find { |c| c.slug == calculator.country }.name
144125
end
145126

146127
next_node do |response|
147128
case benefit
148129
when 'jsa'
149-
if already_abroad && responded_with_eea_country
130+
if already_abroad && calculator.eea_country?
150131
outcome :jsa_eea_already_abroad_outcome # A3 already_abroad
151-
elsif already_abroad && social_security_countries_jsa
132+
elsif already_abroad && calculator.social_security_countries_jsa?
152133
outcome :jsa_social_security_already_abroad_outcome # A4 already_abroad
153-
elsif going_abroad && responded_with_eea_country
134+
elsif going_abroad && calculator.eea_country?
154135
outcome :jsa_eea_going_abroad_outcome # A5 going_abroad
155-
elsif going_abroad && social_security_countries_jsa
136+
elsif going_abroad && calculator.social_security_countries_jsa?
156137
outcome :jsa_social_security_going_abroad_outcome # A6 going_abroad
157138
else
158139
outcome :jsa_not_entitled_outcome # A7 going_abroad and A5 already_abroad
159140
end
160141
when 'maternity_benefits'
161-
if responded_with_eea_country
142+
if calculator.eea_country?
162143
question :working_for_a_uk_employer? # Q8 going_abroad and Q7 already_abroad
163144
else
164145
question :employer_paying_ni? # Q10, Q11, Q16 going_abroad and Q9, Q10, Q15 already_abroad
165146
end
166147
when 'winter_fuel_payment'
167-
if responded_with_eea_country
148+
if calculator.eea_country?
168149
if going_abroad
169150
outcome :wfp_going_abroad_outcome # A9 going_abroad
170151
else
@@ -174,9 +155,9 @@ def define
174155
outcome :wfp_not_eligible_outcome # A8 going_abroad and A6 already_abroad
175156
end
176157
when 'child_benefit'
177-
if responded_with_eea_country
158+
if calculator.eea_country?
178159
question :do_either_of_the_following_apply? # Q13 going_abroad and Q12 already_abroad
179-
elsif responded_with_former_yugoslavia
160+
elsif calculator.former_yugoslavia?
180161
if going_abroad
181162
outcome :child_benefit_fy_going_abroad_outcome # A14 going_abroad
182163
else
@@ -191,57 +172,57 @@ def define
191172
end
192173
when 'iidb'
193174
if going_abroad
194-
if responded_with_eea_country
175+
if calculator.eea_country?
195176
outcome :iidb_going_abroad_eea_outcome # A32 going_abroad
196-
elsif social_security_countries_iidb
177+
elsif calculator.social_security_countries_iidb?
197178
outcome :iidb_going_abroad_ss_outcome # A33 going_abroad
198179
else
199180
outcome :iidb_going_abroad_other_outcome # A34 going_abroad
200181
end
201182
elsif already_abroad
202-
if responded_with_eea_country
183+
if calculator.eea_country?
203184
outcome :iidb_already_abroad_eea_outcome # A31 already_abroad
204-
elsif social_security_countries_iidb
185+
elsif calculator.social_security_countries_iidb?
205186
outcome :iidb_already_abroad_ss_outcome # A32 already_abroad
206187
else
207188
outcome :iidb_already_abroad_other_outcome # A33 already_abroad
208189
end
209190
end
210191
when 'disability_benefits'
211-
if responded_with_eea_country
192+
if calculator.eea_country?
212193
question :db_claiming_benefits? # Q30 going_abroad and Q29 already_abroad
213194
elsif going_abroad
214195
outcome :db_going_abroad_other_outcome # A36 going_abroad
215196
else
216197
outcome :db_already_abroad_other_outcome # A35 already_abroad
217198
end
218199
when 'ssp'
219-
if responded_with_eea_country
200+
if calculator.eea_country?
220201
question :working_for_uk_employer_ssp? # Q15 going_abroad and Q14 already_abroad
221202
else
222203
question :employer_paying_ni? # Q10, Q11, Q16 going_abroad and Q9, Q10, Q15 already_abroad
223204
end
224205
when 'tax_credits'
225-
if responded_with_eea_country
206+
if calculator.eea_country?
226207
question :tax_credits_currently_claiming? # Q20 already_abroad
227208
else
228209
outcome :tax_credits_unlikely_outcome # A21 already_abroad and A23 going_abroad
229210
end
230211
when 'esa'
231212
if going_abroad
232-
if responded_with_eea_country
213+
if calculator.eea_country?
233214
outcome :esa_going_abroad_eea_outcome # A29 going_abroad
234-
elsif responded_with_former_yugoslavia
215+
elsif calculator.former_yugoslavia?
235216
outcome :esa_going_abroad_eea_outcome
236217
elsif %w(barbados guernsey israel jersey jamaica turkey usa).include?(response)
237218
outcome :esa_going_abroad_eea_outcome
238219
else
239220
outcome :esa_going_abroad_other_outcome # A30 going_abroad
240221
end
241222
elsif already_abroad
242-
if responded_with_eea_country
223+
if calculator.eea_country?
243224
outcome :esa_already_abroad_eea_outcome # A27 already_abroad
244-
elsif responded_with_former_yugoslavia
225+
elsif calculator.former_yugoslavia?
245226
outcome :esa_already_abroad_ss_outcome # A28 already_abroad
246227
elsif %w(barbados jersey guernsey jamaica turkey usa).include?(response)
247228
outcome :esa_already_abroad_ss_outcome
@@ -251,17 +232,17 @@ def define
251232
end
252233
when 'bereavement_benefits'
253234
if going_abroad
254-
if responded_with_eea_country
235+
if calculator.eea_country?
255236
outcome :bb_going_abroad_eea_outcome # A39 going_abroad
256-
elsif social_security_countries_bereavement_benefits
237+
elsif calculator.social_security_countries_bereavement_benefits?
257238
outcome :bb_going_abroad_ss_outcome # A40 going_abroad
258239
else
259240
outcome :bb_going_abroad_other_outcome # A38 going_abroad
260241
end
261242
elsif already_abroad
262-
if responded_with_eea_country
243+
if calculator.eea_country?
263244
outcome :bb_already_abroad_eea_outcome # A37 already_abroad
264-
elsif social_security_countries_bereavement_benefits
245+
elsif calculator.social_security_countries_bereavement_benefits?
265246
outcome :bb_already_abroad_ss_outcome # A38 already_abroad
266247
else
267248
outcome :bb_already_abroad_other_outcome # A39 already_abroad
@@ -326,7 +307,7 @@ def define
326307
#not SSP benefits
327308
if response == 'yes'
328309
question :eligible_for_smp? # Q9 going_abroad and Q8 already_abroad
329-
elsif (countries_of_former_yugoslavia + %w(barbados guernsey jersey israel turkey)).include?(country)
310+
elsif (countries_of_former_yugoslavia + %w(barbados guernsey jersey israel turkey)).include?(calculator.country)
330311
if already_abroad
331312
outcome :maternity_benefits_social_security_already_abroad_outcome # A10 already_abroad
332313
else

test/data/uk-benefits-abroad-files.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
lib/smart_answer_flows/uk-benefits-abroad.rb: 62cbeec29d3f571985efdcb0c540eb18
2+
lib/smart_answer_flows/uk-benefits-abroad.rb: 866546b9bf29daa90b9b53f43171ac8c
33
test/data/uk-benefits-abroad-questions-and-responses.yml: 279454ec0916c13ac09ed5a90ad58777
44
test/data/uk-benefits-abroad-responses-and-expected-results.yml: dbf714c4de3ed03f81c868c354aa9c81
55
lib/smart_answer_flows/uk-benefits-abroad/outcomes/_tax_credits_already_abroad_helpline.govspeak.erb: d79b1b09c2fe01c66cdda028a7679b8b
@@ -96,3 +96,4 @@ lib/smart_answer_flows/uk-benefits-abroad/questions/which_country.govspeak.erb:
9696
lib/smart_answer_flows/uk-benefits-abroad/questions/working_for_a_uk_employer.govspeak.erb: 8367cff3d1d36a843d6d966a547d179b
9797
lib/smart_answer_flows/uk-benefits-abroad/questions/working_for_uk_employer_ssp.govspeak.erb: 15e9162bb80fe215af169d0e39dd53d0
9898
lib/smart_answer_flows/uk-benefits-abroad/uk_benefits_abroad.govspeak.erb: 289ed7bd184696294095c760f24ffb0d
99+
lib/smart_answer/calculators/uk_benefits_abroad_calculator.rb: 7ef61bd2e7662905c1189918d3701b79

0 commit comments

Comments
 (0)