From 0ecd82bf8f17c3a711559100bc54e55d027fe68a Mon Sep 17 00:00:00 2001 From: Arthur Campbell <51094020+arfacamble@users.noreply.github.com> Date: Fri, 28 Jun 2024 14:45:18 +0100 Subject: [PATCH] more tests fixed (#2491) --- spec/lib/tasks/clear_invalidated_earnings_spec.rb | 2 +- spec/models/bulk_upload_spec.rb | 10 +++++----- spec/models/form_handler_spec.rb | 2 +- .../validations/sales/household_validations_spec.rb | 2 +- spec/requests/form_controller_spec.rb | 11 ++++++----- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/spec/lib/tasks/clear_invalidated_earnings_spec.rb b/spec/lib/tasks/clear_invalidated_earnings_spec.rb index dfe9f951b..614a0e953 100644 --- a/spec/lib/tasks/clear_invalidated_earnings_spec.rb +++ b/spec/lib/tasks/clear_invalidated_earnings_spec.rb @@ -55,7 +55,7 @@ RSpec.describe "clear_invalidated_earnings" do lettings_log.earnings = 95 lettings_log.hhmemb = 1 lettings_log.ecstat1 = 1 - lettings_log.save! + lettings_log.save!(validate: false) end it "does not update the logs" do diff --git a/spec/models/bulk_upload_spec.rb b/spec/models/bulk_upload_spec.rb index 8f56a6b97..bad87d19d 100644 --- a/spec/models/bulk_upload_spec.rb +++ b/spec/models/bulk_upload_spec.rb @@ -13,7 +13,7 @@ RSpec.describe BulkUpload, type: :model do context "when there are no incomplete logs" do it "returns true" do - create_list(:lettings_log, 2, :completed, bulk_upload:, startdate: Time.zone.local(2024, 3, 3), voiddate: Time.zone.local(2024, 3, 3), mrcdate: Time.zone.local(2024, 3, 3)) + create_list(:lettings_log, 2, :completed, :startdate_today, bulk_upload:) expect(bulk_upload.completed?).to equal(true) end end @@ -21,18 +21,18 @@ RSpec.describe BulkUpload, type: :model do describe "value check clearing" do context "with a lettings log bulk upload" do - let(:log) { create(:lettings_log, bulk_upload:, startdate: Time.zone.local(2024, 3, 3)) } + let(:log) { create(:lettings_log, :startdate_today, bulk_upload:) } it "has the correct number of value checks to be set as confirmed" do - expect(bulk_upload.fields_to_confirm(log).sort).to eq(%w[rent_value_check void_date_value_check major_repairs_date_value_check pregnancy_value_check retirement_value_check referral_value_check net_income_value_check carehome_charges_value_check scharge_value_check pscharge_value_check supcharg_value_check].sort) + expect(bulk_upload.fields_to_confirm(log)).to match_array %w[rent_value_check void_date_value_check major_repairs_date_value_check pregnancy_value_check retirement_value_check referral_value_check net_income_value_check carehome_charges_value_check scharge_value_check pscharge_value_check supcharg_value_check address_search_value_check multiple_partners_value_check partner_under_16_value_check reasonother_value_check] end end context "with a sales log bulk upload" do - let(:log) { create(:sales_log, bulk_upload:, saledate: Time.zone.local(2024, 3, 3)) } + let(:log) { create(:sales_log, :saledate_today, bulk_upload:) } it "has the correct number of value checks to be set as confirmed" do - expect(bulk_upload.fields_to_confirm(log).sort).to eq(%w[value_value_check monthly_charges_value_check percentage_discount_value_check income1_value_check income2_value_check combined_income_value_check retirement_value_check old_persons_shared_ownership_value_check buyer_livein_value_check student_not_child_value_check wheel_value_check mortgage_value_check savings_value_check deposit_value_check staircase_bought_value_check stairowned_value_check hodate_check shared_ownership_deposit_value_check extrabor_value_check grant_value_check discounted_sale_value_check deposit_and_mortgage_value_check].sort) + expect(bulk_upload.fields_to_confirm(log)).to match_array %w[value_value_check monthly_charges_value_check percentage_discount_value_check income1_value_check income2_value_check combined_income_value_check retirement_value_check old_persons_shared_ownership_value_check buyer_livein_value_check student_not_child_value_check wheel_value_check mortgage_value_check savings_value_check deposit_value_check staircase_bought_value_check stairowned_value_check hodate_check shared_ownership_deposit_value_check extrabor_value_check grant_value_check discounted_sale_value_check deposit_and_mortgage_value_check address_search_value_check multiple_partners_value_check partner_under_16_value_check] end end end diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index b642a9056..3747cf92d 100644 --- a/spec/models/form_handler_spec.rb +++ b/spec/models/form_handler_spec.rb @@ -246,7 +246,7 @@ RSpec.describe FormHandler do end end - context "when only archived form form is defined in JSON (current collection start year 2024 onwards)" do + context "when only archived form form is defined in JSON (current collection start year 2024 onwards)" do # TODO: CLDC-3505 remove this test on year hard end let(:now) { Time.utc(2024, 9, 20) } it "creates previous_lettings, current_lettings and next_lettings forms from ruby form objects and archived form from json" do diff --git a/spec/models/validations/sales/household_validations_spec.rb b/spec/models/validations/sales/household_validations_spec.rb index c12d7c5b3..12135c585 100644 --- a/spec/models/validations/sales/household_validations_spec.rb +++ b/spec/models/validations/sales/household_validations_spec.rb @@ -278,7 +278,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do end describe "validating fields about buyers living in the property" do - let(:sales_log) { FactoryBot.create(:sales_log, :outright_sale_setup_complete, saledate:, noint: 1, companybuy: 2, buylivein:, jointpur:, jointmore:, buy1livein:) } + let(:sales_log) { build(:sales_log, :outright_sale_setup_complete, saledate:, noint: 1, companybuy: 2, buylivein:, jointpur:, jointmore:, buy1livein:) } context "when buyers will live in the property and the sale is a joint purchase" do let(:buylivein) { 1 } diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index 05604ae64..575058d6d 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -499,6 +499,7 @@ RSpec.describe FormController, type: :request do end it "renders the review page for the sales log" do + Timecop.return # TODO: CLDC-3289 this can be removed when the Timecop freezing at the top of the describe GET is removed log = create(:sales_log, :completed, assigned_to: user) get "/sales-logs/#{log.id}/review", headers: headers, params: { sales_log: true } expect(response.body).to match("Review sales log") @@ -872,7 +873,7 @@ RSpec.describe FormController, type: :request do end before do - lettings_log.update!(startdate: Time.zone.local(2023, 4, 1)) + lettings_log.update!(startdate: Time.zone.today) post "/lettings-logs/#{lettings_log.id}/lead-tenant-age?referrer=interruption_screen", params: end @@ -884,7 +885,7 @@ RSpec.describe FormController, type: :request do follow_redirect! follow_redirect! - expect(response.body).to include("You have successfully updated Q32: lead tenant’s age") + expect(response.body).to include("You have successfully updated Q31: lead tenant’s age") end end @@ -1015,7 +1016,7 @@ RSpec.describe FormController, type: :request do end end - context "when the sale date changes from 2024 to 2023" do + context "when the sale date changes from 2024 to 2023" do # TODO: CLDC-3505 remove this test on year hard end let(:sales_log) { create(:sales_log, owning_organisation: organisation, managing_organisation:, assigned_to: user) } let(:params) do { @@ -1156,8 +1157,8 @@ RSpec.describe FormController, type: :request do end context "when the sales question was accessed from a duplicate logs screen" do - let!(:sales_log) { create(:sales_log, :duplicate, assigned_to: user, duplicate_set_id: 1, saledate: Time.zone.local(2024, 3, 3)) } - let!(:duplicate_log) { create(:sales_log, :duplicate, assigned_to: user, duplicate_set_id: 1, saledate: Time.zone.local(2024, 3, 3)) } + let!(:sales_log) { create(:sales_log, :duplicate, :saledate_today, assigned_to: user, duplicate_set_id: 1) } + let!(:duplicate_log) { create(:sales_log, :duplicate, :saledate_today, assigned_to: user, duplicate_set_id: 1) } let(:referrer) { "/sales-logs/#{sales_log.id}/buyer-1-age?referrer=duplicate_logs&first_remaining_duplicate_id=#{duplicate_log.id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs" } let(:params) do {