diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb index 905298e5e..fbb4f5c96 100644 --- a/spec/factories/sales_log.rb +++ b/spec/factories/sales_log.rb @@ -2,14 +2,14 @@ FactoryBot.define do factory :sales_log do created_by { FactoryBot.create(:user) } owning_organisation { created_by.organisation } - created_at { Time.utc(2023, 2, 8, 16, 52, 15) } - updated_at { Time.utc(2023, 2, 8, 16, 52, 15) } + created_at { Time.zone.now } + updated_at { Time.zone.now } trait :in_progress do purchid { "PC123" } ownershipsch { 2 } type { 8 } jointpur { 2 } - saledate { Time.utc(2023, 2, 2, 10, 36, 49) } + saledate { Time.zone.today } end trait :shared_ownership do ownershipsch { 1 } @@ -39,7 +39,7 @@ FactoryBot.define do purchid { rand(999_999_999).to_s } ownershipsch { 2 } type { 8 } - saledate { Time.utc(2023, 2, 2, 10, 36, 49) } + saledate { Time.zone.today } jointpur { 1 } beds { 2 } jointmore { 1 } @@ -81,6 +81,9 @@ FactoryBot.define do income2nk { 0 } income2 { 10_000 } inc2mort { 1 } + uprn_known { 0 } + address_line1 { "Address line 1" } + town_or_city { "Town or city" } la_known { 1 } la { "E09000003" } savingsnk { 1 } @@ -125,9 +128,14 @@ FactoryBot.define do is_la_inferred { false } mortgagelender { 5 } extrabor { 1 } + ethnic_group2 { 17 } + nationalbuy2 { 13 } + buy2living { 3 } + proplen_asked { 1 } end trait :with_uprn do uprn { rand(999_999_999_999).to_s } + uprn_known { 1 } end trait :deleted do status { 4 } diff --git a/spec/features/sales_log_spec.rb b/spec/features/sales_log_spec.rb index 990b62096..8093f85dd 100644 --- a/spec/features/sales_log_spec.rb +++ b/spec/features/sales_log_spec.rb @@ -38,16 +38,16 @@ RSpec.describe "Sales Log Features" do visit("/sales-logs") click_button("Create a new sales log") click_link("Set up this sales log") - fill_in("sales_log[saledate(1i)]", with: "2022") - fill_in("sales_log[saledate(2i)]", with: "08") - fill_in("sales_log[saledate(3i)]", with: "10") + fill_in("sales_log[saledate(1i)]", with: Time.zone.today.year) + fill_in("sales_log[saledate(2i)]", with: Time.zone.today.month) + fill_in("sales_log[saledate(3i)]", with: Time.zone.today.day) click_button("Save and continue") fill_in("sales_log[purchid]", with: "PC123") click_button("Save and continue") log_id = page.current_path.scan(/\d/).join visit("sales-logs/#{log_id}/setup/check-answers") expect(page).to have_content("Sale completion date") - expect(page).to have_content("2022") + expect(page).to have_content(Time.zone.today.year) expect(page).to have_content("Purchaser code") expect(page).to have_content("PC123") end diff --git a/spec/fixtures/files/sales_logs_csv_export_codes.csv b/spec/fixtures/files/sales_logs_csv_export_codes.csv index 81dcfb2a9..31d964afe 100644 --- a/spec/fixtures/files/sales_logs_csv_export_codes.csv +++ b/spec/fixtures/files/sales_logs_csv_export_codes.csv @@ -1,2 +1,2 @@ id,status,created_at,updated_at,old_id,collection_start_year,creation_method,is_dpo,owning_organisation_name,created_by_name,day,month,year,purchid,ownershipsch,type,othtype,companybuy,buylivein,jointpur,jointmore,beds,proptype,builtype,pcodenk,uprn,uprn_confirmed,address_line1,address_line2,town_or_city,county,pcode1,pcode2,la_known,la,la_label,wchair,noint,privacynotice,age1,sex1,ethnic_group,ethnic,national,ecstat1,buy1livein,relat2,age2,sex2,ethnic_group2,ethnicbuy2,nationalbuy2,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 -,completed,2023-02-08T16:52:15+00:00,2023-02-08T16:52:15+00:00,,2022,single log,false,DLUHC,Danny Rojas,2,2,2023,,2,8,,,,1,1,2,1,1,0,,,,,,,SW1A,1AA,1,E09000003,Barnet,1,2,1,30,X,17,17,18,1,1,P,35,X,,,,1,1,6,C,14,X,9,X,18,X,3,R,40,X,2,R,40,X,1,1,1,,,0,,,1,1,1,1,,,,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,2023-02-08T00:00:00+00:00,2023-02-08T00:00:00+00:00,,2022,single log,false,DLUHC,Danny Rojas,8,2,2023,,2,8,,,,1,1,2,1,1,0,,,Address line 1,,Town or city,,SW1A,1AA,1,E09000003,Barnet,1,2,1,30,X,17,17,18,1,1,P,35,X,17,,13,1,1,6,C,14,X,9,X,18,X,3,R,40,X,2,R,40,X,1,1,1,,,0,,,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 diff --git a/spec/fixtures/files/sales_logs_csv_export_labels.csv b/spec/fixtures/files/sales_logs_csv_export_labels.csv index 0c81ab389..aeda373f3 100644 --- a/spec/fixtures/files/sales_logs_csv_export_labels.csv +++ b/spec/fixtures/files/sales_logs_csv_export_labels.csv @@ -1,2 +1,2 @@ id,status,created_at,updated_at,old_id,collection_start_year,creation_method,is_dpo,owning_organisation_name,created_by_name,day,month,year,purchid,ownershipsch,type,othtype,companybuy,buylivein,jointpur,jointmore,beds,proptype,builtype,pcodenk,uprn,uprn_confirmed,address_line1,address_line2,town_or_city,county,pcode1,pcode2,la_known,la,la_label,wchair,noint,privacynotice,age1,sex1,ethnic_group,ethnic,national,ecstat1,buy1livein,relat2,age2,sex2,ethnic_group2,ethnicbuy2,nationalbuy2,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 -,completed,2023-02-08T16:52:15+00:00,2023-02-08T16:52:15+00:00,,2022,single log,false,DLUHC,Danny Rojas,2,2,2023,,Yes - a discounted ownership scheme,Right to Acquire (RTA),,,,Yes,Yes,2,Flat or maisonette,Purpose built,Yes,,,,,,,SW1A,1AA,Yes,E09000003,Barnet,Yes,Yes,1,30,Non-binary,Buyer 1 prefers not to say,17,United Kingdom,Full-time - 30 hours or more,Yes,Partner,35,Non-binary,,,,Full-time - 30 hours or more,Yes,6,Child,14,Non-binary,Child under 16,Other,18,Non-binary,"In government training into work, such as New Deal",Person prefers not to say,40,Non-binary,Part-time - Less than 30 hours,Person prefers not to say,40,Non-binary,Full-time - 30 hours or more,Local authority tenant,No,,,No,,,1,1,1,1,,,,Yes,Yes,No,Yes,Yes,Yes,10000,Yes,Yes,10000,Yes,Don’t know ,No,,Yes,2,10,,,,,,,,,,,,,,,,,110000.0,,Yes,20000.0,Cambridge Building Society,,10,Yes,80000.0,,,Yes,100.0,,10000.0 +,completed,2023-02-08T00:00:00+00:00,2023-02-08T00:00:00+00:00,,2022,single log,false,DLUHC,Danny Rojas,8,2,2023,,Yes - a discounted ownership scheme,Right to Acquire (RTA),,,,Yes,Yes,2,Flat or maisonette,Purpose built,Yes,,,Address line 1,,Town or city,,SW1A,1AA,Yes,E09000003,Barnet,Yes,Yes,1,30,Non-binary,Buyer 1 prefers not to say,17,United Kingdom,Full-time - 30 hours or more,Yes,Partner,35,Non-binary,17,,13,Full-time - 30 hours or more,Yes,6,Child,14,Non-binary,Child under 16,Other,18,Non-binary,"In government training into work, such as New Deal",Person prefers not to say,40,Non-binary,Part-time - Less than 30 hours,Person prefers not to say,40,Non-binary,Full-time - 30 hours or more,Local authority tenant,No,,,No,,,1,1,1,1,,3,,Yes,Yes,No,Yes,Yes,Yes,10000,Yes,Yes,10000,Yes,Don’t know ,No,,Yes,2,10,,,,,,,,,,,,,,,,,110000.0,,Yes,20000.0,Cambridge Building Society,,10,Yes,80000.0,,,Yes,100.0,,10000.0 diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb index 5a13c9009..f2337b84d 100644 --- a/spec/models/sales_log_spec.rb +++ b/spec/models/sales_log_spec.rb @@ -125,7 +125,7 @@ RSpec.describe SalesLog, type: :model do end it "is set to completed for a log with a saledate before 23/24" do - completed_sales_log.update!(proplen: nil, saledate: Time.zone.local(2022, 5, 1)) + completed_sales_log.update!(proplen: nil, proplen_asked: 0, saledate: Time.zone.local(2022, 5, 1)) expect(completed_sales_log.in_progress?).to be(false) expect(completed_sales_log.not_started?).to be(false) expect(completed_sales_log.completed?).to be(true) @@ -133,7 +133,7 @@ RSpec.describe SalesLog, type: :model do end it "is set to in_progress for a log with a saledate after 23/24" do - completed_sales_log.update!(proplen: nil, saledate: Time.zone.local(2023, 5, 1)) + completed_sales_log.update!(proplen: nil, proplen_asked: 0, saledate: Time.zone.local(2023, 5, 1)) expect(completed_sales_log.in_progress?).to be(true) expect(completed_sales_log.not_started?).to be(false) expect(completed_sales_log.completed?).to be(false) @@ -163,6 +163,13 @@ RSpec.describe SalesLog, type: :model do describe "derived variables" do let(:sales_log) { create(:sales_log, :completed) } + around do |example| + Timecop.freeze(Time.zone.local(2022, 7, 4)) do + example.run + end + Timecop.return + end + it "correctly derives and saves exday, exmonth and exyear" do sales_log.update!(exdate: Time.gm(2022, 5, 4), saledate: Time.gm(2022, 7, 4), ownershipsch: 1, type: 18, staircase: 2, resale: 2, proplen: 0) record_from_db = described_class.find(sales_log.id) diff --git a/spec/requests/sales_logs_controller_spec.rb b/spec/requests/sales_logs_controller_spec.rb index cc7df60e3..30d756356 100644 --- a/spec/requests/sales_logs_controller_spec.rb +++ b/spec/requests/sales_logs_controller_spec.rb @@ -65,7 +65,7 @@ RSpec.describe SalesLogsController, type: :request do context "with a request containing invalid json parameters" do let(:params) do { - "saledate": Date.new(2022, 4, 1), + "saledate": Time.zone.today, "purchid": "1", "ownershipsch": 1, "type": 2, @@ -236,17 +236,35 @@ RSpec.describe SalesLogsController, type: :request do end context "with year filter" do + around do |example| + Timecop.freeze(2022, 12, 1) do + example.run + end + Timecop.return + end + + before do + Timecop.freeze(2022, 4, 1) + sales_log_2022.update!(saledate: Time.zone.local(2022, 4, 1)) + Timecop.freeze(2023, 1, 1) + sales_log_2022.update!(saledate: Time.zone.local(2023, 1, 1)) + end + + after do + Timecop.unfreeze + end + let!(:sales_log_2022) do - FactoryBot.create(:sales_log, :in_progress, + FactoryBot.create(:sales_log, :completed, owning_organisation: organisation, - saledate: Time.zone.local(2022, 4, 1)) + created_by: user, + saledate: Time.zone.today) end let!(:sales_log_2023) do - sales_log = FactoryBot.build(:sales_log, :completed, - owning_organisation: organisation, - saledate: Time.zone.local(2023, 1, 1)) - sales_log.save!(validate: false) - sales_log + FactoryBot.create(:sales_log, + owning_organisation: organisation, + created_by: user, + saledate: Time.zone.today) end it "shows sales logs for multiple selected years" do diff --git a/spec/services/bulk_upload/lettings/validator_spec.rb b/spec/services/bulk_upload/lettings/validator_spec.rb index 41d42b25f..27d018229 100644 --- a/spec/services/bulk_upload/lettings/validator_spec.rb +++ b/spec/services/bulk_upload/lettings/validator_spec.rb @@ -387,6 +387,13 @@ RSpec.describe BulkUpload::Lettings::Validator do let(:log_1) { build(:lettings_log, :completed, renttype: 1, created_by: user) } let(:log_2) { build(:lettings_log, :completed, renttype: 1, created_by: user) } + around do |example| + Timecop.freeze(Time.zone.local(2023, 2, 22)) do + example.run + end + Timecop.return + end + before do file.write(BulkUpload::LettingsLogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_csv_row) file.write(BulkUpload::LettingsLogToCsv.new(log: log_2, line_ending: "\r\n", col_offset: 0).to_2022_csv_row) diff --git a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb index bac02dde6..05120713d 100644 --- a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb @@ -13,7 +13,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do let(:managing_org) { create(:organisation, :with_old_visible_id) } let(:scheme) { create(:scheme, :with_old_visible_id, owning_organisation: owning_org) } let(:location) { create(:location, :with_old_visible_id, scheme:) } - let(:mock_interrupion_ids) {} + let(:mock_interruption_ids) {} let(:setup_section_params) do { @@ -148,7 +148,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do end before do - mock_interrupion_ids + mock_interruption_ids create(:organisation_relationship, parent_organisation: owning_org, child_organisation: managing_org) end @@ -993,7 +993,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do context "when soft validation is triggered and the mappings for errors are not defined" do let(:attributes) { setup_section_params.merge({ field_12: 22, field_35: 5 }) } # rubocop:disable RSpec/AnyInstance - let(:mock_interrupion_ids) { allow_any_instance_of(Form::Page).to receive(:interruption_screen_question_ids).and_return(%w[fake_question_id]) } + let(:mock_interruption_ids) { allow_any_instance_of(Form::Page).to receive(:interruption_screen_question_ids).and_return(%w[fake_question_id]) } # rubocop:enable RSpec/AnyInstance it "does not crash" do diff --git a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb index 0c885f11d..8586a470c 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -6,7 +6,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do let(:now) { Time.zone.now.beginning_of_day } let(:attributes) { { bulk_upload: } } - let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: nil) } + let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: nil, year: 2023) } let(:user) { create(:user, organisation: owning_org) } let(:owning_org) { create(:organisation, :with_old_visible_id) } diff --git a/spec/services/bulk_upload/sales/log_creator_spec.rb b/spec/services/bulk_upload/sales/log_creator_spec.rb index 14a363a4c..7e0082311 100644 --- a/spec/services/bulk_upload/sales/log_creator_spec.rb +++ b/spec/services/bulk_upload/sales/log_creator_spec.rb @@ -10,6 +10,15 @@ RSpec.describe BulkUpload::Sales::LogCreator do let(:path) { file_fixture("completed_2022_23_sales_bulk_upload.csv") } describe "#call" do + around do |example| + Timecop.freeze(Time.zone.local(2023, 2, 22)) do + Singleton.__init__(FormHandler) + example.run + end + Timecop.return + Singleton.__init__(FormHandler) + end + context "when a valid csv with new log" do it "creates a new log" do expect { service.call }.to change(SalesLog, :count) diff --git a/spec/services/bulk_upload/sales/validator_spec.rb b/spec/services/bulk_upload/sales/validator_spec.rb index 79362b8e9..851109772 100644 --- a/spec/services/bulk_upload/sales/validator_spec.rb +++ b/spec/services/bulk_upload/sales/validator_spec.rb @@ -61,10 +61,15 @@ RSpec.describe BulkUpload::Sales::Validator do let(:path) { file.path } before do + Timecop.freeze(Time.utc(2022, 6, 3)) file.write(BulkUpload::SalesLogToCsv.new(log:, line_ending: "\r\n", col_offset: 0).to_2022_csv_row) file.close end + after do + Timecop.unfreeze + end + it "is not valid" do expect(validator).not_to be_valid end @@ -144,6 +149,15 @@ RSpec.describe BulkUpload::Sales::Validator do end describe "#create_logs?" do + around do |example| + Timecop.freeze(Time.zone.local(2023, 2, 22)) do + Singleton.__init__(FormHandler) + example.run + end + Timecop.return + Singleton.__init__(FormHandler) + end + context "when all logs are valid" do let(:target_path) { file_fixture("completed_2022_23_sales_bulk_upload.csv") } diff --git a/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb index dae343c49..9da1fbe79 100644 --- a/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb @@ -107,6 +107,15 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do } end + around do |example| + Timecop.freeze(Time.zone.local(2023, 2, 22)) do + Singleton.__init__(FormHandler) + example.run + end + Timecop.return + Singleton.__init__(FormHandler) + end + describe "#blank_row?" do context "when a new object" do it "returns true" do @@ -200,6 +209,13 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do context "when valid row" do let(:attributes) { valid_attributes } + around do |example| + Timecop.freeze(Date.new(2023, 2, 22)) do + example.run + end + Timecop.return + end + it "returns true" do expect(parser).to be_valid end diff --git a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb index 0f23dfbc0..545efd0f5 100644 --- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb @@ -6,11 +6,9 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do let(:now) { Time.zone.parse("01/03/2023") } let(:attributes) { { bulk_upload: } } - let(:bulk_upload) { create(:bulk_upload, :sales, user:) } + let(:bulk_upload) { create(:bulk_upload, :sales, user:, year: 2023) } let(:user) { create(:user, organisation: owning_org) } - let(:owning_org) { create(:organisation, :with_old_visible_id) } - let(:setup_section_params) do { bulk_upload:, @@ -26,7 +24,6 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do field_14: "2", # joint purchase } end - let(:valid_attributes) do { bulk_upload:, @@ -34,7 +31,7 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do field_1: owning_org.old_visible_id, field_3: "22", field_4: "2", - field_5: "23", + field_5: "24", field_6: "test id", field_7: "1", field_8: "2", @@ -60,6 +57,8 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do field_37: "R", field_38: "32", field_39: "F", + field_40: "17", + field_41: "13", field_43: "2", field_44: "1", field_45: "0", @@ -70,6 +69,7 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do field_66: "E09000008", field_69: "1", field_70: "1", + field_71: "3", field_73: "3", field_75: "5", field_76: "3", @@ -85,11 +85,11 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do field_87: "1", field_88: "10", field_89: "10", - field_91: "2", + field_90: "1", field_92: "30", field_93: "3", field_94: "22", - field_95: "23", + field_95: "24", field_96: "3", field_97: "22", field_98: "3", @@ -110,6 +110,15 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do } end + around do |example| + Timecop.freeze(Time.zone.local(2024, 2, 22)) do + Singleton.__init__(FormHandler) + example.run + end + Timecop.return + Singleton.__init__(FormHandler) + end + describe "#blank_row?" do context "when a new object" do it "returns true" do diff --git a/spec/services/csv/sales_log_csv_service_spec.rb b/spec/services/csv/sales_log_csv_service_spec.rb index 358e1d40a..2c24bf7b1 100644 --- a/spec/services/csv/sales_log_csv_service_spec.rb +++ b/spec/services/csv/sales_log_csv_service_spec.rb @@ -7,6 +7,15 @@ RSpec.describe Csv::SalesLogCsvService do let(:service) { described_class.new(export_type: "labels") } let(:csv) { CSV.parse(service.prepare_csv(SalesLog.all)) } + around do |example| + Timecop.freeze(Time.utc(2023, 2, 8)) do + Singleton.__init__(FormHandler) + example.run + end + Timecop.return + Singleton.__init__(FormHandler) + end + it "calls the form handler to get all questions in order when initialized" do allow(FormHandler).to receive(:instance).and_return(form_handler_mock) allow(form_handler_mock).to receive(:ordered_sales_questions_for_all_years).and_return([]) diff --git a/spec/services/imports/sales_logs_import_service_spec.rb b/spec/services/imports/sales_logs_import_service_spec.rb index 52ea5f59b..295d727e8 100644 --- a/spec/services/imports/sales_logs_import_service_spec.rb +++ b/spec/services/imports/sales_logs_import_service_spec.rb @@ -16,6 +16,15 @@ RSpec.describe Imports::SalesLogsImportService do File.open("#{directory}/#{filename}.xml") end + around do |example| + Timecop.freeze(Time.zone.local(2023, 2, 1)) do + Singleton.__init__(FormHandler) + example.run + end + Timecop.return + Singleton.__init__(FormHandler) + end + before do allow(Organisation).to receive(:find_by).and_return(nil) allow(Organisation).to receive(:find_by).with(old_visible_id: organisation.old_visible_id).and_return(organisation)