Browse Source

Cldc 1440 household situation section (#1132)

* feat: add question page and subsection (#1120)

* feat: add question page and subsection

* refactor: linting

* feat: remove schema rows from other branch

* feat: slight refactor, fix tag behaviour and add section tests

* test: update and add tests

* feat: update status behaviour

* feat: update subsection status tag

* refactor: linting

* [CLDC-857] Add household wheelchair check (#1122)

* [CLDC-857] Add household wheelchair check

* Hide only if answered

* Cldc 1497 ever served armed forces (#1124)

* feat: add question and page

* test: update tests

* refactor: linting and slight test updates

* test: fix tests

* Cldc 1498 still serving armed forces (#1123)

* feat: new question and tests

* test: update subsection spec

* test: update tests

* feat: (future) conflict resolving

* feat: more conflict resolution

* feat: update db field

* test: update id

* test: updates

* Cldc 1488 last accomodation (#1125)

* Add postcode fields

* Add previous postcode page and questions

* Add last accommodation page to household situation subsection

* add previous la known to the db

* infer correct location fields

* styling

* Reorder disability questions (#1127)

* [CLDC-1487] Add buyer1 previous tenure question (#1133)

* use collection_start_year instead of the startdate (#1128)

* [CLDC-1487] Add buyer 1 previous tenure

Co-authored-by: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>

* feat: fix routing (#1141)

* Add last accommodation la question (#1142)

* move hint text (#1146)

Co-authored-by: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com>
Co-authored-by: Jack S <113976590+bibblobcode@users.noreply.github.com>
pull/1150/head^2
kosiakkatrina 2 years ago committed by GitHub
parent
commit
7d02752d82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/models/form/question.rb
  2. 15
      app/models/form/sales/pages/armed_forces.rb
  3. 15
      app/models/form/sales/pages/buyer1_previous_tenure.rb
  4. 18
      app/models/form/sales/pages/buyer_still_serving.rb
  5. 15
      app/models/form/sales/pages/buyers_organisations.rb
  6. 20
      app/models/form/sales/pages/household_wheelchair_check.rb
  7. 16
      app/models/form/sales/pages/last_accommodation.rb
  8. 19
      app/models/form/sales/pages/last_accommodation_la.rb
  9. 19
      app/models/form/sales/questions/armed_forces.rb
  10. 22
      app/models/form/sales/questions/buyer1_previous_tenure.rb
  11. 19
      app/models/form/sales/questions/buyer_still_serving.rb
  12. 19
      app/models/form/sales/questions/buyers_organisations.rb
  13. 25
      app/models/form/sales/questions/household_wheelchair_check.rb
  14. 30
      app/models/form/sales/questions/previous_la_known.rb
  15. 23
      app/models/form/sales/questions/previous_postcode.rb
  16. 20
      app/models/form/sales/questions/previous_postcode_known.rb
  17. 405
      app/models/form/sales/questions/prevloc.rb
  18. 1
      app/models/form/sales/sections/household.rb
  19. 5
      app/models/form/sales/subsections/household_needs.rb
  20. 18
      app/models/form/sales/subsections/household_situation.rb
  21. 2
      app/models/form/subsection.rb
  22. 28
      app/models/lettings_log.rb
  23. 28
      app/models/log.rb
  24. 24
      app/models/sales_log.rb
  25. 6
      app/models/validations/sales/soft_validations.rb
  26. 7
      db/migrate/20221222105044_add_wheel_value_check.rb
  27. 10
      db/migrate/20221222153059_add_buyers_organisations_to_sales_log.rb
  28. 13
      db/migrate/20221223105623_add_postcode_fields.rb
  29. 7
      db/migrate/20221223134818_add_armed_forces_to_sales_log.rb
  30. 7
      db/migrate/20221223151033_add_still_serving_to_sales.rb
  31. 7
      db/migrate/20230103135135_add_prevten.rb
  32. 13
      db/migrate/20230104164318_change_previous_la_known_type.rb
  33. 17
      db/schema.rb
  34. 11
      spec/factories/sales_log.rb
  35. 29
      spec/models/form/sales/pages/armed_forces_spec.rb
  36. 25
      spec/models/form/sales/pages/buyer1_previous_tenure_spec.rb
  37. 33
      spec/models/form/sales/pages/buyer_still_serving_spec.rb
  38. 33
      spec/models/form/sales/pages/buyers_organisations_spec.rb
  39. 33
      spec/models/form/sales/pages/household_wheelchair_check_spec.rb
  40. 35
      spec/models/form/sales/pages/last_accommodation_la_spec.rb
  41. 33
      spec/models/form/sales/pages/last_accommodation_spec.rb
  42. 46
      spec/models/form/sales/questions/armed_forces_spec.rb
  43. 46
      spec/models/form/sales/questions/buyer1_previous_tenure_spec.rb
  44. 46
      spec/models/form/sales/questions/buyer_still_serving_spec.rb
  45. 48
      spec/models/form/sales/questions/buyers_organisations_spec.rb
  46. 48
      spec/models/form/sales/questions/household_wheelchair_check_spec.rb
  47. 65
      spec/models/form/sales/questions/previous_la_known_spec.rb
  48. 50
      spec/models/form/sales/questions/previous_postcode_known_spec.rb
  49. 58
      spec/models/form/sales/questions/previous_postcode_spec.rb
  50. 433
      spec/models/form/sales/questions/prevloc_spec.rb
  51. 1
      spec/models/form/sales/sections/household_spec.rb
  52. 37
      spec/models/form/sales/subsections/household_needs_spec.rb
  53. 36
      spec/models/form/sales/subsections/household_situation_spec.rb
  54. 4
      spec/models/form_handler_spec.rb
  55. 66
      spec/models/sales_log_spec.rb

6
app/models/form/question.rb

@ -129,6 +129,12 @@ class Form::Question
"/#{log.model_name.param_key.dasherize}s/#{log.id}/#{page_id.to_s.dasherize}?referrer=check_answers"
end
def unanswered?(log)
return answer_options.keys.none? { |key| value_is_yes?(log[key]) } if type == "checkbox"
log[id].blank?
end
def completed?(log)
return answer_options.keys.any? { |key| value_is_yes?(log[key]) } if type == "checkbox"

15
app/models/form/sales/pages/armed_forces.rb

@ -0,0 +1,15 @@
class Form::Sales::Pages::ArmedForces < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "armed_forces"
@header = ""
@description = ""
@subsection = subsection
end
def questions
@questions ||= [
Form::Sales::Questions::ArmedForces.new(nil, nil, self),
]
end
end

15
app/models/form/sales/pages/buyer1_previous_tenure.rb

@ -0,0 +1,15 @@
class Form::Sales::Pages::Buyer1PreviousTenure < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer1_previous_tenure"
@header = "What was buyer 1's previous tenure?"
@description = ""
@subsection = subsection
end
def questions
@questions ||= [
Form::Sales::Questions::Buyer1PreviousTenure.new(nil, nil, self),
]
end
end

18
app/models/form/sales/pages/buyer_still_serving.rb

@ -0,0 +1,18 @@
class Form::Sales::Pages::BuyerStillServing < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_still_serving"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [{
"hhregres" => 1,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::BuyerStillServing.new(nil, nil, self),
]
end
end

15
app/models/form/sales/pages/buyers_organisations.rb

@ -0,0 +1,15 @@
class Form::Sales::Pages::BuyersOrganisations < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyers_organisations"
@header = ""
@description = ""
@subsection = subsection
end
def questions
@questions ||= [
Form::Sales::Questions::BuyersOrganisations.new(nil, nil, self),
]
end
end

20
app/models/form/sales/pages/household_wheelchair_check.rb

@ -0,0 +1,20 @@
class Form::Sales::Pages::HouseholdWheelchairCheck < ::Form::Page
def initialize(id, hsh, subsection)
super
@header = ""
@description = ""
@subsection = subsection
@depends_on = [
{
"wheelchair_when_not_disabled?" => true,
},
]
@informative_text = {}
end
def questions
@questions ||= [
Form::Sales::Questions::HouseholdWheelchairCheck.new(nil, nil, self),
]
end
end

16
app/models/form/sales/pages/last_accommodation.rb

@ -0,0 +1,16 @@
class Form::Sales::Pages::LastAccommodation < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "last_accommodation"
@header = ""
@description = ""
@subsection = subsection
end
def questions
@questions ||= [
Form::Sales::Questions::PreviousPostcodeKnown.new(nil, nil, self),
Form::Sales::Questions::PreviousPostcode.new(nil, nil, self),
]
end
end

19
app/models/form/sales/pages/last_accommodation_la.rb

@ -0,0 +1,19 @@
class Form::Sales::Pages::LastAccommodationLa < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "last_accommodation_la"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [{
"is_previous_la_inferred" => false,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::PreviousLaKnown.new(nil, nil, self),
Form::Sales::Questions::Prevloc.new(nil, nil, self),
]
end
end

19
app/models/form/sales/questions/armed_forces.rb

@ -0,0 +1,19 @@
class Form::Sales::Questions::ArmedForces < ::Form::Question
def initialize(id, hsh, page)
super
@id = "hhregres"
@check_answer_label = "Have any of the buyers ever served as a regular in the UK armed forces?"
@header = "Have any of the buyers ever served as a regular in the UK armed forces?"
@type = "radio"
@hint_text = "A regular is somebody who has served in the Royal Navy, the Royal Marines, the Royal Airforce or Army full time and does not include reserve forces"
@answer_options = ANSWER_OPTIONS
@page = page
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"7" => { "value" => "No" },
"3" => { "value" => "Buyer prefers not to say" },
"8" => { "value" => "Don't know" },
}.freeze
end

22
app/models/form/sales/questions/buyer1_previous_tenure.rb

@ -0,0 +1,22 @@
class Form::Sales::Questions::Buyer1PreviousTenure < ::Form::Question
def initialize(id, hsh, page)
super
@id = "prevten"
@check_answer_label = "Buyer 1's previous tenure"
@header = "What was buyer 1's previous tenure?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
end
ANSWER_OPTIONS = {
"1" => { "value" => "Local Authority" },
"2" => { "value" => "Private registered provider or housing association tenant" },
"3" => { "value" => "Private tenant" },
"5" => { "value" => "Owner occupier" },
"4" => { "value" => "Tied home or renting with job" },
"6" => { "value" => "Living with family or friends" },
"7" => { "value" => "Temporary accomodation" },
"9" => { "value" => "Other" },
}.freeze
end

19
app/models/form/sales/questions/buyer_still_serving.rb

@ -0,0 +1,19 @@
class Form::Sales::Questions::BuyerStillServing < ::Form::Question
def initialize(id, hsh, page)
super
@id = "hhregresstill"
@check_answer_label = "Are they still serving in the UK armed forces?"
@header = "Is the buyer still serving in the UK armed forces?"
@type = "radio"
@hint_text = ""
@answer_options = ANSWER_OPTIONS
@page = page
end
ANSWER_OPTIONS = {
"4" => { "value" => "Yes" },
"5" => { "value" => "No" },
"6" => { "value" => "Buyer prefers not to say" },
"7" => { "value" => "Don't know" },
}.freeze
end

19
app/models/form/sales/questions/buyers_organisations.rb

@ -0,0 +1,19 @@
class Form::Sales::Questions::BuyersOrganisations < ::Form::Question
def initialize(id, hsh, page)
super
@id = "buyers_organisations"
@check_answer_label = "Organisations buyers were registered with"
@header = "What organisations were the buyers registered with?"
@type = "checkbox"
@hint_text = "Select all that apply"
@page = page
@answer_options = ANSWER_OPTIONS
end
ANSWER_OPTIONS = {
"pregyrha" => { "value" => "Their private registered provider (PRP) - housing association" },
"pregother" => { "value" => "Other private registered provider (PRP) - housing association" },
"pregla" => { "value" => "Local Authority" },
"pregghb" => { "value" => "Help to Buy Agent" },
}.freeze
end

25
app/models/form/sales/questions/household_wheelchair_check.rb

@ -0,0 +1,25 @@
class Form::Sales::Questions::HouseholdWheelchairCheck < ::Form::Question
def initialize(id, hsh, page)
super
@id = "wheel_value_check"
@check_answer_label = "Does anyone in the household use a wheelchair?"
@header = "Are you sure? You said previously that somebody in household uses a wheelchair"
@type = "interruption_screen"
@page = page
@answer_options = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}
@hidden_in_check_answers = {
"depends_on" => [
{
"wheel_value_check" => 0,
},
{
"wheel_value_check" => 1,
},
],
}
@page = page
end
end

30
app/models/form/sales/questions/previous_la_known.rb

@ -0,0 +1,30 @@
class Form::Sales::Questions::PreviousLaKnown < ::Form::Question
def initialize(id, hsh, page)
super
@id = "previous_la_known"
@check_answer_label = "Local authority of buyer 1’s last settled accommodation"
@header = "Do you know the local authority of buyer 1’s last settled accommodation?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = "This is also known as the household’s 'last settled home'"
@hidden_in_check_answers = {
"depends_on" => [
{
"previous_la_known" => 0,
},
{
"previous_la_known" => 1,
},
],
}
@conditional_for = {
"prevloc" => [1],
}
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"0" => { "value" => "No" },
}.freeze
end

23
app/models/form/sales/questions/previous_postcode.rb

@ -0,0 +1,23 @@
class Form::Sales::Questions::PreviousPostcode < ::Form::Question
def initialize(id, hsh, page)
super
@id = "ppostcode_full"
@check_answer_label = "Postcode of buyer 1’s last settled accommodation"
@header = "Postcode"
@page = page
@type = "text"
@width = 5
@hint_text = ""
@inferred_check_answers_value = {
"condition" => {
"ppcodenk" => 1,
},
"value" => "Not known",
}
@inferred_answers = {
"prevloc" => {
"is_previous_la_inferred" => true,
},
}
end
end

20
app/models/form/sales/questions/previous_postcode_known.rb

@ -0,0 +1,20 @@
class Form::Sales::Questions::PreviousPostcodeKnown < ::Form::Question
def initialize(id, hsh, page)
super
@id = "ppcodenk"
@check_answer_label = "Buyer 1’s last settled accommodation"
@header = "Do you know the postcode of buyer 1’s last settled accommodation?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@conditional_for = {
"ppostcode_full" => [0],
}
@hint_text = "This is also known as the household’s 'last settled home'"
end
ANSWER_OPTIONS = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}.freeze
end

405
app/models/form/sales/questions/prevloc.rb

@ -0,0 +1,405 @@
class Form::Sales::Questions::Prevloc < ::Form::Question
def initialize(id, hsh, page)
super
@id = "prevloc"
@check_answer_label = "Local authority of buyer 1’s last settled accommodation"
@header = "Select a local authority"
@type = "select"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = ""
@inferred_check_answers_value = {
"condition" => {
"previous_la_known" => 0,
},
"value" => "Not known",
}
end
ANSWER_OPTIONS = {
"" => "Select an option",
"S12000033" => "Aberdeen City",
"S12000034" => "Aberdeenshire",
"E07000223" => "Adur",
"E07000026" => "Allerdale",
"E07000032" => "Amber Valley",
"S12000041" => "Angus",
"N09000001" => "Antrim and Newtownabbey",
"N09000011" => "Ards and North Down",
"S12000035" => "Argyll and Bute",
"N09000002" => "Armagh City, Banbridge and Craigavon",
"E07000224" => "Arun",
"E07000170" => "Ashfield",
"E07000105" => "Ashford",
"E07000200" => "Babergh",
"E09000002" => "Barking and Dagenham",
"E09000003" => "Barnet",
"E08000016" => "Barnsley",
"E07000027" => "Barrow-in-Furness",
"E07000066" => "Basildon",
"E07000084" => "Basingstoke and Deane",
"E07000171" => "Bassetlaw",
"E06000022" => "Bath and North East Somerset",
"E06000055" => "Bedford",
"N09000003" => "Belfast",
"E09000004" => "Bexley",
"E08000025" => "Birmingham",
"E07000129" => "Blaby",
"E06000008" => "Blackburn with Darwen",
"E06000009" => "Blackpool",
"W06000019" => "Blaenau Gwent",
"E07000033" => "Bolsover",
"E08000001" => "Bolton",
"E07000136" => "Boston",
"E06000058" => "Bournemouth, Christchurch and Poole",
"E06000036" => "Bracknell Forest",
"E08000032" => "Bradford",
"E07000067" => "Braintree",
"E07000143" => "Breckland",
"E09000005" => "Brent",
"E07000068" => "Brentwood",
"W06000013" => "Bridgend",
"E06000043" => "Brighton and Hove",
"E06000023" => "Bristol, City of",
"E07000144" => "Broadland",
"E09000006" => "Bromley",
"E07000234" => "Bromsgrove",
"E07000095" => "Broxbourne",
"E07000172" => "Broxtowe",
"E06000060" => "Buckinghamshire",
"E07000117" => "Burnley",
"E08000002" => "Bury",
"W06000018" => "Caerphilly",
"E08000033" => "Calderdale",
"E07000008" => "Cambridge",
"E09000007" => "Camden",
"E07000192" => "Cannock Chase",
"E07000106" => "Canterbury",
"W06000015" => "Cardiff",
"E07000028" => "Carlisle",
"W06000010" => "Carmarthenshire",
"E07000069" => "Castle Point",
"N09000004" => "Causeway Coast and Glens",
"E06000056" => "Central Bedfordshire",
"W06000008" => "Ceredigion",
"E07000130" => "Charnwood",
"E07000070" => "Chelmsford",
"E07000078" => "Cheltenham",
"E07000177" => "Cherwell",
"E06000049" => "Cheshire East",
"E06000050" => "Cheshire West and Chester",
"E07000034" => "Chesterfield",
"E07000225" => "Chichester",
"E07000118" => "Chorley",
"S12000036" => "City of Edinburgh",
"E09000001" => "City of London",
"S12000005" => "Clackmannanshire",
"E07000071" => "Colchester",
"W06000003" => "Conwy",
"E07000029" => "Copeland",
"E07000150" => "Corby",
"E06000052" => "Cornwall",
"E07000079" => "Cotswold",
"E06000047" => "County Durham",
"E08000026" => "Coventry",
"E07000163" => "Craven",
"E07000226" => "Crawley",
"E09000008" => "Croydon",
"E07000096" => "Dacorum",
"E06000005" => "Darlington",
"E07000107" => "Dartford",
"E07000151" => "Daventry",
"W06000004" => "Denbighshire",
"E06000015" => "Derby",
"E07000035" => "Derbyshire Dales",
"N09000005" => "Derry City and Strabane",
"E08000017" => "Doncaster",
"E06000059" => "Dorset",
"E07000108" => "Dover",
"E08000027" => "Dudley",
"S12000006" => "Dumfries and Galloway",
"S12000042" => "Dundee City",
"E09000009" => "Ealing",
"S12000008" => "East Ayrshire",
"E07000009" => "East Cambridgeshire",
"E07000040" => "East Devon",
"S12000045" => "East Dunbartonshire",
"E07000085" => "East Hampshire",
"E07000242" => "East Hertfordshire",
"E07000137" => "East Lindsey",
"S12000010" => "East Lothian",
"E07000152" => "East Northamptonshire",
"S12000011" => "East Renfrewshire",
"E06000011" => "East Riding of Yorkshire",
"E07000193" => "East Staffordshire",
"E07000244" => "East Suffolk",
"E07000061" => "Eastbourne",
"E07000086" => "Eastleigh",
"E07000030" => "Eden",
"E07000207" => "Elmbridge",
"E09000010" => "Enfield",
"E07000072" => "Epping Forest",
"E07000208" => "Epsom and Ewell",
"E07000036" => "Erewash",
"E07000041" => "Exeter",
"S12000014" => "Falkirk",
"E07000087" => "Fareham",
"E07000010" => "Fenland",
"N09000006" => "Fermanagh and Omagh",
"S12000047" => "Fife",
"W06000005" => "Flintshire",
"E07000112" => "Folkestone and Hythe",
"E07000080" => "Forest of Dean",
"E07000119" => "Fylde",
"E08000037" => "Gateshead",
"E07000173" => "Gedling",
"S12000049" => "Glasgow City",
"E07000081" => "Gloucester",
"E07000088" => "Gosport",
"E07000109" => "Gravesham",
"E07000145" => "Great Yarmouth",
"E09000011" => "Greenwich",
"E07000209" => "Guildford",
"W06000002" => "Gwynedd",
"E09000012" => "Hackney",
"E06000006" => "Halton",
"E07000164" => "Hambleton",
"E09000013" => "Hammersmith and Fulham",
"E07000131" => "Harborough",
"E09000014" => "Haringey",
"E07000073" => "Harlow",
"E07000165" => "Harrogate",
"E09000015" => "Harrow",
"E07000089" => "Hart",
"E06000001" => "Hartlepool",
"E07000062" => "Hastings",
"E07000090" => "Havant",
"E09000016" => "Havering",
"E06000019" => "Herefordshire, County of",
"E07000098" => "Hertsmere",
"E07000037" => "High Peak",
"S12000017" => "Highland",
"E09000017" => "Hillingdon",
"E07000132" => "Hinckley and Bosworth",
"E07000227" => "Horsham",
"E09000018" => "Hounslow",
"E07000011" => "Huntingdonshire",
"E07000120" => "Hyndburn",
"S12000018" => "Inverclyde",
"E07000202" => "Ipswich",
"W06000001" => "Isle of Anglesey",
"E06000046" => "Isle of Wight",
"E06000053" => "Isles of Scilly",
"E09000019" => "Islington",
"E09000020" => "Kensington and Chelsea",
"E07000153" => "Kettering",
"E07000146" => "King’s Lynn and West Norfolk",
"E06000010" => "Kingston upon Hull, City of",
"E09000021" => "Kingston upon Thames",
"E08000034" => "Kirklees",
"E08000011" => "Knowsley",
"E09000022" => "Lambeth",
"E07000121" => "Lancaster",
"E08000035" => "Leeds",
"E06000016" => "Leicester",
"E07000063" => "Lewes",
"E09000023" => "Lewisham",
"E07000194" => "Lichfield",
"E07000138" => "Lincoln",
"N09000007" => "Lisburn and Castlereagh",
"E08000012" => "Liverpool",
"E06000032" => "Luton",
"E07000110" => "Maidstone",
"E07000074" => "Maldon",
"E07000235" => "Malvern Hills",
"E08000003" => "Manchester",
"E07000174" => "Mansfield",
"E06000035" => "Medway",
"E07000133" => "Melton",
"E07000187" => "Mendip",
"W06000024" => "Merthyr Tydfil",
"E09000024" => "Merton",
"E07000042" => "Mid Devon",
"E07000203" => "Mid Suffolk",
"E07000228" => "Mid Sussex",
"N09000009" => "Mid Ulster",
"N09000008" => "Mid and East Antrim",
"E06000002" => "Middlesbrough",
"S12000019" => "Midlothian",
"E06000042" => "Milton Keynes",
"E07000210" => "Mole Valley",
"W06000021" => "Monmouthshire",
"S12000020" => "Moray",
"S12000013" => "Na h-Eileanan Siar",
"W06000012" => "Neath Port Talbot",
"E07000091" => "New Forest",
"E07000175" => "Newark and Sherwood",
"E08000021" => "Newcastle upon Tyne",
"E07000195" => "Newcastle-under-Lyme",
"E09000025" => "Newham",
"W06000022" => "Newport",
"N09000010" => "Newry, Mourne and Down",
"S12000021" => "North Ayrshire",
"E07000043" => "North Devon",
"E07000038" => "North East Derbyshire",
"E06000012" => "North East Lincolnshire",
"E07000099" => "North Hertfordshire",
"E07000139" => "North Kesteven",
"S12000050" => "North Lanarkshire",
"E06000013" => "North Lincolnshire",
"E07000147" => "North Norfolk",
"E06000024" => "North Somerset",
"E08000022" => "North Tyneside",
"E07000218" => "North Warwickshire",
"E07000134" => "North West Leicestershire",
"E07000154" => "Northampton",
"E06000057" => "Northumberland",
"E07000148" => "Norwich",
"E06000018" => "Nottingham",
"E07000219" => "Nuneaton and Bedworth",
"E07000135" => "Oadby and Wigston",
"E08000004" => "Oldham",
"S12000023" => "Orkney Islands",
"E07000178" => "Oxford",
"W06000009" => "Pembrokeshire",
"E07000122" => "Pendle",
"S12000048" => "Perth and Kinross",
"E06000031" => "Peterborough",
"E06000026" => "Plymouth",
"E06000044" => "Portsmouth",
"W06000023" => "Powys",
"E07000123" => "Preston",
"E06000038" => "Reading",
"E09000026" => "Redbridge",
"E06000003" => "Redcar and Cleveland",
"E07000236" => "Redditch",
"E07000211" => "Reigate and Banstead",
"S12000038" => "Renfrewshire",
"W06000016" => "Rhondda Cynon Taf",
"E07000124" => "Ribble Valley",
"E09000027" => "Richmond upon Thames",
"E07000166" => "Richmondshire",
"E08000005" => "Rochdale",
"E07000075" => "Rochford",
"E07000125" => "Rossendale",
"E07000064" => "Rother",
"E08000018" => "Rotherham",
"E07000220" => "Rugby",
"E07000212" => "Runnymede",
"E07000176" => "Rushcliffe",
"E07000092" => "Rushmoor",
"E06000017" => "Rutland",
"E07000167" => "Ryedale",
"E08000006" => "Salford",
"E08000028" => "Sandwell",
"E07000168" => "Scarborough",
"S12000026" => "Scottish Borders",
"E07000188" => "Sedgemoor",
"E08000014" => "Sefton",
"E07000169" => "Selby",
"E07000111" => "Sevenoaks",
"E08000019" => "Sheffield",
"S12000027" => "Shetland Islands",
"E06000051" => "Shropshire",
"E06000039" => "Slough",
"E08000029" => "Solihull",
"E07000246" => "Somerset West and Taunton",
"S12000028" => "South Ayrshire",
"E07000012" => "South Cambridgeshire",
"E07000039" => "South Derbyshire",
"E06000025" => "South Gloucestershire",
"E07000044" => "South Hams",
"E07000140" => "South Holland",
"E07000141" => "South Kesteven",
"E07000031" => "South Lakeland",
"S12000029" => "South Lanarkshire",
"E07000149" => "South Norfolk",
"E07000155" => "South Northamptonshire",
"E07000179" => "South Oxfordshire",
"E07000126" => "South Ribble",
"E07000189" => "South Somerset",
"E07000196" => "South Staffordshire",
"E08000023" => "South Tyneside",
"E06000045" => "Southampton",
"E06000033" => "Southend-on-Sea",
"E09000028" => "Southwark",
"E07000213" => "Spelthorne",
"E07000240" => "St Albans",
"E08000013" => "St. Helens",
"E07000197" => "Stafford",
"E07000198" => "Staffordshire Moorlands",
"E07000243" => "Stevenage",
"S12000030" => "Stirling",
"E08000007" => "Stockport",
"E06000004" => "Stockton-on-Tees",
"E06000021" => "Stoke-on-Trent",
"E07000221" => "Stratford-on-Avon",
"E07000082" => "Stroud",
"E08000024" => "Sunderland",
"E07000214" => "Surrey Heath",
"E09000029" => "Sutton",
"E07000113" => "Swale",
"W06000011" => "Swansea",
"E06000030" => "Swindon",
"E08000008" => "Tameside",
"E07000199" => "Tamworth",
"E07000215" => "Tandridge",
"E07000045" => "Teignbridge",
"E06000020" => "Telford and Wrekin",
"E07000076" => "Tendring",
"E07000093" => "Test Valley",
"E07000083" => "Tewkesbury",
"E07000114" => "Thanet",
"E07000102" => "Three Rivers",
"E06000034" => "Thurrock",
"E07000115" => "Tonbridge and Malling",
"E06000027" => "Torbay",
"W06000020" => "Torfaen",
"E07000046" => "Torridge",
"E09000030" => "Tower Hamlets",
"E08000009" => "Trafford",
"E07000116" => "Tunbridge Wells",
"E07000077" => "Uttlesford",
"W06000014" => "Vale of Glamorgan",
"E07000180" => "Vale of White Horse",
"E08000036" => "Wakefield",
"E08000030" => "Walsall",
"E09000031" => "Waltham Forest",
"E09000032" => "Wandsworth",
"E06000007" => "Warrington",
"E07000222" => "Warwick",
"E07000103" => "Watford",
"E07000216" => "Waverley",
"E07000065" => "Wealden",
"E07000156" => "Wellingborough",
"E07000241" => "Welwyn Hatfield",
"E06000037" => "West Berkshire",
"E07000047" => "West Devon",
"S12000039" => "West Dunbartonshire",
"E07000127" => "West Lancashire",
"E07000142" => "West Lindsey",
"S12000040" => "West Lothian",
"E07000181" => "West Oxfordshire",
"E07000245" => "West Suffolk",
"E09000033" => "Westminster",
"E08000010" => "Wigan",
"E06000054" => "Wiltshire",
"E07000094" => "Winchester",
"E06000040" => "Windsor and Maidenhead",
"E08000015" => "Wirral",
"E07000217" => "Woking",
"E06000041" => "Wokingham",
"E08000031" => "Wolverhampton",
"E07000237" => "Worcester",
"E07000229" => "Worthing",
"W06000006" => "Wrexham",
"E07000238" => "Wychavon",
"E07000128" => "Wyre",
"E07000239" => "Wyre Forest",
"E06000014" => "York",
"N92000002" => "Northern Ireland",
"S92000003" => "Scotland",
"W92000004" => "Wales",
"9300000XX" => "Outside UK",
}.freeze
end

1
app/models/form/sales/sections/household.rb

@ -7,6 +7,7 @@ class Form::Sales::Sections::Household < ::Form::Section
@form = form
@subsections = [
Form::Sales::Subsections::HouseholdCharacteristics.new(nil, nil, self),
Form::Sales::Subsections::HouseholdSituation.new(nil, nil, self),
Form::Sales::Subsections::HouseholdNeeds.new(nil, nil, self),
]
end

5
app/models/form/sales/subsections/household_needs.rb

@ -9,8 +9,11 @@ class Form::Sales::Subsections::HouseholdNeeds < ::Form::Subsection
def pages
@pages ||= [
Form::Sales::Pages::HouseholdWheelchair.new(nil, nil, self),
Form::Sales::Pages::ArmedForces.new(nil, nil, self),
Form::Sales::Pages::BuyerStillServing.new(nil, nil, self),
Form::Sales::Pages::HouseholdDisability.new(nil, nil, self),
Form::Sales::Pages::HouseholdWheelchair.new(nil, nil, self),
Form::Sales::Pages::HouseholdWheelchairCheck.new("wheelchair_check", nil, self),
]
end
end

18
app/models/form/sales/subsections/household_situation.rb

@ -0,0 +1,18 @@
class Form::Sales::Subsections::HouseholdSituation < ::Form::Subsection
def initialize(id, hsh, section)
super
@id = "household_situation"
@label = "Household situation"
@section = section
@depends_on = [{ "setup_completed?" => true }]
end
def pages
@pages ||= [
Form::Sales::Pages::Buyer1PreviousTenure.new(nil, nil, self),
Form::Sales::Pages::LastAccommodation.new(nil, nil, self),
Form::Sales::Pages::LastAccommodationLa.new(nil, nil, self),
Form::Sales::Pages::BuyersOrganisations.new(nil, nil, self),
]
end
end

2
app/models/form/subsection.rb

@ -28,7 +28,7 @@ class Form::Subsection
qs = applicable_questions(log)
qs_optional_removed = qs.reject { |q| log.optional_fields.include?(q.id) }
return :not_started if qs.count.positive? && qs.all? { |question| log[question.id].blank? || question.read_only? || question.derived? }
return :not_started if qs.count.positive? && qs.all? { |question| question.unanswered?(log) || question.read_only? || question.derived? }
return :completed if qs_optional_removed.all? { |question| question.completed?(log) }
:in_progress

28
app/models/lettings_log.rb

@ -521,8 +521,6 @@ class LettingsLog < Log
private
PIO = PostcodeService.new
def reset_derived_questions
dependent_questions = { waityear: [{ key: :renewal, value: 0 }],
referral: [{ key: :renewal, value: 0 }],
@ -600,11 +598,6 @@ private
process_postcode(postcode_full, "postcode_known", "is_la_inferred", "la")
end
def process_previous_postcode_changes!
self.ppostcode_full = upcase_and_remove_whitespace(ppostcode_full)
process_postcode(ppostcode_full, "ppcodenk", "is_previous_la_inferred", "prevloc")
end
def process_postcode(postcode, postcode_known_key, la_inferred_key, la_key)
return if postcode.blank?
@ -618,23 +611,6 @@ private
reset_location(is_la_inferred, "la", "is_la_inferred", "postcode_full", 1)
end
def reset_previous_location_fields!
reset_location(is_previous_la_inferred, "prevloc", "is_previous_la_inferred", "ppostcode_full", previous_la_known)
end
def reset_location(is_inferred, la_key, is_inferred_key, postcode_key, is_la_known)
if is_inferred || is_la_known != 1
self[la_key] = nil
end
self[is_inferred_key] = false
self[postcode_key] = nil
end
def get_inferred_la(postcode)
result = PIO.lookup(postcode)
result[:location_code] if result
end
def get_has_benefits
HAS_BENEFITS_OPTIONS.include?(hb) ? 1 : 0
end
@ -687,10 +663,6 @@ private
(value * 52 / num_of_weeks).round(2)
end
def upcase_and_remove_whitespace(string)
string.present? ? string.upcase.gsub(/\s+/, "") : string
end
def fully_wheelchair_accessible?
housingneeds_type.present? && housingneeds_type.zero?
end

28
app/models/log.rb

@ -88,4 +88,32 @@ private
update!(created_by: nil)
end
PIO = PostcodeService.new
def process_previous_postcode_changes!
self.ppostcode_full = upcase_and_remove_whitespace(ppostcode_full)
process_postcode(ppostcode_full, "ppcodenk", "is_previous_la_inferred", "prevloc")
end
def get_inferred_la(postcode)
result = PIO.lookup(postcode)
result[:location_code] if result
end
def upcase_and_remove_whitespace(string)
string.present? ? string.upcase.gsub(/\s+/, "") : string
end
def reset_previous_location_fields!
reset_location(is_previous_la_inferred, "prevloc", "is_previous_la_inferred", "ppostcode_full", previous_la_known)
end
def reset_location(is_inferred, la_key, is_inferred_key, postcode_key, is_la_known)
if is_inferred || is_la_known != 1
self[la_key] = nil
end
self[is_inferred_key] = false
self[postcode_key] = nil
end
end

24
app/models/sales_log.rb

@ -2,6 +2,7 @@ class SalesLogValidator < ActiveModel::Validator
include Validations::Sales::HouseholdValidations
include Validations::SharedValidations
include Validations::Sales::FinancialValidations
include Validations::LocalAuthorityValidations
def validate(record)
validation_methods = public_methods.select { |method| method.starts_with?("validate_") }
@ -20,6 +21,8 @@ class SalesLog < Log
validates_with SalesLogValidator
before_validation :set_derived_fields!
before_validation :reset_invalidated_dependent_fields!
before_validation :process_previous_postcode_changes!, if: :ppostcode_full_changed?
before_validation :reset_previous_location_fields!, unless: :previous_postcode_known?
scope :filter_by_year, ->(year) { where(saledate: Time.zone.local(year.to_i, 4, 1)...Time.zone.local(year.to_i + 1, 4, 1)) }
scope :search_by, ->(param) { filter_by_id(param) }
@ -119,4 +122,25 @@ class SalesLog < Log
def is_type_discount?
type == 18
end
def ppostcode_full=(postcode)
if postcode
super UKPostcode.parse(postcode).to_s
else
super nil
end
end
def previous_postcode_known?
ppcodenk&.zero?
end
def process_postcode(postcode, postcode_known_key, la_inferred_key, la_key)
return if postcode.blank?
self[postcode_known_key] = 0
inferred_la = get_inferred_la(postcode)
self[la_inferred_key] = inferred_la.present?
self[la_key] = inferred_la if inferred_la.present?
end
end

6
app/models/validations/sales/soft_validations.rb

@ -20,4 +20,10 @@ module Validations::Sales::SoftValidations
income_used_for_mortgage = (income1_used_for_mortgage? ? income1 : 0) + (income2_used_for_mortgage? ? income2 : 0)
mortgage > income_used_for_mortgage * 5
end
def wheelchair_when_not_disabled?
return false unless disabled == 2
wheel == 1
end
end

7
db/migrate/20221222105044_add_wheel_value_check.rb

@ -0,0 +1,7 @@
class AddWheelValueCheck < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :wheel_value_check, :integer
end
end
end

10
db/migrate/20221222153059_add_buyers_organisations_to_sales_log.rb

@ -0,0 +1,10 @@
class AddBuyersOrganisationsToSalesLog < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :pregyrha, :int
t.column :pregla, :int
t.column :pregghb, :int
t.column :pregother, :integer
end
end
end

13
db/migrate/20221223105623_add_postcode_fields.rb

@ -0,0 +1,13 @@
class AddPostcodeFields < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :ppostcode_full, :string
t.column :is_previous_la_inferred, :boolean
t.column :ppcodenk, :integer
t.column :ppostc1, :string
t.column :ppostc2, :string
t.column :prevloc, :string
t.column :previous_la_known, :boolean
end
end
end

7
db/migrate/20221223134818_add_armed_forces_to_sales_log.rb

@ -0,0 +1,7 @@
class AddArmedForcesToSalesLog < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :hhregres, :integer
end
end
end

7
db/migrate/20221223151033_add_still_serving_to_sales.rb

@ -0,0 +1,7 @@
class AddStillServingToSales < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :hhregresstill, :integer
end
end
end

7
db/migrate/20230103135135_add_prevten.rb

@ -0,0 +1,7 @@
class AddPrevten < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :prevten, :integer
end
end
end

13
db/migrate/20230104164318_change_previous_la_known_type.rb

@ -0,0 +1,13 @@
class ChangePreviousLaKnownType < ActiveRecord::Migration[7.0]
def up
change_table :sales_logs, bulk: true do |t|
t.change :previous_la_known, "integer USING previous_la_known::integer"
end
end
def down
change_table :sales_logs, bulk: true do |t|
t.change :previous_la_known, "boolean USING previous_la_known::boolean"
end
end
end

17
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_01_04_093057) do
ActiveRecord::Schema[7.0].define(version: 2023_01_04_164318) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -429,12 +429,27 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_04_093057) do
t.decimal "cashdis", precision: 10, scale: 2
t.integer "disabled"
t.integer "lanomagr"
t.integer "wheel_value_check"
t.integer "soctenant"
t.decimal "value", precision: 10, scale: 2
t.decimal "equity", precision: 10, scale: 2
t.decimal "discount", precision: 10, scale: 2
t.decimal "grant", precision: 10, scale: 2
t.integer "pregyrha"
t.integer "pregla"
t.integer "pregghb"
t.integer "pregother"
t.string "ppostcode_full"
t.boolean "is_previous_la_inferred"
t.integer "ppcodenk"
t.string "ppostc1"
t.string "ppostc2"
t.string "prevloc"
t.integer "previous_la_known"
t.integer "hhregres"
t.integer "hhregresstill"
t.integer "proplen"
t.integer "prevten"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

11
spec/factories/sales_log.rb

@ -67,12 +67,21 @@ FactoryBot.define do
ecstat4 { 3 }
ecstat5 { 2 }
ecstat6 { 1 }
disabled { 2 }
disabled { 1 }
deposit { 10_000 }
cashdis { 1_000 }
value { 110_000 }
grant { 1_000 }
proplen { 10 }
pregyrha { 1 }
pregla { 1 }
pregother { 1 }
pregghb { 1 }
hhregres { 1 }
hhregresstill { 4 }
ppcodenk { 1 }
prevten { 1 }
previous_la_known { 0 }
end
end
end

29
spec/models/form/sales/pages/armed_forces_spec.rb

@ -0,0 +1,29 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::ArmedForces, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[hhregres])
end
it "has the correct id" do
expect(page.id).to eq("armed_forces")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
end

25
spec/models/form/sales/pages/buyer1_previous_tenure_spec.rb

@ -0,0 +1,25 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Buyer1PreviousTenure, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[prevten])
end
it "has the correct id" do
expect(page.id).to eq("buyer1_previous_tenure")
end
it "has the correct header" do
expect(page.header).to eq("What was buyer 1's previous tenure?")
end
end

33
spec/models/form/sales/pages/buyer_still_serving_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::BuyerStillServing, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[hhregresstill])
end
it "has the correct id" do
expect(page.id).to eq("buyer_still_serving")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "hhregres" => 1 }])
end
end

33
spec/models/form/sales/pages/buyers_organisations_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::BuyersOrganisations, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[buyers_organisations])
end
it "has the correct id" do
expect(page.id).to eq("buyers_organisations")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to be nil
end
end

33
spec/models/form/sales/pages/household_wheelchair_check_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::HouseholdWheelchairCheck, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { "buyer_1_income_mortgage_value_check" }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[wheel_value_check])
end
it "has the correct id" do
expect(page.id).to eq("buyer_1_income_mortgage_value_check")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([
{
"wheelchair_when_not_disabled?" => true,
},
])
end
end

35
spec/models/form/sales/pages/last_accommodation_la_spec.rb

@ -0,0 +1,35 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::LastAccommodationLa, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[previous_la_known prevloc])
end
it "has the correct id" do
expect(page.id).to eq("last_accommodation_la")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{
"is_previous_la_inferred" => false,
}])
end
end

33
spec/models/form/sales/pages/last_accommodation_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::LastAccommodation, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ppcodenk ppostcode_full])
end
it "has the correct id" do
expect(page.id).to eq("last_accommodation")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to be_nil
end
end

46
spec/models/form/sales/questions/armed_forces_spec.rb

@ -0,0 +1,46 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::ArmedForces, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("hhregres")
end
it "has the correct header" do
expect(question.header).to eq("Have any of the buyers ever served as a regular in the UK armed forces?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Have any of the buyers ever served as a regular in the UK armed forces?")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to eq("A regular is somebody who has served in the Royal Navy, the Royal Marines, the Royal Airforce or Army full time and does not include reserve forces")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Yes" },
"7" => { "value" => "No" },
"3" => { "value" => "Buyer prefers not to say" },
"8" => { "value" => "Don't know" },
})
end
end

46
spec/models/form/sales/questions/buyer1_previous_tenure_spec.rb

@ -0,0 +1,46 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer1PreviousTenure, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("prevten")
end
it "has the correct header" do
expect(question.header).to eq("What was buyer 1's previous tenure?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1's previous tenure")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Local Authority" },
"2" => { "value" => "Private registered provider or housing association tenant" },
"3" => { "value" => "Private tenant" },
"4" => { "value" => "Tied home or renting with job" },
"5" => { "value" => "Owner occupier" },
"6" => { "value" => "Living with family or friends" },
"7" => { "value" => "Temporary accomodation" },
"9" => { "value" => "Other" },
})
end
end

46
spec/models/form/sales/questions/buyer_still_serving_spec.rb

@ -0,0 +1,46 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::BuyerStillServing, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("hhregresstill")
end
it "has the correct header" do
expect(question.header).to eq("Is the buyer still serving in the UK armed forces?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Are they still serving in the UK armed forces?")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to eq("")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"4" => { "value" => "Yes" },
"5" => { "value" => "No" },
"6" => { "value" => "Buyer prefers not to say" },
"7" => { "value" => "Don't know" },
})
end
end

48
spec/models/form/sales/questions/buyers_organisations_spec.rb

@ -0,0 +1,48 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::BuyersOrganisations, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("buyers_organisations")
end
it "has the correct header" do
expect(question.header).to eq("What organisations were the buyers registered with?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Organisations buyers were registered with")
end
it "has the correct type" do
expect(question.type).to eq("checkbox")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to eq("Select all that apply")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq(
{
"pregyrha" => { "value" => "Their private registered provider (PRP) - housing association" },
"pregother" => { "value" => "Other private registered provider (PRP) - housing association" },
"pregla" => { "value" => "Local Authority" },
"pregghb" => { "value" => "Help to Buy Agent" },
},
)
end
end

48
spec/models/form/sales/questions/household_wheelchair_check_spec.rb

@ -0,0 +1,48 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::HouseholdWheelchairCheck, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("wheel_value_check")
end
it "has the correct header" do
expect(question.header).to eq("Are you sure? You said previously that somebody in household uses a wheelchair")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Does anyone in the household use a wheelchair?")
end
it "has the correct type" do
expect(question.type).to eq("interruption_screen")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to be_nil
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
})
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq({ "depends_on" => [{ "wheel_value_check" => 0 }, { "wheel_value_check" => 1 }] })
end
end

65
spec/models/form/sales/questions/previous_la_known_spec.rb

@ -0,0 +1,65 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::PreviousLaKnown, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("previous_la_known")
end
it "has the correct header" do
expect(question.header).to eq("Do you know the local authority of buyer 1’s last settled accommodation?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Local authority of buyer 1’s last settled accommodation")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Yes" },
"0" => { "value" => "No" },
})
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"previous_la_known" => 0,
},
{
"previous_la_known" => 1,
},
],
},
)
end
it "has correct conditional_for" do
expect(question.conditional_for).to eq({
"prevloc" => [1],
})
end
it "has the correct hint" do
expect(question.hint_text).to eq("This is also known as the household’s 'last settled home'")
end
end

50
spec/models/form/sales/questions/previous_postcode_known_spec.rb

@ -0,0 +1,50 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::PreviousPostcodeKnown, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("ppcodenk")
end
it "has the correct header" do
expect(question.header).to eq("Do you know the postcode of buyer 1’s last settled accommodation?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1’s last settled accommodation")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"ppostcode_full" => [0],
})
end
it "has the correct hint" do
expect(question.hint_text).to eq("This is also known as the household’s 'last settled home'")
end
end

58
spec/models/form/sales/questions/previous_postcode_spec.rb

@ -0,0 +1,58 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::PreviousPostcode, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("ppostcode_full")
end
it "has the correct header" do
expect(question.header).to eq("Postcode")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Postcode of buyer 1’s last settled accommodation")
end
it "has the correct type" do
expect(question.type).to eq("text")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to eq("")
end
it "has the correct width" do
expect(question.width).to eq(5)
end
it "has the correct inferred_answers" do
expect(question.inferred_answers).to eq({
"prevloc" => {
"is_previous_la_inferred" => true,
},
})
end
it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq({
"condition" => {
"ppcodenk" => 1,
},
"value" => "Not known",
})
end
end

433
spec/models/form/sales/questions/prevloc_spec.rb

@ -0,0 +1,433 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Prevloc, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("prevloc")
end
it "has the correct header" do
expect(question.header).to eq("Select a local authority")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Local authority of buyer 1’s last settled accommodation")
end
it "has the correct type" do
expect(question.type).to eq("select")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"" => "Select an option",
"S12000033" => "Aberdeen City",
"S12000034" => "Aberdeenshire",
"E07000223" => "Adur",
"E07000026" => "Allerdale",
"E07000032" => "Amber Valley",
"S12000041" => "Angus",
"N09000001" => "Antrim and Newtownabbey",
"N09000011" => "Ards and North Down",
"S12000035" => "Argyll and Bute",
"N09000002" => "Armagh City, Banbridge and Craigavon",
"E07000224" => "Arun",
"E07000170" => "Ashfield",
"E07000105" => "Ashford",
"E07000200" => "Babergh",
"E09000002" => "Barking and Dagenham",
"E09000003" => "Barnet",
"E08000016" => "Barnsley",
"E07000027" => "Barrow-in-Furness",
"E07000066" => "Basildon",
"E07000084" => "Basingstoke and Deane",
"E07000171" => "Bassetlaw",
"E06000022" => "Bath and North East Somerset",
"E06000055" => "Bedford",
"N09000003" => "Belfast",
"E09000004" => "Bexley",
"E08000025" => "Birmingham",
"E07000129" => "Blaby",
"E06000008" => "Blackburn with Darwen",
"E06000009" => "Blackpool",
"W06000019" => "Blaenau Gwent",
"E07000033" => "Bolsover",
"E08000001" => "Bolton",
"E07000136" => "Boston",
"E06000058" => "Bournemouth, Christchurch and Poole",
"E06000036" => "Bracknell Forest",
"E08000032" => "Bradford",
"E07000067" => "Braintree",
"E07000143" => "Breckland",
"E09000005" => "Brent",
"E07000068" => "Brentwood",
"W06000013" => "Bridgend",
"E06000043" => "Brighton and Hove",
"E06000023" => "Bristol, City of",
"E07000144" => "Broadland",
"E09000006" => "Bromley",
"E07000234" => "Bromsgrove",
"E07000095" => "Broxbourne",
"E07000172" => "Broxtowe",
"E06000060" => "Buckinghamshire",
"E07000117" => "Burnley",
"E08000002" => "Bury",
"W06000018" => "Caerphilly",
"E08000033" => "Calderdale",
"E07000008" => "Cambridge",
"E09000007" => "Camden",
"E07000192" => "Cannock Chase",
"E07000106" => "Canterbury",
"W06000015" => "Cardiff",
"E07000028" => "Carlisle",
"W06000010" => "Carmarthenshire",
"E07000069" => "Castle Point",
"N09000004" => "Causeway Coast and Glens",
"E06000056" => "Central Bedfordshire",
"W06000008" => "Ceredigion",
"E07000130" => "Charnwood",
"E07000070" => "Chelmsford",
"E07000078" => "Cheltenham",
"E07000177" => "Cherwell",
"E06000049" => "Cheshire East",
"E06000050" => "Cheshire West and Chester",
"E07000034" => "Chesterfield",
"E07000225" => "Chichester",
"E07000118" => "Chorley",
"S12000036" => "City of Edinburgh",
"E09000001" => "City of London",
"S12000005" => "Clackmannanshire",
"E07000071" => "Colchester",
"W06000003" => "Conwy",
"E07000029" => "Copeland",
"E07000150" => "Corby",
"E06000052" => "Cornwall",
"E07000079" => "Cotswold",
"E06000047" => "County Durham",
"E08000026" => "Coventry",
"E07000163" => "Craven",
"E07000226" => "Crawley",
"E09000008" => "Croydon",
"E07000096" => "Dacorum",
"E06000005" => "Darlington",
"E07000107" => "Dartford",
"E07000151" => "Daventry",
"W06000004" => "Denbighshire",
"E06000015" => "Derby",
"E07000035" => "Derbyshire Dales",
"N09000005" => "Derry City and Strabane",
"E08000017" => "Doncaster",
"E06000059" => "Dorset",
"E07000108" => "Dover",
"E08000027" => "Dudley",
"S12000006" => "Dumfries and Galloway",
"S12000042" => "Dundee City",
"E09000009" => "Ealing",
"S12000008" => "East Ayrshire",
"E07000009" => "East Cambridgeshire",
"E07000040" => "East Devon",
"S12000045" => "East Dunbartonshire",
"E07000085" => "East Hampshire",
"E07000242" => "East Hertfordshire",
"E07000137" => "East Lindsey",
"S12000010" => "East Lothian",
"E07000152" => "East Northamptonshire",
"S12000011" => "East Renfrewshire",
"E06000011" => "East Riding of Yorkshire",
"E07000193" => "East Staffordshire",
"E07000244" => "East Suffolk",
"E07000061" => "Eastbourne",
"E07000086" => "Eastleigh",
"E07000030" => "Eden",
"E07000207" => "Elmbridge",
"E09000010" => "Enfield",
"E07000072" => "Epping Forest",
"E07000208" => "Epsom and Ewell",
"E07000036" => "Erewash",
"E07000041" => "Exeter",
"S12000014" => "Falkirk",
"E07000087" => "Fareham",
"E07000010" => "Fenland",
"N09000006" => "Fermanagh and Omagh",
"S12000047" => "Fife",
"W06000005" => "Flintshire",
"E07000112" => "Folkestone and Hythe",
"E07000080" => "Forest of Dean",
"E07000119" => "Fylde",
"E08000037" => "Gateshead",
"E07000173" => "Gedling",
"S12000049" => "Glasgow City",
"E07000081" => "Gloucester",
"E07000088" => "Gosport",
"E07000109" => "Gravesham",
"E07000145" => "Great Yarmouth",
"E09000011" => "Greenwich",
"E07000209" => "Guildford",
"W06000002" => "Gwynedd",
"E09000012" => "Hackney",
"E06000006" => "Halton",
"E07000164" => "Hambleton",
"E09000013" => "Hammersmith and Fulham",
"E07000131" => "Harborough",
"E09000014" => "Haringey",
"E07000073" => "Harlow",
"E07000165" => "Harrogate",
"E09000015" => "Harrow",
"E07000089" => "Hart",
"E06000001" => "Hartlepool",
"E07000062" => "Hastings",
"E07000090" => "Havant",
"E09000016" => "Havering",
"E06000019" => "Herefordshire, County of",
"E07000098" => "Hertsmere",
"E07000037" => "High Peak",
"S12000017" => "Highland",
"E09000017" => "Hillingdon",
"E07000132" => "Hinckley and Bosworth",
"E07000227" => "Horsham",
"E09000018" => "Hounslow",
"E07000011" => "Huntingdonshire",
"E07000120" => "Hyndburn",
"S12000018" => "Inverclyde",
"E07000202" => "Ipswich",
"W06000001" => "Isle of Anglesey",
"E06000046" => "Isle of Wight",
"E06000053" => "Isles of Scilly",
"E09000019" => "Islington",
"E09000020" => "Kensington and Chelsea",
"E07000153" => "Kettering",
"E07000146" => "King’s Lynn and West Norfolk",
"E06000010" => "Kingston upon Hull, City of",
"E09000021" => "Kingston upon Thames",
"E08000034" => "Kirklees",
"E08000011" => "Knowsley",
"E09000022" => "Lambeth",
"E07000121" => "Lancaster",
"E08000035" => "Leeds",
"E06000016" => "Leicester",
"E07000063" => "Lewes",
"E09000023" => "Lewisham",
"E07000194" => "Lichfield",
"E07000138" => "Lincoln",
"N09000007" => "Lisburn and Castlereagh",
"E08000012" => "Liverpool",
"E06000032" => "Luton",
"E07000110" => "Maidstone",
"E07000074" => "Maldon",
"E07000235" => "Malvern Hills",
"E08000003" => "Manchester",
"E07000174" => "Mansfield",
"E06000035" => "Medway",
"E07000133" => "Melton",
"E07000187" => "Mendip",
"W06000024" => "Merthyr Tydfil",
"E09000024" => "Merton",
"E07000042" => "Mid Devon",
"E07000203" => "Mid Suffolk",
"E07000228" => "Mid Sussex",
"N09000009" => "Mid Ulster",
"N09000008" => "Mid and East Antrim",
"E06000002" => "Middlesbrough",
"S12000019" => "Midlothian",
"E06000042" => "Milton Keynes",
"E07000210" => "Mole Valley",
"W06000021" => "Monmouthshire",
"S12000020" => "Moray",
"S12000013" => "Na h-Eileanan Siar",
"W06000012" => "Neath Port Talbot",
"E07000091" => "New Forest",
"E07000175" => "Newark and Sherwood",
"E08000021" => "Newcastle upon Tyne",
"E07000195" => "Newcastle-under-Lyme",
"E09000025" => "Newham",
"W06000022" => "Newport",
"N09000010" => "Newry, Mourne and Down",
"S12000021" => "North Ayrshire",
"E07000043" => "North Devon",
"E07000038" => "North East Derbyshire",
"E06000012" => "North East Lincolnshire",
"E07000099" => "North Hertfordshire",
"E07000139" => "North Kesteven",
"S12000050" => "North Lanarkshire",
"E06000013" => "North Lincolnshire",
"E07000147" => "North Norfolk",
"E06000024" => "North Somerset",
"E08000022" => "North Tyneside",
"E07000218" => "North Warwickshire",
"E07000134" => "North West Leicestershire",
"E07000154" => "Northampton",
"E06000057" => "Northumberland",
"E07000148" => "Norwich",
"E06000018" => "Nottingham",
"E07000219" => "Nuneaton and Bedworth",
"E07000135" => "Oadby and Wigston",
"E08000004" => "Oldham",
"S12000023" => "Orkney Islands",
"E07000178" => "Oxford",
"W06000009" => "Pembrokeshire",
"E07000122" => "Pendle",
"S12000048" => "Perth and Kinross",
"E06000031" => "Peterborough",
"E06000026" => "Plymouth",
"E06000044" => "Portsmouth",
"W06000023" => "Powys",
"E07000123" => "Preston",
"E06000038" => "Reading",
"E09000026" => "Redbridge",
"E06000003" => "Redcar and Cleveland",
"E07000236" => "Redditch",
"E07000211" => "Reigate and Banstead",
"S12000038" => "Renfrewshire",
"W06000016" => "Rhondda Cynon Taf",
"E07000124" => "Ribble Valley",
"E09000027" => "Richmond upon Thames",
"E07000166" => "Richmondshire",
"E08000005" => "Rochdale",
"E07000075" => "Rochford",
"E07000125" => "Rossendale",
"E07000064" => "Rother",
"E08000018" => "Rotherham",
"E07000220" => "Rugby",
"E07000212" => "Runnymede",
"E07000176" => "Rushcliffe",
"E07000092" => "Rushmoor",
"E06000017" => "Rutland",
"E07000167" => "Ryedale",
"E08000006" => "Salford",
"E08000028" => "Sandwell",
"E07000168" => "Scarborough",
"S12000026" => "Scottish Borders",
"E07000188" => "Sedgemoor",
"E08000014" => "Sefton",
"E07000169" => "Selby",
"E07000111" => "Sevenoaks",
"E08000019" => "Sheffield",
"S12000027" => "Shetland Islands",
"E06000051" => "Shropshire",
"E06000039" => "Slough",
"E08000029" => "Solihull",
"E07000246" => "Somerset West and Taunton",
"S12000028" => "South Ayrshire",
"E07000012" => "South Cambridgeshire",
"E07000039" => "South Derbyshire",
"E06000025" => "South Gloucestershire",
"E07000044" => "South Hams",
"E07000140" => "South Holland",
"E07000141" => "South Kesteven",
"E07000031" => "South Lakeland",
"S12000029" => "South Lanarkshire",
"E07000149" => "South Norfolk",
"E07000155" => "South Northamptonshire",
"E07000179" => "South Oxfordshire",
"E07000126" => "South Ribble",
"E07000189" => "South Somerset",
"E07000196" => "South Staffordshire",
"E08000023" => "South Tyneside",
"E06000045" => "Southampton",
"E06000033" => "Southend-on-Sea",
"E09000028" => "Southwark",
"E07000213" => "Spelthorne",
"E07000240" => "St Albans",
"E08000013" => "St. Helens",
"E07000197" => "Stafford",
"E07000198" => "Staffordshire Moorlands",
"E07000243" => "Stevenage",
"S12000030" => "Stirling",
"E08000007" => "Stockport",
"E06000004" => "Stockton-on-Tees",
"E06000021" => "Stoke-on-Trent",
"E07000221" => "Stratford-on-Avon",
"E07000082" => "Stroud",
"E08000024" => "Sunderland",
"E07000214" => "Surrey Heath",
"E09000029" => "Sutton",
"E07000113" => "Swale",
"W06000011" => "Swansea",
"E06000030" => "Swindon",
"E08000008" => "Tameside",
"E07000199" => "Tamworth",
"E07000215" => "Tandridge",
"E07000045" => "Teignbridge",
"E06000020" => "Telford and Wrekin",
"E07000076" => "Tendring",
"E07000093" => "Test Valley",
"E07000083" => "Tewkesbury",
"E07000114" => "Thanet",
"E07000102" => "Three Rivers",
"E06000034" => "Thurrock",
"E07000115" => "Tonbridge and Malling",
"E06000027" => "Torbay",
"W06000020" => "Torfaen",
"E07000046" => "Torridge",
"E09000030" => "Tower Hamlets",
"E08000009" => "Trafford",
"E07000116" => "Tunbridge Wells",
"E07000077" => "Uttlesford",
"W06000014" => "Vale of Glamorgan",
"E07000180" => "Vale of White Horse",
"E08000036" => "Wakefield",
"E08000030" => "Walsall",
"E09000031" => "Waltham Forest",
"E09000032" => "Wandsworth",
"E06000007" => "Warrington",
"E07000222" => "Warwick",
"E07000103" => "Watford",
"E07000216" => "Waverley",
"E07000065" => "Wealden",
"E07000156" => "Wellingborough",
"E07000241" => "Welwyn Hatfield",
"E06000037" => "West Berkshire",
"E07000047" => "West Devon",
"S12000039" => "West Dunbartonshire",
"E07000127" => "West Lancashire",
"E07000142" => "West Lindsey",
"S12000040" => "West Lothian",
"E07000181" => "West Oxfordshire",
"E07000245" => "West Suffolk",
"E09000033" => "Westminster",
"E08000010" => "Wigan",
"E06000054" => "Wiltshire",
"E07000094" => "Winchester",
"E06000040" => "Windsor and Maidenhead",
"E08000015" => "Wirral",
"E07000217" => "Woking",
"E06000041" => "Wokingham",
"E08000031" => "Wolverhampton",
"E07000237" => "Worcester",
"E07000229" => "Worthing",
"W06000006" => "Wrexham",
"E07000238" => "Wychavon",
"E07000128" => "Wyre",
"E07000239" => "Wyre Forest",
"E06000014" => "York",
"N92000002" => "Northern Ireland",
"S92000003" => "Scotland",
"W92000004" => "Wales",
"9300000XX" => "Outside UK",
})
end
it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq(
{
"condition" => {
"previous_la_known" => 0,
},
"value" => "Not known",
},
)
end
end

1
spec/models/form/sales/sections/household_spec.rb

@ -15,6 +15,7 @@ RSpec.describe Form::Sales::Sections::Household, type: :model do
expect(household.subsections.map(&:id)).to eq(
%w[
household_characteristics
household_situation
household_needs
],
)

37
spec/models/form/sales/subsections/household_needs_spec.rb

@ -0,0 +1,37 @@
require "rails_helper"
RSpec.describe Form::Sales::Subsections::HouseholdNeeds, type: :model do
subject(:household_characteristics) { described_class.new(subsection_id, subsection_definition, section) }
let(:subsection_id) { nil }
let(:subsection_definition) { nil }
let(:section) { instance_double(Form::Sales::Sections::Household) }
it "has correct section" do
expect(household_characteristics.section).to eq(section)
end
it "has correct pages" do
expect(household_characteristics.pages.map(&:id)).to eq(
%w[
armed_forces
buyer_still_serving
household_disability
household_wheelchair
wheelchair_check
],
)
end
it "has the correct id" do
expect(household_characteristics.id).to eq("household_needs")
end
it "has the correct label" do
expect(household_characteristics.label).to eq("Household needs")
end
it "has correct depends on" do
expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true }])
end
end

36
spec/models/form/sales/subsections/household_situation_spec.rb

@ -0,0 +1,36 @@
require "rails_helper"
RSpec.describe Form::Sales::Subsections::HouseholdSituation, type: :model do
subject(:household_characteristics) { described_class.new(subsection_id, subsection_definition, section) }
let(:subsection_id) { nil }
let(:subsection_definition) { nil }
let(:section) { instance_double(Form::Sales::Sections::Household) }
it "has correct section" do
expect(household_characteristics.section).to eq(section)
end
it "has correct pages" do
expect(household_characteristics.pages.map(&:id)).to eq(
%w[
buyer1_previous_tenure
last_accommodation
last_accommodation_la
buyers_organisations
],
)
end
it "has the correct id" do
expect(household_characteristics.id).to eq("household_situation")
end
it "has the correct label" do
expect(household_characteristics.label).to eq("Household situation")
end
it "has correct depends on" do
expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true }])
end
end

4
spec/models/form_handler_spec.rb

@ -52,14 +52,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do
form = form_handler.get_form("current_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(90)
expect(form.pages.count).to eq(97)
expect(form.name).to eq("2022_2023_sales")
end
it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(90)
expect(form.pages.count).to eq(97)
expect(form.name).to eq("2021_2022_sales")
end
end

66
spec/models/sales_log_spec.rb

@ -105,4 +105,70 @@ RSpec.describe SalesLog, type: :model do
expect(record_from_db["exyear"]).to eq(2022)
end
end
context "when saving previous address" do
def check_previous_postcode_fields(postcode_field)
record_from_db = ActiveRecord::Base.connection.execute("select #{postcode_field} from sales_logs where id=#{address_sales_log.id}").to_a[0]
expect(address_sales_log[postcode_field]).to eq("M1 1AE")
expect(record_from_db[postcode_field]).to eq("M1 1AE")
end
before do
stub_request(:get, /api.postcodes.io/)
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {})
end
let!(:address_sales_log) do
described_class.create({
managing_organisation: owning_organisation,
owning_organisation:,
created_by: created_by_user,
ppcodenk: 1,
ppostcode_full: "M1 1AE",
})
end
def previous_postcode_fields
check_previous_postcode_fields("ppostcode_full")
end
it "correctly formats previous postcode" do
address_sales_log.update!(ppostcode_full: "M1 1AE")
previous_postcode_fields
address_sales_log.update!(ppostcode_full: "m1 1ae")
previous_postcode_fields
address_sales_log.update!(ppostcode_full: "m11Ae")
previous_postcode_fields
address_sales_log.update!(ppostcode_full: "m11ae")
previous_postcode_fields
end
it "correctly infers prevloc" do
record_from_db = ActiveRecord::Base.connection.execute("select prevloc from sales_logs where id=#{address_sales_log.id}").to_a[0]
expect(address_sales_log.prevloc).to eq("E08000003")
expect(record_from_db["prevloc"]).to eq("E08000003")
end
it "errors if the previous postcode is emptied" do
expect { address_sales_log.update!({ ppostcode_full: "" }) }
.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
end
it "errors if the previous postcode is not valid" do
expect { address_sales_log.update!({ ppostcode_full: "invalid_postcode" }) }
.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
end
it "correctly resets all fields if previous postcode not known" do
address_sales_log.update!({ ppcodenk: 1 })
record_from_db = ActiveRecord::Base.connection.execute("select prevloc, ppostcode_full from sales_logs where id=#{address_sales_log.id}").to_a[0]
expect(record_from_db["ppostcode_full"]).to eq(nil)
expect(address_sales_log.prevloc).to eq(nil)
expect(record_from_db["prevloc"]).to eq(nil)
end
end
end

Loading…
Cancel
Save