Browse Source

Cldc 3505 fix tests that will break on rollover (#2485)

* update factory completed traits using an after build hook so that trait does what it says regardless of start or sale date of log

* use completed trait rather than completed2024 trait from factories
skip validation on saving logs from previous years so that logs created too far in the past do not trigger validations

* remove sale and start dates from logs in tests where that should not be important
build rather than create to reduce db interactions
in order that the setup is complete, build the necessary user and organisation with ids

* fix a wide range of tests affected by the changes in log factories completed traits
pull/2491/head
Arthur Campbell 8 months ago committed by GitHub
parent
commit
8f65fd35fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      spec/components/check_answers_summary_list_card_component_spec.rb
  2. 26
      spec/factories/lettings_log.rb
  3. 27
      spec/factories/sales_log.rb
  4. 8
      spec/features/form/form_navigation_spec.rb
  5. 18
      spec/fixtures/exports/general_needs_log_24_25.xml
  6. 2
      spec/fixtures/files/sales_logs_csv_export_codes_24.csv
  7. 2
      spec/fixtures/files/sales_logs_csv_export_labels_24.csv
  8. 2
      spec/fixtures/files/sales_logs_csv_export_non_support_labels_24.csv
  9. 2
      spec/models/form/lettings/questions/uprn_spec.rb
  10. 4
      spec/models/form/sales/questions/uprn_spec.rb
  11. 1
      spec/models/form_spec.rb
  12. 11
      spec/models/log_spec.rb
  13. 16
      spec/presenters/homepage_presenter_spec.rb
  14. 11
      spec/request_helper.rb
  15. 172
      spec/requests/lettings_logs_controller_spec.rb

2
spec/components/check_answers_summary_list_card_component_spec.rb

@ -43,6 +43,8 @@ RSpec.describe CheckAnswersSummaryListCardComponent, type: :component do
end end
context "when log was not created via a bulk upload and has an unanswered question" do context "when log was not created via a bulk upload and has an unanswered question" do
let(:log) { create(:lettings_log, :in_progress) }
it "displays normal copy with muted colour " do it "displays normal copy with muted colour " do
expect(rendered).to have_selector("span", class: "app-!-colour-muted", text: "You didn’t answer this question") expect(rendered).to have_selector("span", class: "app-!-colour-muted", text: "You didn’t answer this question")
end end

26
spec/factories/lettings_log.rb

@ -23,15 +23,6 @@ FactoryBot.define do
age1 { 17 } age1 { 17 }
age2 { 19 } age2 { 19 }
end end
trait :conditional_section_complete do
tenancycode { Faker::Name.initials(number: 10) }
age1 { 34 }
sex1 { "M" }
ethnic { 2 }
national { 18 }
ecstat1 { 2 }
hhmemb { 1 }
end
trait :duplicate do trait :duplicate do
setup_completed setup_completed
status { 1 } status { 1 }
@ -168,14 +159,15 @@ FactoryBot.define do
town_or_city { "London" } town_or_city { "London" }
ppcodenk { 1 } ppcodenk { 1 }
tshortfall_known { 1 } tshortfall_known { 1 }
end after(:build) do |log, _evaluator|
trait :completed2024 do if log.startdate >= Time.zone.local(2024, 4, 1)
completed log.address_line1_input = log.address_line1
address_line1_input { address_line1 } log.postcode_full_input = log.postcode_full
postcode_full_input { postcode_full } log.nationality_all_group = 826
nationality_all_group { 826 } log.uprn = "10033558653"
uprn { 1 } log.uprn_selection = 1
uprn_selection { 1 } end
end
end end
trait :export do trait :export do
tenancycode { "987654" } tenancycode { "987654" }

27
spec/factories/sales_log.rb

@ -1,6 +1,8 @@
FactoryBot.define do FactoryBot.define do
factory :sales_log do factory :sales_log do
assigned_to { association :user } assigned_to { association :user }
before(:create) { |log, _evaluator| log.assigned_to ||= create(:user) }
created_by { assigned_to } created_by { assigned_to }
owning_organisation { assigned_to.organisation } owning_organisation { assigned_to.organisation }
managing_organisation { owning_organisation } managing_organisation { owning_organisation }
@ -11,7 +13,7 @@ FactoryBot.define do
ownershipsch { 2 } ownershipsch { 2 }
type { 8 } type { 8 }
jointpur { 2 } jointpur { 2 }
saledate { Time.zone.today } saledate_today
end end
trait :shared_ownership do trait :shared_ownership do
ownershipsch { 1 } ownershipsch { 1 }
@ -45,7 +47,7 @@ FactoryBot.define do
trait :duplicate do trait :duplicate do
shared_ownership_setup_complete shared_ownership_setup_complete
purchid { "PC123" } purchid { "PC123" }
saledate { Time.zone.today } saledate_today
age1_known { 1 } age1_known { 1 }
age1 { 20 } age1 { 20 }
sex1 { "F" } sex1 { "F" }
@ -57,7 +59,7 @@ FactoryBot.define do
purchid { rand(999_999_999).to_s } purchid { rand(999_999_999).to_s }
ownershipsch { 2 } ownershipsch { 2 }
type { 8 } type { 8 }
saledate { Time.zone.today } saledate_today
jointpur { 1 } jointpur { 1 }
beds { 2 } beds { 2 }
jointmore { 1 } jointmore { 1 }
@ -150,15 +152,16 @@ FactoryBot.define do
nationalbuy2 { 13 } nationalbuy2 { 13 }
buy2living { 3 } buy2living { 3 }
proplen_asked { 1 } proplen_asked { 1 }
end after(:build) do |log, _evaluator|
trait :completed2024 do if log.saledate >= Time.zone.local(2024, 4, 1)
completed log.address_line1_input = log.address_line1
address_line1_input { address_line1 } log.postcode_full_input = log.postcode_full
postcode_full_input { postcode_full } log.nationality_all_group = 826
nationality_all_group { 826 } log.nationality_all_buyer2_group = 826
nationality_all_buyer2_group { 826 } log.uprn = "10033558653"
uprn { 1 } log.uprn_selection = 1
uprn_selection { 1 } end
end
end end
trait :with_uprn do trait :with_uprn do
uprn { rand(999_999_999_999).to_s } uprn { rand(999_999_999_999).to_s }

8
spec/features/form/form_navigation_spec.rb

@ -191,7 +191,7 @@ RSpec.describe "Form Navigation" do
let(:now) { Time.zone.local(2024, 5, 1) } let(:now) { Time.zone.local(2024, 5, 1) }
context "with a lettings log" do context "with a lettings log" do
let(:lettings_log) { create(:lettings_log, :completed, startdate: Time.zone.local(2024, 5, 5), assigned_to: user) } let(:lettings_log) { create(:lettings_log, :setup_completed, startdate: Time.zone.local(2024, 5, 5), assigned_to: user) }
before do before do
stub_request(:get, /api\.os\.uk/) stub_request(:get, /api\.os\.uk/)
@ -211,7 +211,7 @@ RSpec.describe "Form Navigation" do
fill_in("lettings-log-address-line1-input-field", with: "address") fill_in("lettings-log-address-line1-input-field", with: "address")
fill_in("lettings-log-postcode-full-input-field", with: "A1 1AA") fill_in("lettings-log-postcode-full-input-field", with: "A1 1AA")
click_button(text: "Search") click_button(text: "Search")
expect(page).to have_current_path("/lettings-logs/#{id}/uprn-selection?referrer=check_answers") expect(page).to have_current_path("/lettings-logs/#{id}/uprn-selection?referrer=check_answers&unanswered_pages=property_local_authority")
choose("lettings-log-uprn-selection-12345-field", allow_label_click: true) choose("lettings-log-uprn-selection-12345-field", allow_label_click: true)
click_button(text: "Save changes") click_button(text: "Save changes")
expect(page).to have_current_path("/lettings-logs/#{id}/property-information/check-answers") expect(page).to have_current_path("/lettings-logs/#{id}/property-information/check-answers")
@ -219,7 +219,7 @@ RSpec.describe "Form Navigation" do
end end
context "with a sales log" do context "with a sales log" do
let(:sales_log) { create(:sales_log, :completed, saledate: Time.zone.local(2024, 5, 5), assigned_to: user) } let(:sales_log) { create(:sales_log, :outright_sale_setup_complete, saledate: Time.zone.local(2024, 5, 5), assigned_to: user) }
before do before do
stub_request(:get, /api\.os\.uk/) stub_request(:get, /api\.os\.uk/)
@ -239,7 +239,7 @@ RSpec.describe "Form Navigation" do
fill_in("sales-log-address-line1-input-field", with: "address") fill_in("sales-log-address-line1-input-field", with: "address")
fill_in("sales-log-postcode-full-input-field", with: "A1 1AA") fill_in("sales-log-postcode-full-input-field", with: "A1 1AA")
click_button(text: "Search") click_button(text: "Search")
expect(page).to have_current_path("/sales-logs/#{sales_log.id}/uprn-selection?referrer=check_answers") expect(page).to have_current_path("/sales-logs/#{sales_log.id}/uprn-selection?referrer=check_answers&unanswered_pages=property_local_authority")
choose("sales-log-uprn-selection-12345-field", allow_label_click: true) choose("sales-log-uprn-selection-12345-field", allow_label_click: true)
click_button(text: "Save changes") click_button(text: "Save changes")
expect(page).to have_current_path("/sales-logs/#{sales_log.id}/property-information/check-answers") expect(page).to have_current_path("/sales-logs/#{sales_log.id}/property-information/check-answers")

18
spec/fixtures/exports/general_needs_log_24_25.xml vendored

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<forms> <forms>
<form> <form>
<status>1</status> <status>2</status>
<tenancycode>BZ737</tenancycode> <tenancycode>BZ737</tenancycode>
<age1>35</age1> <age1>35</age1>
<sex1>F</sex1> <sex1>F</sex1>
@ -50,7 +50,7 @@
<period>2</period> <period>2</period>
<layear>2</layear> <layear>2</layear>
<waityear>7</waityear> <waityear>7</waityear>
<postcode_full>SE2 6RT</postcode_full> <postcode_full>AA1 1AA</postcode_full>
<reasonpref>1</reasonpref> <reasonpref>1</reasonpref>
<cbl>2</cbl> <cbl>2</cbl>
<chr>1</chr> <chr>1</chr>
@ -82,7 +82,7 @@
<irproduct_other/> <irproduct_other/>
<reason>4</reason> <reason>4</reason>
<propcode>123</propcode> <propcode>123</propcode>
<la>E09000003</la> <la>E09000033</la>
<prevloc>E07000105</prevloc> <prevloc>E07000105</prevloc>
<hb>6</hb> <hb>6</hb>
<hbrentshortfall>1</hbrentshortfall> <hbrentshortfall>1</hbrentshortfall>
@ -137,12 +137,12 @@
<new_old>2</new_old> <new_old>2</new_old>
<vacdays>698</vacdays> <vacdays>698</vacdays>
<bulk_upload_id>1</bulk_upload_id> <bulk_upload_id>1</bulk_upload_id>
<uprn/> <uprn>1</uprn>
<uprn_known>0</uprn_known> <uprn_known>1</uprn_known>
<uprn_confirmed/> <uprn_confirmed>1</uprn_confirmed>
<address_line1>Address line 1</address_line1> <address_line1>1, Test Street</address_line1>
<address_line2/> <address_line2/>
<town_or_city>London</town_or_city> <town_or_city>Test Town</town_or_city>
<county/> <county/>
<carehome_charges_value_check/> <carehome_charges_value_check/>
<discarded_at/> <discarded_at/>
@ -152,7 +152,7 @@
<pscharge_value_check/> <pscharge_value_check/>
<duplicate_set_id/> <duplicate_set_id/>
<accessible_register>2</accessible_register> <accessible_register>2</accessible_register>
<nationality_all/> <nationality_all>826</nationality_all>
<address_line1_as_entered>address line 1 as entered</address_line1_as_entered> <address_line1_as_entered>address line 1 as entered</address_line1_as_entered>
<address_line2_as_entered>address line 2 as entered</address_line2_as_entered> <address_line2_as_entered>address line 2 as entered</address_line2_as_entered>
<town_or_city_as_entered>town or city as entered</town_or_city_as_entered> <town_or_city_as_entered>town or city as entered</town_or_city_as_entered>

2
spec/fixtures/files/sales_logs_csv_export_codes_24.csv vendored

@ -1,2 +1,2 @@
ID,STATUS,DUPLICATESET,CREATEDDATE,UPLOADDATE,COLLECTIONYEAR,CREATIONMETHOD,BULKUPLOADID,DATAPROTECT,OWNINGORGNAME,MANINGORGNAME,CREATEDBY,USERNAME,DAY,MONTH,YEAR,PURCHID,OWNERSHIP,TYPE,OTHTYPE,COMPANY,LIVEINBUYER,JOINT,JOINTMORE,NOINT,PRIVACYNOTICE,UPRN,ADDRESS1,ADDRESS2,TOWNCITY,COUNTY,POSTCODE,ISLAINFERRED,LANAME,LA,UPRNSELECTED,ADDRESS_SEARCH_VALUE_CHECK,ADDRESS1INPUT,POSTCODEINPUT,BULKADDRESS1,BULKADDRESS2,BULKTOWNCITY,BULKCOUNTY,BULKPOSTCODE,BULKLA,BEDS,PROPTYPE,BUILTYPE,WCHAIR,AGE1,SEX1,ETHNICGROUP1,ETHNIC,NATIONALITYALL1,ECSTAT1,LIVEINBUYER1,RELAT2,AGE2,SEX2,ETHNICGROUP2,ETHNIC2,NATIONALITYALL2,ECSTAT2,LIVEINBUYER2,HHTYPE,RELAT3,AGE3,SEX3,ECSTAT3,RELAT4,AGE4,SEX4,ECSTAT4,RELAT5,AGE5,SEX5,ECSTAT5,RELAT6,AGE6,SEX6,ECSTAT6,PREVTEN,PPCODENK,PPOSTC1,PPOSTC2,PREVIOUSLAKNOWN,PREVLOC,PREVLOCNAME,PREGYRHA,PREGOTHER,PREGLA,PREGGHB,PREGBLANK,BUY2LIVING,PREVTEN2,HHREGRES,HHREGRESSTILL,ARMEDFORCESSPOUSE,DISABLED,WHEEL,INC1NK,INCOME1,INC1MORT,INC2NK,INCOME2,INC2MORT,HB,SAVINGSNK,SAVINGS,PREVOWN,PREVSHARED,PROPLEN,STAIRCASE,STAIRBOUGHT,STAIROWNED,STAIRCASETOSALE,RESALE,EXDAY,EXMONTH,EXYEAR,HODAY,HOMONTH,HOYEAR,LANOMAGR,SOCTEN,FROMBEDS,FROMPROP,SOCPREVTEN,VALUE,VALUE_VALUE_CHECK,EQUITY,MORTGAGEUSED,MORTGAGE,MORTGAGELENDER,MORTGAGELENDEROTHER,MORTLEN1,EXTRABOR,DEPOSIT,CASHDIS,MRENT,HASMSCHARGE,MSCHARGE,MSCHARGE_VALUE_CHECK,DISCOUNT,GRANT ID,STATUS,DUPLICATESET,CREATEDDATE,UPLOADDATE,COLLECTIONYEAR,CREATIONMETHOD,BULKUPLOADID,DATAPROTECT,OWNINGORGNAME,MANINGORGNAME,CREATEDBY,USERNAME,DAY,MONTH,YEAR,PURCHID,OWNERSHIP,TYPE,OTHTYPE,COMPANY,LIVEINBUYER,JOINT,JOINTMORE,NOINT,PRIVACYNOTICE,UPRN,ADDRESS1,ADDRESS2,TOWNCITY,COUNTY,POSTCODE,ISLAINFERRED,LANAME,LA,UPRNSELECTED,ADDRESS_SEARCH_VALUE_CHECK,ADDRESS1INPUT,POSTCODEINPUT,BULKADDRESS1,BULKADDRESS2,BULKTOWNCITY,BULKCOUNTY,BULKPOSTCODE,BULKLA,BEDS,PROPTYPE,BUILTYPE,WCHAIR,AGE1,SEX1,ETHNICGROUP1,ETHNIC,NATIONALITYALL1,ECSTAT1,LIVEINBUYER1,RELAT2,AGE2,SEX2,ETHNICGROUP2,ETHNIC2,NATIONALITYALL2,ECSTAT2,LIVEINBUYER2,HHTYPE,RELAT3,AGE3,SEX3,ECSTAT3,RELAT4,AGE4,SEX4,ECSTAT4,RELAT5,AGE5,SEX5,ECSTAT5,RELAT6,AGE6,SEX6,ECSTAT6,PREVTEN,PPCODENK,PPOSTC1,PPOSTC2,PREVIOUSLAKNOWN,PREVLOC,PREVLOCNAME,PREGYRHA,PREGOTHER,PREGLA,PREGGHB,PREGBLANK,BUY2LIVING,PREVTEN2,HHREGRES,HHREGRESSTILL,ARMEDFORCESSPOUSE,DISABLED,WHEEL,INC1NK,INCOME1,INC1MORT,INC2NK,INCOME2,INC2MORT,HB,SAVINGSNK,SAVINGS,PREVOWN,PREVSHARED,PROPLEN,STAIRCASE,STAIRBOUGHT,STAIROWNED,STAIRCASETOSALE,RESALE,EXDAY,EXMONTH,EXYEAR,HODAY,HOMONTH,HOYEAR,LANOMAGR,SOCTEN,FROMBEDS,FROMPROP,SOCPREVTEN,VALUE,VALUE_VALUE_CHECK,EQUITY,MORTGAGEUSED,MORTGAGE,MORTGAGELENDER,MORTGAGELENDEROTHER,MORTLEN1,EXTRABOR,DEPOSIT,CASHDIS,MRENT,HASMSCHARGE,MSCHARGE,MSCHARGE_VALUE_CHECK,DISCOUNT,GRANT
,in_progress,,2024-05-01T00:00:00+01:00,2024-05-01T00:00:00+01:00,2024,1,,false,DLUHC,DLUHC,billyboy@eyeklaud.com,billyboy@eyeklaud.com,1,5,2024,,2,8,,,,1,1,2,1,,Address line 1,,Town or city,,SW1A 1AA,true,Westminster,E09000033,,,,,address line 1 as entered,address line 2 as entered,town or city as entered,county as entered,AB1 2CD,la as entered,2,1,1,1,30,X,17,17,,1,1,P,35,X,17,,,1,1,3,C,14,X,9,X,-9,X,3,R,-9,R,10,,,,,1,0,SW1A,1AA,1,E09000033,Westminster,1,1,1,1,,3,,1,4,5,1,1,0,10000,1,0,10000,1,4,1,,1,2,10,,,,,,,,,,,,,,,,,110000.0,,,1,20000.0,5,,10,1,80000.0,,,1,100.0,,,10000.0 ,completed,,2024-05-01T00:00:00+01:00,2024-05-01T00:00:00+01:00,2024,1,,false,DLUHC,DLUHC,billyboy@eyeklaud.com,billyboy@eyeklaud.com,1,5,2024,,2,8,,,,1,1,2,1,1,"1, Test Street",,Test Town,,AA1 1AA,true,Westminster,E09000033,,,Address line 1,SW1A 1AA,address line 1 as entered,address line 2 as entered,town or city as entered,county as entered,AB1 2CD,la as entered,2,1,1,1,30,X,17,17,826,1,1,P,35,X,17,,826,1,1,3,C,14,X,9,X,-9,X,3,R,-9,R,10,,,,,1,0,SW1A,1AA,1,E09000033,Westminster,1,1,1,1,,3,,1,4,5,1,1,0,10000,1,0,10000,1,4,1,,1,2,10,,,,,,,,,,,,,,,,,110000.0,,,1,20000.0,5,,10,1,80000.0,,,1,100.0,,,10000.0

1 ID STATUS DUPLICATESET CREATEDDATE UPLOADDATE COLLECTIONYEAR CREATIONMETHOD BULKUPLOADID DATAPROTECT OWNINGORGNAME MANINGORGNAME CREATEDBY USERNAME DAY MONTH YEAR PURCHID OWNERSHIP TYPE OTHTYPE COMPANY LIVEINBUYER JOINT JOINTMORE NOINT PRIVACYNOTICE UPRN ADDRESS1 ADDRESS2 TOWNCITY COUNTY POSTCODE ISLAINFERRED LANAME LA UPRNSELECTED ADDRESS_SEARCH_VALUE_CHECK ADDRESS1INPUT POSTCODEINPUT BULKADDRESS1 BULKADDRESS2 BULKTOWNCITY BULKCOUNTY BULKPOSTCODE BULKLA BEDS PROPTYPE BUILTYPE WCHAIR AGE1 SEX1 ETHNICGROUP1 ETHNIC NATIONALITYALL1 ECSTAT1 LIVEINBUYER1 RELAT2 AGE2 SEX2 ETHNICGROUP2 ETHNIC2 NATIONALITYALL2 ECSTAT2 LIVEINBUYER2 HHTYPE RELAT3 AGE3 SEX3 ECSTAT3 RELAT4 AGE4 SEX4 ECSTAT4 RELAT5 AGE5 SEX5 ECSTAT5 RELAT6 AGE6 SEX6 ECSTAT6 PREVTEN PPCODENK PPOSTC1 PPOSTC2 PREVIOUSLAKNOWN PREVLOC PREVLOCNAME PREGYRHA PREGOTHER PREGLA PREGGHB PREGBLANK BUY2LIVING PREVTEN2 HHREGRES HHREGRESSTILL ARMEDFORCESSPOUSE DISABLED WHEEL INC1NK INCOME1 INC1MORT INC2NK INCOME2 INC2MORT HB SAVINGSNK SAVINGS PREVOWN PREVSHARED PROPLEN STAIRCASE STAIRBOUGHT STAIROWNED STAIRCASETOSALE RESALE EXDAY EXMONTH EXYEAR HODAY HOMONTH HOYEAR LANOMAGR SOCTEN FROMBEDS FROMPROP SOCPREVTEN VALUE VALUE_VALUE_CHECK EQUITY MORTGAGEUSED MORTGAGE MORTGAGELENDER MORTGAGELENDEROTHER MORTLEN1 EXTRABOR DEPOSIT CASHDIS MRENT HASMSCHARGE MSCHARGE MSCHARGE_VALUE_CHECK DISCOUNT GRANT
2 in_progress completed 2024-05-01T00:00:00+01:00 2024-05-01T00:00:00+01:00 2024 1 false DLUHC DLUHC billyboy@eyeklaud.com billyboy@eyeklaud.com 1 5 2024 2 8 1 1 2 1 1 Address line 1 1, Test Street Town or city Test Town SW1A 1AA AA1 1AA true Westminster E09000033 Address line 1 SW1A 1AA address line 1 as entered address line 2 as entered town or city as entered county as entered AB1 2CD la as entered 2 1 1 1 30 X 17 17 826 1 1 P 35 X 17 826 1 1 3 C 14 X 9 X -9 X 3 R -9 R 10 1 0 SW1A 1AA 1 E09000033 Westminster 1 1 1 1 3 1 4 5 1 1 0 10000 1 0 10000 1 4 1 1 2 10 110000.0 1 20000.0 5 10 1 80000.0 1 100.0 10000.0

2
spec/fixtures/files/sales_logs_csv_export_labels_24.csv vendored

@ -1,2 +1,2 @@
ID,STATUS,DUPLICATESET,CREATEDDATE,UPLOADDATE,COLLECTIONYEAR,CREATIONMETHOD,BULKUPLOADID,DATAPROTECT,OWNINGORGNAME,MANINGORGNAME,CREATEDBY,USERNAME,DAY,MONTH,YEAR,PURCHID,OWNERSHIP,TYPE,OTHTYPE,COMPANY,LIVEINBUYER,JOINT,JOINTMORE,NOINT,PRIVACYNOTICE,UPRN,ADDRESS1,ADDRESS2,TOWNCITY,COUNTY,POSTCODE,ISLAINFERRED,LANAME,LA,UPRNSELECTED,ADDRESS_SEARCH_VALUE_CHECK,ADDRESS1INPUT,POSTCODEINPUT,BULKADDRESS1,BULKADDRESS2,BULKTOWNCITY,BULKCOUNTY,BULKPOSTCODE,BULKLA,BEDS,PROPTYPE,BUILTYPE,WCHAIR,AGE1,SEX1,ETHNICGROUP1,ETHNIC,NATIONALITYALL1,ECSTAT1,LIVEINBUYER1,RELAT2,AGE2,SEX2,ETHNICGROUP2,ETHNIC2,NATIONALITYALL2,ECSTAT2,LIVEINBUYER2,HHTYPE,RELAT3,AGE3,SEX3,ECSTAT3,RELAT4,AGE4,SEX4,ECSTAT4,RELAT5,AGE5,SEX5,ECSTAT5,RELAT6,AGE6,SEX6,ECSTAT6,PREVTEN,PPCODENK,PPOSTC1,PPOSTC2,PREVIOUSLAKNOWN,PREVLOC,PREVLOCNAME,PREGYRHA,PREGOTHER,PREGLA,PREGGHB,PREGBLANK,BUY2LIVING,PREVTEN2,HHREGRES,HHREGRESSTILL,ARMEDFORCESSPOUSE,DISABLED,WHEEL,INC1NK,INCOME1,INC1MORT,INC2NK,INCOME2,INC2MORT,HB,SAVINGSNK,SAVINGS,PREVOWN,PREVSHARED,PROPLEN,STAIRCASE,STAIRBOUGHT,STAIROWNED,STAIRCASETOSALE,RESALE,EXDAY,EXMONTH,EXYEAR,HODAY,HOMONTH,HOYEAR,LANOMAGR,SOCTEN,FROMBEDS,FROMPROP,SOCPREVTEN,VALUE,VALUE_VALUE_CHECK,EQUITY,MORTGAGEUSED,MORTGAGE,MORTGAGELENDER,MORTGAGELENDEROTHER,MORTLEN1,EXTRABOR,DEPOSIT,CASHDIS,MRENT,HASMSCHARGE,MSCHARGE,MSCHARGE_VALUE_CHECK,DISCOUNT,GRANT ID,STATUS,DUPLICATESET,CREATEDDATE,UPLOADDATE,COLLECTIONYEAR,CREATIONMETHOD,BULKUPLOADID,DATAPROTECT,OWNINGORGNAME,MANINGORGNAME,CREATEDBY,USERNAME,DAY,MONTH,YEAR,PURCHID,OWNERSHIP,TYPE,OTHTYPE,COMPANY,LIVEINBUYER,JOINT,JOINTMORE,NOINT,PRIVACYNOTICE,UPRN,ADDRESS1,ADDRESS2,TOWNCITY,COUNTY,POSTCODE,ISLAINFERRED,LANAME,LA,UPRNSELECTED,ADDRESS_SEARCH_VALUE_CHECK,ADDRESS1INPUT,POSTCODEINPUT,BULKADDRESS1,BULKADDRESS2,BULKTOWNCITY,BULKCOUNTY,BULKPOSTCODE,BULKLA,BEDS,PROPTYPE,BUILTYPE,WCHAIR,AGE1,SEX1,ETHNICGROUP1,ETHNIC,NATIONALITYALL1,ECSTAT1,LIVEINBUYER1,RELAT2,AGE2,SEX2,ETHNICGROUP2,ETHNIC2,NATIONALITYALL2,ECSTAT2,LIVEINBUYER2,HHTYPE,RELAT3,AGE3,SEX3,ECSTAT3,RELAT4,AGE4,SEX4,ECSTAT4,RELAT5,AGE5,SEX5,ECSTAT5,RELAT6,AGE6,SEX6,ECSTAT6,PREVTEN,PPCODENK,PPOSTC1,PPOSTC2,PREVIOUSLAKNOWN,PREVLOC,PREVLOCNAME,PREGYRHA,PREGOTHER,PREGLA,PREGGHB,PREGBLANK,BUY2LIVING,PREVTEN2,HHREGRES,HHREGRESSTILL,ARMEDFORCESSPOUSE,DISABLED,WHEEL,INC1NK,INCOME1,INC1MORT,INC2NK,INCOME2,INC2MORT,HB,SAVINGSNK,SAVINGS,PREVOWN,PREVSHARED,PROPLEN,STAIRCASE,STAIRBOUGHT,STAIROWNED,STAIRCASETOSALE,RESALE,EXDAY,EXMONTH,EXYEAR,HODAY,HOMONTH,HOYEAR,LANOMAGR,SOCTEN,FROMBEDS,FROMPROP,SOCPREVTEN,VALUE,VALUE_VALUE_CHECK,EQUITY,MORTGAGEUSED,MORTGAGE,MORTGAGELENDER,MORTGAGELENDEROTHER,MORTLEN1,EXTRABOR,DEPOSIT,CASHDIS,MRENT,HASMSCHARGE,MSCHARGE,MSCHARGE_VALUE_CHECK,DISCOUNT,GRANT
,in_progress,,2024-05-01T00:00:00+01:00,2024-05-01T00:00:00+01:00,2024,single log,,false,DLUHC,DLUHC,billyboy@eyeklaud.com,billyboy@eyeklaud.com,1,5,2024,,Yes - a discounted ownership scheme,Right to Acquire (RTA),,,,Yes,Yes,Yes,1,,Address line 1,,Town or city,,SW1A 1AA,Yes,Westminster,E09000033,,,,,address line 1 as entered,address line 2 as entered,town or city as entered,county as entered,AB1 2CD,la as entered,2,Flat or maisonette,Purpose built,Yes,30,Non-binary,Buyer prefers not to say,17,Australia,Full-time - 30 hours or more,Yes,Partner,35,Non-binary,Buyer prefers not to say,,,Full-time - 30 hours or more,Yes,3,Child,14,Non-binary,Child under 16,Other,Not known,Non-binary,In government training into work,Prefers not to say,Not known,Prefers not to say,Prefers not to say,,,,,Local authority tenant,Yes,SW1A,1AA,Yes,E09000033,Westminster,1,1,1,1,,Don't know,,Yes,Yes,No,Yes,Yes,Yes,10000,Yes,Yes,10000,Yes,Don’t know ,No,,Yes,No,10,,,,,,,,,,,,,,,,,110000.0,,,Yes,20000.0,Cambridge Building Society,,10,Yes,80000.0,,,Yes,100.0,,,10000.0 ,completed,,2024-05-01T00:00:00+01:00,2024-05-01T00:00:00+01:00,2024,single log,,false,DLUHC,DLUHC,billyboy@eyeklaud.com,billyboy@eyeklaud.com,1,5,2024,,Yes - a discounted ownership scheme,Right to Acquire (RTA),,,,Yes,Yes,Yes,1,1,"1, Test Street",,Test Town,,AA1 1AA,Yes,Westminster,E09000033,,,Address line 1,SW1A 1AA,address line 1 as entered,address line 2 as entered,town or city as entered,county as entered,AB1 2CD,la as entered,2,Flat or maisonette,Purpose built,Yes,30,Non-binary,Buyer prefers not to say,17,United Kingdom,Full-time - 30 hours or more,Yes,Partner,35,Non-binary,Buyer prefers not to say,,United Kingdom,Full-time - 30 hours or more,Yes,3,Child,14,Non-binary,Child under 16,Other,Not known,Non-binary,In government training into work,Prefers not to say,Not known,Prefers not to say,Prefers not to say,,,,,Local authority tenant,Yes,AA1,1AA,Yes,E09000033,Westminster,1,1,1,1,,Don't know,,Yes,Yes,No,Yes,Yes,Yes,10000,Yes,Yes,10000,Yes,Don’t know ,No,,Yes,No,10,,,,,,,,,,,,,,,,,110000.0,,,Yes,20000.0,Cambridge Building Society,,10,Yes,80000.0,,,Yes,100.0,,,10000.0

1 ID STATUS DUPLICATESET CREATEDDATE UPLOADDATE COLLECTIONYEAR CREATIONMETHOD BULKUPLOADID DATAPROTECT OWNINGORGNAME MANINGORGNAME CREATEDBY USERNAME DAY MONTH YEAR PURCHID OWNERSHIP TYPE OTHTYPE COMPANY LIVEINBUYER JOINT JOINTMORE NOINT PRIVACYNOTICE UPRN ADDRESS1 ADDRESS2 TOWNCITY COUNTY POSTCODE ISLAINFERRED LANAME LA UPRNSELECTED ADDRESS_SEARCH_VALUE_CHECK ADDRESS1INPUT POSTCODEINPUT BULKADDRESS1 BULKADDRESS2 BULKTOWNCITY BULKCOUNTY BULKPOSTCODE BULKLA BEDS PROPTYPE BUILTYPE WCHAIR AGE1 SEX1 ETHNICGROUP1 ETHNIC NATIONALITYALL1 ECSTAT1 LIVEINBUYER1 RELAT2 AGE2 SEX2 ETHNICGROUP2 ETHNIC2 NATIONALITYALL2 ECSTAT2 LIVEINBUYER2 HHTYPE RELAT3 AGE3 SEX3 ECSTAT3 RELAT4 AGE4 SEX4 ECSTAT4 RELAT5 AGE5 SEX5 ECSTAT5 RELAT6 AGE6 SEX6 ECSTAT6 PREVTEN PPCODENK PPOSTC1 PPOSTC2 PREVIOUSLAKNOWN PREVLOC PREVLOCNAME PREGYRHA PREGOTHER PREGLA PREGGHB PREGBLANK BUY2LIVING PREVTEN2 HHREGRES HHREGRESSTILL ARMEDFORCESSPOUSE DISABLED WHEEL INC1NK INCOME1 INC1MORT INC2NK INCOME2 INC2MORT HB SAVINGSNK SAVINGS PREVOWN PREVSHARED PROPLEN STAIRCASE STAIRBOUGHT STAIROWNED STAIRCASETOSALE RESALE EXDAY EXMONTH EXYEAR HODAY HOMONTH HOYEAR LANOMAGR SOCTEN FROMBEDS FROMPROP SOCPREVTEN VALUE VALUE_VALUE_CHECK EQUITY MORTGAGEUSED MORTGAGE MORTGAGELENDER MORTGAGELENDEROTHER MORTLEN1 EXTRABOR DEPOSIT CASHDIS MRENT HASMSCHARGE MSCHARGE MSCHARGE_VALUE_CHECK DISCOUNT GRANT
2 in_progress completed 2024-05-01T00:00:00+01:00 2024-05-01T00:00:00+01:00 2024 single log false DLUHC DLUHC billyboy@eyeklaud.com billyboy@eyeklaud.com 1 5 2024 Yes - a discounted ownership scheme Right to Acquire (RTA) Yes Yes Yes 1 1 Address line 1 1, Test Street Town or city Test Town SW1A 1AA AA1 1AA Yes Westminster E09000033 Address line 1 SW1A 1AA address line 1 as entered address line 2 as entered town or city as entered county as entered AB1 2CD la as entered 2 Flat or maisonette Purpose built Yes 30 Non-binary Buyer prefers not to say 17 Australia United Kingdom Full-time - 30 hours or more Yes Partner 35 Non-binary Buyer prefers not to say United Kingdom Full-time - 30 hours or more Yes 3 Child 14 Non-binary Child under 16 Other Not known Non-binary In government training into work Prefers not to say Not known Prefers not to say Prefers not to say Local authority tenant Yes SW1A AA1 1AA Yes E09000033 Westminster 1 1 1 1 Don't know Yes Yes No Yes Yes Yes 10000 Yes Yes 10000 Yes Don’t know No Yes No 10 110000.0 Yes 20000.0 Cambridge Building Society 10 Yes 80000.0 Yes 100.0 10000.0

2
spec/fixtures/files/sales_logs_csv_export_non_support_labels_24.csv vendored

@ -1,2 +1,2 @@
id,status,duplicate_set_id,created_at,updated_at,collection_start_year,creation_method,bulk_upload_id,is_dpo,owning_organisation_name,managing_organisation_name,assigned_to,day,month,year,purchid,ownershipsch,type,othtype,companybuy,buylivein,jointpur,jointmore,noint,privacynotice,uprn,uprn_confirmed,address_line1_input,postcode_full_input,uprn_selection,address_line1,address_line2,town_or_city,county,pcode1,pcode2,la,la_label,beds,proptype,builtype,wchair,age1,sex1,ethnic_group,ethnic,nationality_all,ecstat1,buy1livein,relat2,age2,sex2,ethnic_group2,ethnicbuy2,nationality_all_buyer2,ecstat2,buy2livein,hholdcount,relat3,age3,sex3,ecstat3,relat4,age4,sex4,ecstat4,relat5,age5,sex5,ecstat5,relat6,age6,sex6,ecstat6,prevten,ppcodenk,ppostc1,ppostc2,previous_la_known,prevloc,prevloc_label,pregyrha,pregother,pregla,pregghb,pregblank,buy2living,prevtenbuy2,hhregres,hhregresstill,armedforcesspouse,disabled,wheel,income1nk,income1,inc1mort,income2nk,income2,inc2mort,hb,savingsnk,savings,prevown,prevshared,proplen,staircase,stairbought,stairowned,staircasesale,resale,exday,exmonth,exyear,hoday,homonth,hoyear,lanomagr,soctenant,frombeds,fromprop,socprevten,value,equity,mortgageused,mortgage,mortgagelender,mortgagelenderother,mortlen,extrabor,deposit,cashdis,mrent,has_mscharge,mscharge,discount,grant id,status,duplicate_set_id,created_at,updated_at,collection_start_year,creation_method,bulk_upload_id,is_dpo,owning_organisation_name,managing_organisation_name,assigned_to,day,month,year,purchid,ownershipsch,type,othtype,companybuy,buylivein,jointpur,jointmore,noint,privacynotice,uprn,uprn_confirmed,address_line1_input,postcode_full_input,uprn_selection,address_line1,address_line2,town_or_city,county,pcode1,pcode2,la,la_label,beds,proptype,builtype,wchair,age1,sex1,ethnic_group,ethnic,nationality_all,ecstat1,buy1livein,relat2,age2,sex2,ethnic_group2,ethnicbuy2,nationality_all_buyer2,ecstat2,buy2livein,hholdcount,relat3,age3,sex3,ecstat3,relat4,age4,sex4,ecstat4,relat5,age5,sex5,ecstat5,relat6,age6,sex6,ecstat6,prevten,ppcodenk,ppostc1,ppostc2,previous_la_known,prevloc,prevloc_label,pregyrha,pregother,pregla,pregghb,pregblank,buy2living,prevtenbuy2,hhregres,hhregresstill,armedforcesspouse,disabled,wheel,income1nk,income1,inc1mort,income2nk,income2,inc2mort,hb,savingsnk,savings,prevown,prevshared,proplen,staircase,stairbought,stairowned,staircasesale,resale,exday,exmonth,exyear,hoday,homonth,hoyear,lanomagr,soctenant,frombeds,fromprop,socprevten,value,equity,mortgageused,mortgage,mortgagelender,mortgagelenderother,mortlen,extrabor,deposit,cashdis,mrent,has_mscharge,mscharge,discount,grant
,in_progress,,2024-05-01T00:00:00+01:00,2024-05-01T00:00:00+01:00,2024,single log,,false,DLUHC,DLUHC,billyboy@eyeklaud.com,1,5,2024,,Yes - a discounted ownership scheme,Right to Acquire (RTA),,,,Yes,Yes,Yes,1,,,,,,Address line 1,,Town or city,,SW1A,1AA,E09000033,Westminster,2,Flat or maisonette,Purpose built,Yes,30,Non-binary,Buyer prefers not to say,17,Australia,Full-time - 30 hours or more,Yes,Partner,35,Non-binary,Buyer prefers not to say,,,Full-time - 30 hours or more,Yes,3,Child,14,Non-binary,Child under 16,Other,Not known,Non-binary,In government training into work,Prefers not to say,Not known,Prefers not to say,Prefers not to say,,,,,Local authority tenant,Yes,SW1A,1AA,Yes,E09000033,Westminster,1,1,1,1,,Don't know,,Yes,Yes,No,Yes,Yes,Yes,10000,Yes,Yes,10000,Yes,Don’t know ,No,,Yes,No,10,,,,,,,,,,,,,,,,,110000.0,,Yes,20000.0,Cambridge Building Society,,10,Yes,80000.0,,,Yes,100.0,,10000.0 ,completed,,2024-05-01T00:00:00+01:00,2024-05-01T00:00:00+01:00,2024,single log,,false,DLUHC,DLUHC,billyboy@eyeklaud.com,1,5,2024,,Yes - a discounted ownership scheme,Right to Acquire (RTA),,,,Yes,Yes,Yes,1,1,Yes,Address line 1,SW1A 1AA,,"1, Test Street",,Test Town,,AA1,1AA,E09000033,Westminster,2,Flat or maisonette,Purpose built,Yes,30,Non-binary,Buyer prefers not to say,17,United Kingdom,Full-time - 30 hours or more,Yes,Partner,35,Non-binary,Buyer prefers not to say,,United Kingdom,Full-time - 30 hours or more,Yes,3,Child,14,Non-binary,Child under 16,Other,Not known,Non-binary,In government training into work,Prefers not to say,Not known,Prefers not to say,Prefers not to say,,,,,Local authority tenant,Yes,AA1,1AA,Yes,E09000033,Westminster,1,1,1,1,,Don't know,,Yes,Yes,No,Yes,Yes,Yes,10000,Yes,Yes,10000,Yes,Don’t know ,No,,Yes,No,10,,,,,,,,,,,,,,,,,110000.0,,Yes,20000.0,Cambridge Building Society,,10,Yes,80000.0,,,Yes,100.0,,10000.0

1 id status duplicate_set_id created_at updated_at collection_start_year creation_method bulk_upload_id is_dpo owning_organisation_name managing_organisation_name assigned_to day month year purchid ownershipsch type othtype companybuy buylivein jointpur jointmore noint privacynotice uprn uprn_confirmed address_line1_input postcode_full_input uprn_selection address_line1 address_line2 town_or_city county pcode1 pcode2 la la_label beds proptype builtype wchair age1 sex1 ethnic_group ethnic nationality_all ecstat1 buy1livein relat2 age2 sex2 ethnic_group2 ethnicbuy2 nationality_all_buyer2 ecstat2 buy2livein hholdcount relat3 age3 sex3 ecstat3 relat4 age4 sex4 ecstat4 relat5 age5 sex5 ecstat5 relat6 age6 sex6 ecstat6 prevten ppcodenk ppostc1 ppostc2 previous_la_known prevloc prevloc_label pregyrha pregother pregla pregghb pregblank buy2living prevtenbuy2 hhregres hhregresstill armedforcesspouse disabled wheel income1nk income1 inc1mort income2nk income2 inc2mort hb savingsnk savings prevown prevshared proplen staircase stairbought stairowned staircasesale resale exday exmonth exyear hoday homonth hoyear lanomagr soctenant frombeds fromprop socprevten value equity mortgageused mortgage mortgagelender mortgagelenderother mortlen extrabor deposit cashdis mrent has_mscharge mscharge discount grant
2 in_progress completed 2024-05-01T00:00:00+01:00 2024-05-01T00:00:00+01:00 2024 single log false DLUHC DLUHC billyboy@eyeklaud.com 1 5 2024 Yes - a discounted ownership scheme Right to Acquire (RTA) Yes Yes Yes 1 1 Yes Address line 1 SW1A 1AA Address line 1 1, Test Street Town or city Test Town SW1A AA1 1AA E09000033 Westminster 2 Flat or maisonette Purpose built Yes 30 Non-binary Buyer prefers not to say 17 Australia United Kingdom Full-time - 30 hours or more Yes Partner 35 Non-binary Buyer prefers not to say United Kingdom Full-time - 30 hours or more Yes 3 Child 14 Non-binary Child under 16 Other Not known Non-binary In government training into work Prefers not to say Not known Prefers not to say Prefers not to say Local authority tenant Yes SW1A AA1 1AA Yes E09000033 Westminster 1 1 1 1 Don't know Yes Yes No Yes Yes Yes 10000 Yes Yes 10000 Yes Don’t know No Yes No 10 110000.0 Yes 20000.0 Cambridge Building Society 10 Yes 80000.0 Yes 100.0 10000.0

2
spec/models/form/lettings/questions/uprn_spec.rb

@ -56,7 +56,7 @@ RSpec.describe Form::Lettings::Questions::Uprn, type: :model do
let(:log) do let(:log) do
create( create(
:lettings_log, :lettings_log,
:completed, :in_progress,
address_line1: "1, Test Street", address_line1: "1, Test Street",
town_or_city: "Test Town", town_or_city: "Test Town",
county: "Test County", county: "Test County",

4
spec/models/form/sales/questions/uprn_spec.rb

@ -54,7 +54,7 @@ RSpec.describe Form::Sales::Questions::Uprn, type: :model do
context "when address is present" do context "when address is present" do
let(:log) do let(:log) do
create( build(
:sales_log, :sales_log,
:completed, :completed,
address_line1: "1, Test Street", address_line1: "1, Test Street",
@ -81,7 +81,7 @@ RSpec.describe Form::Sales::Questions::Uprn, type: :model do
it "returns formatted value" do it "returns formatted value" do
expect(question.get_extra_check_answer_value(log)).to eq( expect(question.get_extra_check_answer_value(log)).to eq(
"\n\n1, Test Street\nTest Town\nAA1 1AA\nWestminster", "\n\n1, Test Street\nTest Town\nAA1 1AA\nBarnet",
) )
end end
end end

1
spec/models/form_spec.rb

@ -14,7 +14,6 @@ RSpec.describe Form, type: :model do
let(:lettings_log) { FactoryBot.build(:lettings_log, :in_progress) } let(:lettings_log) { FactoryBot.build(:lettings_log, :in_progress) }
let(:form) { lettings_log.form } let(:form) { lettings_log.form }
let(:completed_lettings_log) { FactoryBot.build(:lettings_log, :completed) } let(:completed_lettings_log) { FactoryBot.build(:lettings_log, :completed) }
let(:conditional_section_complete_lettings_log) { FactoryBot.build(:lettings_log, :conditional_section_complete) }
describe ".next_page" do describe ".next_page" do
let(:previous_page_id) { form.get_page("person_1_age") } let(:previous_page_id) { form.get_page("person_1_age") }

11
spec/models/log_spec.rb

@ -7,23 +7,26 @@ RSpec.describe Log, type: :model do
end end
describe "#calculate_status" do describe "#calculate_status" do
let(:organisation) { build(:organisation, id: 1) }
let(:user) { build(:user, id: 1, organisation:) }
it "returns the correct status for a completed sales log" do it "returns the correct status for a completed sales log" do
complete_sales_log = create(:sales_log, :completed, saledate: Time.zone.local(2023, 12, 12), status: nil) complete_sales_log = build(:sales_log, :completed, assigned_to: user)
expect(complete_sales_log.calculate_status).to eq "completed" expect(complete_sales_log.calculate_status).to eq "completed"
end end
it "returns the correct status for an in progress sales log" do it "returns the correct status for an in progress sales log" do
in_progress_sales_log = create(:sales_log, :in_progress, saledate: Time.zone.local(2023, 12, 12), status: nil) in_progress_sales_log = build(:sales_log, :in_progress, assigned_to: user)
expect(in_progress_sales_log.calculate_status).to eq "in_progress" expect(in_progress_sales_log.calculate_status).to eq "in_progress"
end end
it "returns the correct status for a completed lettings log" do it "returns the correct status for a completed lettings log" do
complete_lettings_log = create(:lettings_log, :completed, startdate: Time.zone.local(2023, 12, 12), voiddate: Time.zone.local(2023, 12, 11), mrcdate: Time.zone.local(2023, 12, 11), status: nil) complete_lettings_log = build(:lettings_log, :completed, assigned_to: user)
expect(complete_lettings_log.calculate_status).to eq "completed" expect(complete_lettings_log.calculate_status).to eq "completed"
end end
it "returns the correct status for an in progress lettings log" do it "returns the correct status for an in progress lettings log" do
in_progress_lettings_log = create(:lettings_log, :in_progress, startdate: Time.zone.local(2023, 12, 12), status: nil) in_progress_lettings_log = build(:lettings_log, :in_progress, assigned_to: user)
expect(in_progress_lettings_log.calculate_status).to eq "in_progress" expect(in_progress_lettings_log.calculate_status).to eq "in_progress"
end end
end end

16
spec/presenters/homepage_presenter_spec.rb

@ -176,7 +176,8 @@ RSpec.describe HomepagePresenter do
let(:startdate) { date_last_year } let(:startdate) { date_last_year }
it "exposes the correct data for the data box" do it "exposes the correct data for the data box" do
create_list(type, expected_count, status, assigned_to: user, startdate:) logs = build_list(type, expected_count, status, assigned_to: user, startdate:)
logs.each { |log| log.save(validate: false) }
data = presenter.last_year_in_progress_lettings_data data = presenter.last_year_in_progress_lettings_data
expect(data[:count]).to be expected_count expect(data[:count]).to be expected_count
@ -197,7 +198,7 @@ RSpec.describe HomepagePresenter do
let(:startdate) { date_this_year } let(:startdate) { date_this_year }
it "exposes the correct data for the data box" do it "exposes the correct data for the data box" do
create_list(type, expected_count, :completed2024, assigned_to: user, startdate:) create_list(type, expected_count, :completed, assigned_to: user, startdate:)
data = presenter.current_year_completed_lettings_data data = presenter.current_year_completed_lettings_data
expect(data[:count]).to be expected_count expect(data[:count]).to be expected_count
@ -214,7 +215,8 @@ RSpec.describe HomepagePresenter do
let(:startdate) { date_last_year } let(:startdate) { date_last_year }
it "exposes the correct data for the data box" do it "exposes the correct data for the data box" do
create_list(type, expected_count, status, assigned_to: user, startdate:) logs = build_list(type, expected_count, status, assigned_to: user, startdate:)
logs.each { |log| log.save(validate: false) }
data = presenter.last_year_completed_lettings_data data = presenter.last_year_completed_lettings_data
expect(data[:count]).to be expected_count expect(data[:count]).to be expected_count
@ -256,7 +258,8 @@ RSpec.describe HomepagePresenter do
let(:saledate) { date_last_year } let(:saledate) { date_last_year }
it "exposes the correct data for the data box" do it "exposes the correct data for the data box" do
create_list(type, expected_count, status, assigned_to: user, saledate:) logs = build_list(type, expected_count, status, assigned_to: user, saledate:)
logs.each { |log| log.save(validate: false) }
data = presenter.last_year_in_progress_sales_data data = presenter.last_year_in_progress_sales_data
expect(data[:count]).to be expected_count expect(data[:count]).to be expected_count
@ -277,7 +280,7 @@ RSpec.describe HomepagePresenter do
let(:saledate) { date_this_year } let(:saledate) { date_this_year }
it "exposes the correct data for the data box" do it "exposes the correct data for the data box" do
create_list(type, expected_count, :completed2024, assigned_to: user, saledate:) create_list(type, expected_count, :completed, assigned_to: user, saledate:)
data = presenter.current_year_completed_sales_data data = presenter.current_year_completed_sales_data
expect(data[:count]).to be expected_count expect(data[:count]).to be expected_count
@ -294,7 +297,8 @@ RSpec.describe HomepagePresenter do
let(:saledate) { date_last_year } let(:saledate) { date_last_year }
it "exposes the correct data for the data box" do it "exposes the correct data for the data box" do
create_list(type, expected_count, status, assigned_to: user, saledate:) logs = build_list(type, expected_count, status, assigned_to: user, saledate:)
logs.each { |log| log.save(validate: false) }
data = presenter.last_year_completed_sales_data data = presenter.last_year_completed_sales_data
expect(data[:count]).to be expected_count expect(data[:count]).to be expected_count

11
spec/request_helper.rb

@ -17,6 +17,17 @@ module RequestHelper
WebMock.stub_request(:get, "https://api.postcodes.io/postcodes/SW1A1AA") WebMock.stub_request(:get, "https://api.postcodes.io/postcodes/SW1A1AA")
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"postcode\":\"ZZ1 1ZZ\",\"admin_district\":\"Westminster\",\"codes\":{\"admin_district\":\"E09000033\"}}}", headers: {}) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"postcode\":\"ZZ1 1ZZ\",\"admin_district\":\"Westminster\",\"codes\":{\"admin_district\":\"E09000033\"}}}", headers: {})
body = { results: [{ DPA: { UPRN: "10033558653" } }] }.to_json
WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/find?key&maxresults=10&minmatch=0.4&query=Address%20line%201,%20SW1A%201AA")
.to_return(status: 200, body:, headers: {})
body = { results: [{ DPA: { "POSTCODE": "SW1A 1AA", "POST_TOWN": "London" } }] }.to_json
WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key&uprn=1")
.to_return(status: 200, body:, headers: {})
WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key&uprn=10033558653")
.to_return(status: 200, body:, headers: {})
WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key=OS_DATA_KEY&uprn=10033558653")
.to_return(status: 200, body:, headers: {})
WebMock.stub_request(:post, /api.notifications.service.gov.uk\/v2\/notifications\/email/) WebMock.stub_request(:post, /api.notifications.service.gov.uk\/v2\/notifications\/email/)
.to_return(status: 200, body: "", headers: {}) .to_return(status: 200, body: "", headers: {})
WebMock.stub_request(:post, /api.notifications.service.gov.uk\/v2\/notifications\/sms/) WebMock.stub_request(:post, /api.notifications.service.gov.uk\/v2\/notifications\/sms/)

172
spec/requests/lettings_logs_controller_spec.rb

@ -1076,8 +1076,8 @@ RSpec.describe LettingsLogsController, type: :request do
end end
context "when requesting a specific lettings log" do context "when requesting a specific lettings log" do
let!(:completed_lettings_log) { FactoryBot.create(:lettings_log, :completed, owning_organisation: user.organisation, managing_organisation: user.organisation, assigned_to: user) } let(:lettings_log) { create(:lettings_log, :in_progress, assigned_to: user) }
let(:id) { completed_lettings_log.id } let(:id) { lettings_log.id }
before do before do
get "/lettings-logs/#{id}", headers: get "/lettings-logs/#{id}", headers:
@ -1089,7 +1089,7 @@ RSpec.describe LettingsLogsController, type: :request do
it "returns a serialized lettings log" do it "returns a serialized lettings log" do
json_response = JSON.parse(response.body) json_response = JSON.parse(response.body)
expect(json_response["status"]).to eq(completed_lettings_log.status) expect(json_response["status"]).to eq(lettings_log.status)
end end
context "when requesting an invalid lettings log id" do context "when requesting an invalid lettings log id" do
@ -1101,12 +1101,10 @@ RSpec.describe LettingsLogsController, type: :request do
end end
context "when viewing a pending log" do context "when viewing a pending log" do
let(:completed_lettings_log) do let(:lettings_log) do
FactoryBot.create( create(
:lettings_log, :lettings_log,
:completed, :in_progress,
owning_organisation: user.organisation,
managing_organisation: user.organisation,
assigned_to: user, assigned_to: user,
status: "pending", status: "pending",
skip_update_status: true, skip_update_status: true,
@ -1123,28 +1121,21 @@ RSpec.describe LettingsLogsController, type: :request do
context "with a user that is not signed in" do context "with a user that is not signed in" do
it "does not let the user get lettings log tasklist pages they don't have access to" do it "does not let the user get lettings log tasklist pages they don't have access to" do
get "/lettings-logs/#{lettings_log.id}", headers:, params: {} get lettings_log_path(lettings_log)
expect(response).to redirect_to("/account/sign-in") expect(response).to redirect_to("/account/sign-in")
end end
end end
context "with a signed in user" do context "with a signed in user" do
let(:lettings_log) { create(:lettings_log, :in_progress, assigned_to: user) }
before do before do
Timecop.freeze(2021, 4, 1) sign_in user
Singleton.__init__(FormHandler)
completed_lettings_log.update!(startdate: Time.zone.local(2021, 4, 1), voiddate: Time.zone.local(2021, 4, 1), mrcdate: Time.zone.local(2021, 4, 1))
completed_lettings_log.reload
end end
context "with lettings logs that are owned or managed by your organisation" do context "with lettings logs that are owned or managed by your organisation" do
before do before do
sign_in user get lettings_log_path(lettings_log)
get "/lettings-logs/#{lettings_log.id}", headers:, params: {}
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end end
it "shows the tasklist for lettings logs you have access to" do it "shows the tasklist for lettings logs you have access to" do
@ -1153,119 +1144,54 @@ RSpec.describe LettingsLogsController, type: :request do
end end
it "displays a section status for a lettings log" do it "displays a section status for a lettings log" do
assert_select ".govuk-tag", text: /Not started/, count: 6 assert_select ".govuk-tag", text: /Not started/, count: 3
assert_select ".govuk-tag", text: /In progress/, count: 2 assert_select ".govuk-tag", text: /In progress/, count: 3
assert_select ".govuk-tag", text: /Completed/, count: 0 assert_select ".govuk-tag", text: /Completed/, count: 1
assert_select ".govuk-tag", text: /Cannot start yet/, count: 1 assert_select ".govuk-tag", text: /Cannot start yet/, count: 0
end end
it "displays a link to update the log for currently editable logs" do context "and the log is completed" do
completed_lettings_log.update!(startdate: Time.zone.local(2021, 4, 1), tenancylength: nil) let(:lettings_log) { create(:lettings_log, :completed, assigned_to: user) }
completed_lettings_log.reload
get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {} it "displays a link to update the log for currently editable logs" do
expect(completed_lettings_log.form.new_logs_end_date).to eq(Time.zone.local(2022, 11, 20)) expect(lettings_log.status).to eq("completed")
expect(completed_lettings_log.status).to eq("completed") expect(page).to have_link("review and make changes to this log", href: "/lettings-logs/#{lettings_log.id}/review")
expect(page).to have_link("review and make changes to this log", href: "/lettings-logs/#{completed_lettings_log.id}/review") end
end end
end end
context "with lettings logs from a closed collection period before the previous collection" do context "with lettings logs from a closed collection period before the previous collection" do
before do let(:lettings_log) do
sign_in user log = build(:lettings_log, :in_progress, assigned_to: user, startdate: Time.zone.today - 2.years)
Timecop.return log.save!(validate: false)
Singleton.__init__(FormHandler) log
get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {}
end end
it "redirects to review page" do
expect(response).to redirect_to("/lettings-logs/#{completed_lettings_log.id}/review")
end
end
context "with lettings logs from a closed previous collection period" do
before do before do
sign_in user get lettings_log_path(lettings_log)
Timecop.freeze(2023, 2, 1)
Singleton.__init__(FormHandler)
get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {}
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end end
it "redirects to review page" do it "redirects to review page" do
expect(response).to redirect_to("/lettings-logs/#{completed_lettings_log.id}/review") expect(response).to redirect_to("/lettings-logs/#{lettings_log.id}/review")
end end
it "displays a closed collection window message for previous collection year logs" do it "displays a closed collection window message for previous collection year logs" do
get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {}
expect(completed_lettings_log.form.new_logs_end_date).to eq(Time.zone.local(2022, 11, 20))
expect(completed_lettings_log.status).to eq("completed")
follow_redirect! follow_redirect!
expect(page).to have_content("This log is from the 2021/2022 collection window, which is now closed.") expect(page).to have_content(/This log is from the \d{4}\/\d{4} collection window, which is now closed\./)
end end
end end
context "when a lettings log is for a renewal of supported housing, property information does not need to show" do context "when a lettings log is for a renewal of supported housing" do
let(:lettings_log) do let(:lettings_log) { create(:lettings_log, :startdate_today, assigned_to: user, renewal: 1, needstype: 2, rent_type: 3, postcode_known: 0) }
FactoryBot.create(
:lettings_log,
owning_organisation: user.organisation,
managing_organisation: user.organisation,
assigned_to: user,
startdate: Time.zone.now,
renewal: 1,
needstype: 2,
rent_type: 3,
postcode_known: 0,
)
end
before do
sign_in user
end
around do |example| it "does not show property information" do
FormHandler.instance.use_real_forms! get lettings_log_path(lettings_log)
example.run expect(page).to have_content "Tenancy information"
FormHandler.instance.use_fake_forms! expect(page).not_to have_content "Property information"
end end
it "does not crash the app if postcode_known is not nil" do it "does not crash the app if postcode_known is not nil" do
expect { expect { get lettings_log_path(lettings_log) }.not_to raise_error
get "/lettings-logs/#{lettings_log.id}", headers:, params: {}
}.not_to raise_error(ActionView::Template::Error)
end
end
context "with a lettings log with a single section complete" do
let(:section_completed_lettings_log) do
FactoryBot.create(
:lettings_log,
:conditional_section_complete,
assigned_to: user,
)
end
before do
Timecop.freeze(2021, 4, 1)
Singleton.__init__(FormHandler)
sign_in user
get "/lettings-logs/#{section_completed_lettings_log.id}", headers:, params: {}
end
after do
Timecop.unfreeze
Singleton.__init__(FormHandler)
end
it "displays a section status for a lettings log" do
assert_select ".govuk-tag", text: /Not started/, count: 6
assert_select ".govuk-tag", text: /Completed/, count: 1
assert_select ".govuk-tag", text: /Cannot start yet/, count: 1
end end
end end
@ -1280,25 +1206,19 @@ RSpec.describe LettingsLogsController, type: :request do
end end
end end
context "when the log is unresolved" do context "when valid scheme and location are added to an unresolved log" do
let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let(:scheme) { create(:scheme, owning_organisation: user.organisation) }
let!(:location) { FactoryBot.create(:location, scheme:) } let(:location) { create(:location, scheme:) }
let(:lettings_log) { create(:lettings_log, :in_progress, assigned_to: user, unresolved: true) }
let(:further_unresolved_logs_count) { 2 }
before do before do
Timecop.freeze(2021, 4, 1) create_list(:lettings_log, further_unresolved_logs_count, unresolved: true, assigned_to: user)
Singleton.__init__(FormHandler) lettings_log.update!(needstype: 2, scheme:, location:)
FactoryBot.create_list(:lettings_log, 3, unresolved: true, assigned_to: user) get lettings_log_path(lettings_log)
lettings_log.update!(needstype: 2, scheme:, location:, unresolved: true)
sign_in user
get "/lettings-logs/#{lettings_log.id}", headers:, params: {}
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end end
it "marks it as resolved when both scheme and location exist" do it "marks the log as resolved" do
lettings_log.reload lettings_log.reload
expect(lettings_log.unresolved).to eq(false) expect(lettings_log.unresolved).to eq(false)
end end
@ -1306,7 +1226,7 @@ RSpec.describe LettingsLogsController, type: :request do
it "displays a success banner" do it "displays a success banner" do
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("You’ve updated all the fields affected by the scheme change") expect(page).to have_content("You’ve updated all the fields affected by the scheme change")
expect(page).to have_link("Update 3 more logs", href: "/lettings-logs/update-logs") expect(page).to have_link("Update #{further_unresolved_logs_count} more logs", href: "/lettings-logs/update-logs")
end end
end end
end end
@ -1943,7 +1863,7 @@ RSpec.describe LettingsLogsController, type: :request do
sign_in user sign_in user
FactoryBot.create(:lettings_log) FactoryBot.create(:lettings_log)
FactoryBot.create(:lettings_log, FactoryBot.create(:lettings_log,
:completed, :in_progress,
owning_organisation:, owning_organisation:,
managing_organisation: owning_organisation, managing_organisation: owning_organisation,
assigned_to: user) assigned_to: user)

Loading…
Cancel
Save