Browse Source

Update bulk upload year_spec tests

pull/2279/head
Rachael Booth 2 years ago
parent
commit
535e0de72c
  1. 47
      spec/models/forms/bulk_upload_lettings/year_spec.rb
  2. 49
      spec/models/forms/bulk_upload_sales/year_spec.rb

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

@ -4,9 +4,50 @@ RSpec.describe Forms::BulkUploadLettings::Year do
subject(:form) { described_class.new }
describe "#options" do
it "returns correct years" do
expect(form.options.map(&:id)).to eql([2023, 2022])
expect(form.options.map(&:name)).to eql(%w[2023/2024 2022/2023])
context "when in a crossover period" do
before do
Timecop.freeze(2024, 4, 1)
end
after do
Timecop.return
end
it "returns current and previous years" do
expect(form.options.map(&:id)).to eql([2024, 2023])
expect(form.options.map(&:name)).to eql(%w[2024/2025 2023/2024])
end
end
context "when not in a crossover period" do
before do
Timecop.freeze(2024, 3, 1)
end
after do
Timecop.return
end
it "returns the current year" do
expect(form.options.map(&:id)).to eql([2023])
expect(form.options.map(&:name)).to eql(%w[2023/2024])
end
end
context "when allow_future_form_use is toggled on" do
before do
Timecop.freeze(2024, 3, 1)
allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true)
end
after do
Timecop.return
end
it "returns current and next years" do
expect(form.options.map(&:id)).to eql([2023, 2024])
expect(form.options.map(&:name)).to eql(%w[2023/2024 2024/2025])
end
end
end
end

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

@ -3,16 +3,51 @@ require "rails_helper"
RSpec.describe Forms::BulkUploadSales::Year do
subject(:form) { described_class.new }
around do |example|
Timecop.freeze(Time.zone.now) do
example.run
describe "#options" do
context "when in a crossover period" do
before do
Timecop.freeze(2024, 4, 1)
end
after do
Timecop.return
end
describe "#options" do
it "returns correct years" do
expect(form.options.map(&:id)).to eql([2023, 2022])
expect(form.options.map(&:name)).to eql(%w[2023/2024 2022/2023])
it "returns current and previous years" do
expect(form.options.map(&:id)).to eql([2024, 2023])
expect(form.options.map(&:name)).to eql(%w[2024/2025 2023/2024])
end
end
context "when not in a crossover period" do
before do
Timecop.freeze(2024, 3, 1)
end
after do
Timecop.return
end
it "returns the current year" do
expect(form.options.map(&:id)).to eql([2023])
expect(form.options.map(&:name)).to eql(%w[2023/2024])
end
end
context "when allow_future_form_use is toggled on" do
before do
Timecop.freeze(2024, 3, 1)
allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true)
end
after do
Timecop.return
end
it "returns current and next years" do
expect(form.options.map(&:id)).to eql([2023, 2024])
expect(form.options.map(&:name)).to eql(%w[2023/2024 2024/2025])
end
end
end
end

Loading…
Cancel
Save