Browse Source

Udate model/forms tests

pull/2432/head
Kat 2 years ago
parent
commit
d022d99f8f
  1. 30
      spec/models/forms/bulk_upload_lettings/year_spec.rb
  2. 26
      spec/models/forms/bulk_upload_sales/year_spec.rb

30
spec/models/forms/bulk_upload_lettings/year_spec.rb

@ -4,13 +4,15 @@ RSpec.describe Forms::BulkUploadLettings::Year do
subject(:form) { described_class.new } subject(:form) { described_class.new }
describe "#options" do describe "#options" do
context "when in a crossover period" do
before do before do
Timecop.freeze(2024, 4, 1) allow(FormHandler.instance).to receive(:lettings_forms).and_return({ "current_lettings" => instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) })
allow(FormHandler.instance).to receive(:previous_lettings_form).and_return(instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))
allow(FormHandler.instance).to receive(:next_lettings_form).and_return(instance_double(Form, start_date: Time.zone.local(2025, 4, 1)))
end end
after do context "when in a crossover period" do
Timecop.return before do
allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(true)
end end
it "returns current and previous years" do it "returns current and previous years" do
@ -21,32 +23,24 @@ RSpec.describe Forms::BulkUploadLettings::Year do
context "when not in a crossover period" do context "when not in a crossover period" do
before do before do
Timecop.freeze(2024, 3, 1) allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(false)
end
after do
Timecop.return
end end
it "returns the current year" do it "returns the current year" do
expect(form.options.map(&:id)).to eql([2023]) expect(form.options.map(&:id)).to eql([2024])
expect(form.options.map(&:name)).to eql(%w[2023/2024]) expect(form.options.map(&:name)).to eql(%w[2024/2025])
end end
end end
context "when allow_future_form_use is toggled on" do context "when allow_future_form_use is toggled on" do
before do before do
Timecop.freeze(2024, 3, 1) allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(false)
allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true) allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true)
end end
after do
Timecop.return
end
it "returns current and next years" do it "returns current and next years" do
expect(form.options.map(&:id)).to eql([2023, 2024]) expect(form.options.map(&:id)).to eql([2024, 2025])
expect(form.options.map(&:name)).to eql(%w[2023/2024 2024/2025]) expect(form.options.map(&:name)).to eql(%w[2024/2025 2025/2026])
end end
end end
end end

26
spec/models/forms/bulk_upload_sales/year_spec.rb

@ -4,13 +4,15 @@ RSpec.describe Forms::BulkUploadSales::Year do
subject(:form) { described_class.new } subject(:form) { described_class.new }
describe "#options" do describe "#options" do
context "when in a crossover period" do
before do before do
Timecop.freeze(2024, 4, 1) allow(FormHandler.instance).to receive(:sales_forms).and_return({ "current_sales" => instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) })
allow(FormHandler.instance).to receive(:previous_sales_form).and_return(instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))
allow(FormHandler.instance).to receive(:next_sales_form).and_return(instance_double(Form, start_date: Time.zone.local(2025, 4, 1)))
end end
after do context "when in a crossover period" do
Timecop.return before do
allow(FormHandler.instance).to receive(:sales_in_crossover_period?).and_return(true)
end end
it "returns current and previous years" do it "returns current and previous years" do
@ -21,22 +23,18 @@ RSpec.describe Forms::BulkUploadSales::Year do
context "when not in a crossover period" do context "when not in a crossover period" do
before do before do
Timecop.freeze(2024, 3, 1) allow(FormHandler.instance).to receive(:sales_in_crossover_period?).and_return(false)
end
after do
Timecop.return
end end
it "returns the current year" do it "returns the current year" do
expect(form.options.map(&:id)).to eql([2023]) expect(form.options.map(&:id)).to eql([2024])
expect(form.options.map(&:name)).to eql(%w[2023/2024]) expect(form.options.map(&:name)).to eql(%w[2024/2025])
end end
end end
context "when allow_future_form_use is toggled on" do context "when allow_future_form_use is toggled on" do
before do before do
Timecop.freeze(2024, 3, 1) allow(FormHandler.instance).to receive(:sales_in_crossover_period?).and_return(false)
allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true) allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true)
end end
@ -45,8 +43,8 @@ RSpec.describe Forms::BulkUploadSales::Year do
end end
it "returns current and next years" do it "returns current and next years" do
expect(form.options.map(&:id)).to eql([2023, 2024]) expect(form.options.map(&:id)).to eql([2024, 2025])
expect(form.options.map(&:name)).to eql(%w[2023/2024 2024/2025]) expect(form.options.map(&:name)).to eql(%w[2024/2025 2025/2026])
end end
end end
end end

Loading…
Cancel
Save