Browse Source

CLDC-3501: Audit temporarily paused tests (#3127)

* CLDC-3501: Remove unfinished LogCreator tests

seems unclear what the test looked to verify, an existing log cannot be created

* CLDC-3501: Remove charge not provided test

this was moved to a soft validation in #1359

* CLDC-3501: Remove some year dependencies on LettingsLogController tests

no need to store a json of a complete log, we can generate this dynamically

* CLDC-3501: Reinstate skipped setup test

add some new time helpers to do with crossover periods

* CLDC-3501: Reinstate skipped schemes test

Can be made non specific to the year

* CLDC-3501: Reinstate skipped managing org rake test

the log can never be completed as it is missing info

* CLDC-3501: Reinstate row parser completed test

no changes needed, it already passes
main
Samuel Young 3 days ago committed by GitHub
parent
commit
7419663342
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      app/helpers/collection_time_helper.rb
  2. 4
      spec/features/schemes_spec.rb
  3. 179
      spec/fixtures/complete_lettings_log.json
  4. 6
      spec/lib/tasks/set_sales_managing_organisation_spec.rb
  5. 12
      spec/models/validations/financial_validations_spec.rb
  6. 20
      spec/models/validations/setup_validations_spec.rb
  7. 53
      spec/requests/lettings_logs_controller_spec.rb
  8. 4
      spec/services/bulk_upload/lettings/log_creator_spec.rb
  9. 2
      spec/services/bulk_upload/lettings/year2025/row_parser_spec.rb
  10. 4
      spec/services/bulk_upload/sales/log_creator_spec.rb

8
app/helpers/collection_time_helper.rb

@ -58,6 +58,14 @@ module CollectionTimeHelper
current_collection_start_year - 2 current_collection_start_year - 2
end end
def previous_collection_new_logs_end_date
FormHandler.instance.lettings_form_for_start_year(previous_collection_start_year).new_logs_end_date
end
def previous_collection_edit_end_date
FormHandler.instance.lettings_form_for_start_year(previous_collection_start_year).edit_end_date
end
def generate_different_date_within_collection_year(date, start_date_override: nil, end_date_override: nil) def generate_different_date_within_collection_year(date, start_date_override: nil, end_date_override: nil)
start_date = [start_date_override&.to_date, collection_start_date(date).to_date].compact.max.to_date start_date = [start_date_override&.to_date, collection_start_date(date).to_date].compact.max.to_date
end_date = [end_date_override&.to_date, collection_end_date(date).to_date].compact.min.to_date end_date = [end_date_override&.to_date, collection_end_date(date).to_date].compact.min.to_date

4
spec/features/schemes_spec.rb

@ -833,12 +833,12 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content("Deactivated") expect(page).to have_content("Deactivated")
end end
xit "allows to reactivate a location" do it "allows to reactivate a location" do
click_link("Reactivate this location") click_link("Reactivate this location")
expect(page).to have_current_path("/schemes/#{scheme.id}/locations/#{deactivated_location.id}/new-reactivation") expect(page).to have_current_path("/schemes/#{scheme.id}/locations/#{deactivated_location.id}/new-reactivation")
expect(page).to have_content("Reactivate #{deactivated_location.name}") expect(page).to have_content("Reactivate #{deactivated_location.name}")
expect(page).to have_content("You’ll be able to add logs with this location if their tenancy start date is on or after the date you enter.") expect(page).to have_content("You’ll be able to add logs with this location if their tenancy start date is on or after the date you enter.")
expect(page).to have_content("If the date is before 1 April 2022, select ‘From the start of the open collection period’ because the previous period has now closed.") expect(page).to have_content(/If the date is before 1 April \d{4}, select ‘From the start of the open collection period’ because the previous period has now closed./)
end end
context "when I press the back button" do context "when I press the back button" do

179
spec/fixtures/complete_lettings_log.json vendored

@ -1,179 +0,0 @@
{
"lettings_log": {
"tenancycode": "T1245",
"age1": 34,
"sex1": "M",
"ethnic": 1,
"national": 1,
"prevten": 3,
"ecstat1": 1,
"hhmemb": 3,
"age2": 29,
"sex2": "F",
"ecstat2": 2,
"age3": 11,
"sex3": "R",
"ecstat3": 9,
"age4": null,
"sex4": null,
"ecstat4": null,
"age5": null,
"sex5": null,
"ecstat5": null,
"age6": null,
"sex6": null,
"ecstat6": null,
"age7": null,
"sex7": null,
"ecstat7": null,
"age8": null,
"sex8": null,
"ecstat8": null,
"homeless": 1,
"underoccupation_benefitcap": 2,
"leftreg": null,
"reservist": null,
"illness": 2,
"preg_occ": 2,
"startertenancy": 2,
"tenancylength": null,
"tenancy": 2,
"ppostcode_full": "NW18TR",
"rsnvac": 5,
"unittype_gn": 7,
"beds": 2,
"offered": 0,
"wchair": 1,
"earnings": 190,
"incfreq": 1,
"benefits": 3,
"period": 3,
"layear": 7,
"waityear": 2,
"postcode_full": "NW18EE",
"reasonpref": 2,
"cbl": 1,
"chr": 0,
"cap": 0,
"reasonother": "",
"housingneeds": 1,
"housingneeds_type": 2,
"housingneeds_other": 0,
"housingneeds_c": 1,
"illness_type_1": null,
"illness_type_2": null,
"illness_type_3": null,
"illness_type_4": null,
"illness_type_8": null,
"illness_type_5": null,
"illness_type_6": null,
"illness_type_7": null,
"illness_type_9": null,
"illness_type_10": null,
"rp_homeless": null,
"rp_insan_unsat": null,
"rp_medwel": null,
"rp_hardship": null,
"rp_dontknow": null,
"tenancyother": "",
"net_income_value_check": null,
"property_owner_organisation": null,
"property_manager_organisation": null,
"irproduct_other": "",
"purchaser_code": null,
"reason": 42,
"propcode": "PT562",
"majorrepairs": 1,
"la": "E09000007",
"prevloc": "E09000007",
"hb": 9,
"hbrentshortfall": null,
"property_relet": null,
"mrcdate": "2021-05-07T00:00:00.000+01:00",
"incref": null,
"startdate": "2021-06-06T00:00:00.000+01:00",
"armedforces": 2,
"first_time_property_let_as_social_housing": 0,
"unitletas": 1,
"builtype": 1,
"voiddate": "2021-05-05T00:00:00.000+01:00",
"owning_organisation_id": 1,
"managing_organisation_id": 1,
"renttype": 2,
"needstype": 1,
"lettype": 7,
"postcode_known": 1,
"is_la_inferred": true,
"totchild": 1,
"totelder": 0,
"totadult": 2,
"net_income_known": 0,
"nocharge": 0,
"is_carehome": null,
"household_charge": null,
"referral": 2,
"brent": "350.0",
"scharge": "11.0",
"pscharge": "11.0",
"supcharg": "0.0",
"tcharge": "372.0",
"tshortfall": null,
"chcharge": null,
"declaration": 1,
"ppcodenk": 1,
"previous_la_known": null,
"is_previous_la_inferred": true,
"age1_known": 0,
"age2_known": 0,
"age3_known": 0,
"age4_known": null,
"age5_known": null,
"age6_known": null,
"age7_known": null,
"age8_known": null,
"ethnic_group": 0,
"letting_allocation_unknown": 0,
"details_known_2": 0,
"details_known_3": 0,
"details_known_4": null,
"details_known_5": null,
"details_known_6": null,
"details_known_7": null,
"details_known_8": null,
"rent_type": 1,
"has_benefits": 0,
"renewal": 0,
"wrent": "87.5",
"wscharge": "2.75",
"wpschrge": "2.75",
"wsupchrg": "0.0",
"wtcharge": "93.0",
"wtshortfall": null,
"refused": 1,
"wchchrg": null,
"newprop": 2,
"relat2": "P",
"relat3": "C",
"relat4": null,
"relat5": null,
"relat6": null,
"relat7": null,
"relat8": null,
"rent_value_check": null,
"old_form_id": null,
"lar": null,
"irproduct": null,
"old_id": null,
"joint": null,
"assigned_to_id": 2,
"retirement_value_check": null,
"tshortfall_known": null,
"sheltered": null,
"pregnancy_value_check": null,
"hhtype": 6,
"new_old": 1,
"vacdays": 30,
"scheme_id": null,
"location_id": null
}
}

6
spec/lib/tasks/set_sales_managing_organisation_spec.rb

@ -14,13 +14,13 @@ RSpec.describe "set_sales_managing_organisation" do
context "when the rake task is run" do context "when the rake task is run" do
let!(:sales_log) { create(:sales_log, :completed, managing_organisation_id: nil) } let!(:sales_log) { create(:sales_log, :completed, managing_organisation_id: nil) }
xit "updates sales log managing_organisation_id with owning_organisation_id" do it "updates sales log managing_organisation_id with owning_organisation_id" do
expect(sales_log.managing_organisation_id).to eq(nil) expect(sales_log.managing_organisation_id).to eq(nil)
expect(sales_log.status).to eq("completed") expect(sales_log.status).to eq("in_progress")
task.invoke task.invoke
sales_log.reload sales_log.reload
expect(sales_log.managing_organisation_id).to eq(sales_log.owning_organisation_id) expect(sales_log.managing_organisation_id).to eq(sales_log.owning_organisation_id)
expect(sales_log.status).to eq("completed") expect(sales_log.status).to eq("in_progress")
end end
it "does not update sales log managing_organisation_id if owning_organisation_id is nil" do it "does not update sales log managing_organisation_id if owning_organisation_id is nil" do

12
spec/models/validations/financial_validations_spec.rb

@ -1191,18 +1191,6 @@ RSpec.describe Validations::FinancialValidations do
end end
end end
context "and charges are not provided" do
xit "throws an error" do
record.period = 3
record.chcharge = nil
financial_validator.validate_care_home_charges(record)
expect(record.errors["chcharge"])
.to include(match I18n.t("validations.lettings.financial.carehome.not_provided", period: "every 4 weeks"))
expect(record.errors["is_carehome"])
.to include(match I18n.t("validations.lettings.financial.carehome.not_provided", period: "every 4 weeks"))
end
end
context "and charges under valid limit (£10pw)" do context "and charges under valid limit (£10pw)" do
it "validates charge when period is weekly for 52 weeks" do it "validates charge when period is weekly for 52 weeks" do
record.period = 1 record.period = 1

20
spec/models/validations/setup_validations_spec.rb

@ -1,6 +1,8 @@
require "rails_helper" require "rails_helper"
RSpec.describe Validations::SetupValidations do RSpec.describe Validations::SetupValidations do
include CollectionTimeHelper
subject(:setup_validator) { setup_validator_class.new } subject(:setup_validator) { setup_validator_class.new }
let(:setup_validator_class) { Class.new { include Validations::SetupValidations } } let(:setup_validator_class) { Class.new { include Validations::SetupValidations } }
@ -96,24 +98,28 @@ RSpec.describe Validations::SetupValidations do
context "when after the new logs end date but before edit end date for the previous period" do context "when after the new logs end date but before edit end date for the previous period" do
before do before do
allow(Time).to receive(:now).and_return(Time.zone.local(2024, 1, 8)) Timecop.freeze(previous_collection_edit_end_date)
end
after do
Timecop.return
end end
it "cannot create new logs for the previous collection year" do it "cannot create new logs for the previous collection year" do
record.update!(startdate: nil) record.update!(startdate: nil)
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = previous_collection_start_date
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date within the 2023 to 2024 collection year, which is between 1st April 2023 and 31st March 2024") expect(record.errors["startdate"]).to include(match "Enter a date within the #{current_collection_start_year} to #{next_collection_start_year} collection year, which is between 1st April #{current_collection_start_year} and 31st March #{next_collection_start_year}")
end end
xit "can edit already created logs for the previous collection year" do it "can edit already created logs for the previous collection year" do
record.startdate = Time.zone.local(2023, 1, 2) record.startdate = previous_collection_start_date + 1.day
record.save!(validate: false) record.save!(validate: false)
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = previous_collection_start_date
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).not_to include(match "Enter a date within the 2023 to 2024 collection year, which is between 1st April 2023 and 31st March 2024") expect(record.errors["startdate"]).not_to include(match "Enter a date within the #{current_collection_start_year} to #{next_collection_start_year} collection year, which is between 1st April #{current_collection_start_year} and 31st March #{next_collection_start_year}")
end end
end end

53
spec/requests/lettings_logs_controller_spec.rb

@ -21,13 +21,11 @@ RSpec.describe LettingsLogsController, type: :request do
"Authorization" => basic_credentials, "Authorization" => basic_credentials,
} }
end end
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
before do before do
allow(ENV).to receive(:[]) allow(ENV).to receive(:[])
allow(ENV).to receive(:[]).with("API_USER").and_return(api_username) allow(ENV).to receive(:[]).with("API_USER").and_return(api_username)
allow(ENV).to receive(:[]).with("API_KEY").and_return(api_password) allow(ENV).to receive(:[]).with("API_KEY").and_return(api_password)
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form)
end end
describe "POST #create" do describe "POST #create" do
@ -46,6 +44,12 @@ RSpec.describe LettingsLogsController, type: :request do
"managing_organisation_id": managing_organisation.id, "managing_organisation_id": managing_organisation.id,
"assigned_to_id": user.id, "assigned_to_id": user.id,
"tenancycode": tenant_code, "tenancycode": tenant_code,
"startdate": current_date.strftime("%Y-%m-%d"),
"renewal": 0,
"needstype": 1,
"rent_type": 1,
"declaration": 1,
"manual_address_entry_selected": true,
"age1": age1, "age1": age1,
"postcode_full": postcode_full, "postcode_full": postcode_full,
"offered": offered, "offered": offered,
@ -54,14 +58,9 @@ RSpec.describe LettingsLogsController, type: :request do
end end
before do before do
Timecop.freeze(Time.utc(2022, 2, 8))
post "/lettings-logs", headers:, params: params.to_json post "/lettings-logs", headers:, params: params.to_json
end end
after do
Timecop.unfreeze
end
it "returns http success" do it "returns http success" do
expect(response).to have_http_status(:success) expect(response).to have_http_status(:success)
end end
@ -80,12 +79,11 @@ RSpec.describe LettingsLogsController, type: :request do
context "with invalid json parameters" do context "with invalid json parameters" do
let(:age1) { 2000 } let(:age1) { 2000 }
let(:offered) { 21 }
it "validates lettings log parameters" do it "validates lettings log parameters" do
json_response = JSON.parse(response.body) json_response = JSON.parse(response.body)
expect(response).to have_http_status(:unprocessable_content) expect(response).to have_http_status(:unprocessable_content)
expect(json_response["errors"]).to match_array([["offered", [I18n.t("validations.shared.numeric.within_range", field: "Times previously offered since becoming available", min: 0, max: 20)]], ["age1", [I18n.t("validations.shared.numeric.within_range", field: "Lead tenant’s age", min: 16, max: 120)]]]) expect(json_response["errors"]).to match_array([["age1", [I18n.t("validations.shared.numeric.within_range", field: "Lead tenant’s age", min: 16, max: 120)]]])
end end
end end
@ -97,21 +95,11 @@ RSpec.describe LettingsLogsController, type: :request do
end end
context "with a complete lettings log submission" do context "with a complete lettings log submission" do
let(:org_params) do
{
"lettings_log" => {
"owning_organisation_id" => owning_organisation.id,
"managing_organisation_id" => managing_organisation.id,
"assigned_to_id" => user.id,
},
}
end
let(:lettings_log_params) { JSON.parse(File.open("spec/fixtures/complete_lettings_log.json").read) }
let(:params) do let(:params) do
lettings_log_params.merge(org_params) { |_k, a_val, b_val| a_val.merge(b_val) } create(:lettings_log, :completed).attributes
end end
xit "marks the record as completed" do it "marks the record as completed" do
json_response = JSON.parse(response.body) json_response = JSON.parse(response.body)
expect(json_response).not_to have_key("errors") expect(json_response).not_to have_key("errors")
@ -1168,8 +1156,6 @@ RSpec.describe LettingsLogsController, type: :request do
let(:lettings_log) { create(:lettings_log, status: "not_started", assigned_to: user) } let(:lettings_log) { create(:lettings_log, status: "not_started", assigned_to: user) }
it "shows guidance link" do it "shows guidance link" do
allow(Time.zone).to receive(:now).and_return(lettings_log.form.edit_end_date - 1.day)
get lettings_log_path(lettings_log)
expect(lettings_log.status).to eq("not_started") expect(lettings_log.status).to eq("not_started")
expect(page).to have_content("Guidance for submitting social housing lettings and sales data (opens in a new tab)") expect(page).to have_content("Guidance for submitting social housing lettings and sales data (opens in a new tab)")
end end
@ -1287,9 +1273,9 @@ RSpec.describe LettingsLogsController, type: :request do
context "when accessing the check answers page" do context "when accessing the check answers page" do
before do before do
Timecop.freeze(2021, 4, 1) Timecop.freeze(previous_collection_start_date)
Singleton.__init__(FormHandler) 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.update!(startdate: previous_collection_start_date, voiddate: previous_collection_start_date, mrcdate: previous_collection_start_date)
Timecop.unfreeze Timecop.unfreeze
stub_request(:get, /api\.postcodes\.io/) stub_request(:get, /api\.postcodes\.io/)
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {})
@ -1298,6 +1284,7 @@ RSpec.describe LettingsLogsController, type: :request do
let(:postcode_lettings_log) do let(:postcode_lettings_log) do
FactoryBot.create(:lettings_log, FactoryBot.create(:lettings_log,
:setup_completed,
assigned_to: user, assigned_to: user,
postcode_known: "No") postcode_known: "No")
end end
@ -1306,6 +1293,7 @@ RSpec.describe LettingsLogsController, type: :request do
it "shows the inferred la" do it "shows the inferred la" do
lettings_log = FactoryBot.create(:lettings_log, lettings_log = FactoryBot.create(:lettings_log,
:setup_completed,
assigned_to: user, assigned_to: user,
postcode_known: 1, postcode_known: 1,
postcode_full: "PO5 3TE") postcode_full: "PO5 3TE")
@ -1315,21 +1303,6 @@ RSpec.describe LettingsLogsController, type: :request do
expect(CGI.unescape_html(response.body)).to include(expected_inferred_answer) expect(CGI.unescape_html(response.body)).to include(expected_inferred_answer)
end end
it "does not show do you know the property postcode question" do
get "/lettings-logs/#{id}/property-information/check-answers"
expect(CGI.unescape_html(response.body)).not_to include("Do you know the property postcode?")
end
it "shows if the postcode is not known" do
get "/lettings-logs/#{id}/property-information/check-answers"
expect(CGI.unescape_html(response.body)).to include("Not known")
end
it "shows link to answer question if the question wasn’t answered" do
get "/lettings-logs/#{id}/income-and-benefits/check-answers"
expect(page).to have_link("Enter income", href: "/lettings-logs/#{id}/net-income?referrer=check_answers_new_answer", class: "govuk-link govuk-link--no-visited-state")
end
it "does not allow you to change the answers for previous collection year logs" do it "does not allow you to change the answers for previous collection year logs" do
get "/lettings-logs/#{completed_lettings_log.id}/setup/check-answers", headers: { "Accept" => "text/html" }, params: {} get "/lettings-logs/#{completed_lettings_log.id}/setup/check-answers", headers: { "Accept" => "text/html" }, params: {}
expect(page).not_to have_link("Change") expect(page).not_to have_link("Change")

4
spec/services/bulk_upload/lettings/log_creator_spec.rb

@ -153,9 +153,5 @@ RSpec.describe BulkUpload::Lettings::LogCreator do
expect(log.retirement_value_check).to be(nil) expect(log.retirement_value_check).to be(nil)
end end
end end
context "when valid csv with existing log" do
xit "what should happen?"
end
end end
end end

2
spec/services/bulk_upload/lettings/year2025/row_parser_spec.rb

@ -259,7 +259,7 @@ RSpec.describe BulkUpload::Lettings::Year2025::RowParser do
expect(parser).to be_valid expect(parser).to be_valid
end end
xit "instantiates a log with everything completed", aggregate_failures: true do it "instantiates a log with everything completed", aggregate_failures: true do
parser.valid? parser.valid?
questions = parser.send(:questions).reject do |q| questions = parser.send(:questions).reject do |q|

4
spec/services/bulk_upload/sales/log_creator_spec.rb

@ -151,10 +151,6 @@ RSpec.describe BulkUpload::Sales::LogCreator do
end end
end end
context "when valid csv with existing log" do
xit "what should happen?"
end
context "with a valid csv and soft validations" do context "with a valid csv and soft validations" do
let(:log) do let(:log) do
build( build(

Loading…
Cancel
Save