Browse Source

CLDC-3499: Remove old tests from sales log spec

CLDC-3499-remove-pre-2025-tests
samyou-softwire 1 week ago
parent
commit
9778ef143e
  1. 52
      spec/models/sales_log_spec.rb

52
spec/models/sales_log_spec.rb

@ -96,17 +96,7 @@ RSpec.describe SalesLog, type: :model do
describe "#form" do describe "#form" do
let(:sales_log) { build(:sales_log, assigned_to: assigned_to_user) } let(:sales_log) { build(:sales_log, assigned_to: assigned_to_user) }
let(:sales_log_2) { build(:sales_log, saledate: Time.zone.local(2022, 5, 1), assigned_to: assigned_to_user) } let(:sales_log_2) { build(:sales_log, saledate: current_collection_start_date, assigned_to: assigned_to_user) }
before do
Timecop.freeze(Time.zone.local(2023, 1, 10))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
it "has returns the correct form based on the start date" do it "has returns the correct form based on the start date" do
expect(sales_log.form_name).to be_nil expect(sales_log.form_name).to be_nil
@ -120,12 +110,8 @@ RSpec.describe SalesLog, type: :model do
let(:completed_sales_log) { create(:sales_log, :completed) } let(:completed_sales_log) { create(:sales_log, :completed) }
context "when proplen is not given" do context "when proplen is not given" do
before do it "is set to in_progress for a log" do
allow(Time).to receive(:now).and_return(Time.zone.local(2023, 5, 1)) completed_sales_log.update!(proplen: nil, proplen_asked: 0)
end
it "is set to in_progress for a log with a saledate after 23/24" do
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.in_progress?).to be(true)
expect(completed_sales_log.not_started?).to be(false) expect(completed_sales_log.not_started?).to be(false)
expect(completed_sales_log.completed?).to be(false) expect(completed_sales_log.completed?).to be(false)
@ -204,27 +190,25 @@ RSpec.describe SalesLog, type: :model do
end end
context "when filtering by year or nil" do context "when filtering by year or nil" do
let(:previous_year) { previous_collection_start_year.to_s }
let(:current_year) { current_collection_start_year.to_s }
before do before do
create(:sales_log, :in_progress, saledate: nil) create(:sales_log, :in_progress, saledate: nil)
sales_log_2021 = build(:sales_log, :in_progress) create(:sales_log, :in_progress, saledate: previous_collection_start_date)
sales_log_2021.saledate = Time.zone.local(2021, 4, 1) create(:sales_log, :in_progress, saledate: current_collection_start_date)
sales_log_2021.save!(validate: false)
sales_log_3 = build(:sales_log, :in_progress)
sales_log_3.saledate = Time.zone.local(2022, 5, 1)
sales_log_3.save!(validate: false)
end end
it "allows filtering on a single year or nil" do it "allows filtering on a single year or nil" do
expect(described_class.filter_by_years_or_nil(%w[2021]).count).to eq(2) expect(described_class.filter_by_years_or_nil([previous_year]).count).to eq(2)
end end
it "allows filtering by multiple years or nil using OR" do it "allows filtering by multiple years or nil using OR" do
expect(described_class.filter_by_years_or_nil(%w[2021 2022]).count).to eq(3) expect(described_class.filter_by_years_or_nil([previous_year, current_year]).count).to eq(3)
end end
it "can filter by year(s) AND status" do it "can filter by year(s) AND status" do
expect(described_class.filter_by_years_or_nil(%w[2021 2022]).filter_by_status("in_progress").count).to eq(3) expect(described_class.filter_by_years_or_nil([previous_year, current_year]).filter_by_status("in_progress").count).to eq(3)
end end
end end
@ -277,17 +261,9 @@ RSpec.describe SalesLog, type: :model do
end end
end end
context "when there is a 2024 log with a different ecstat1" do context "when there is a log with a different ecstat1" do
let!(:different_ecstat1) { create(:sales_log, :duplicate, ecstat1: 0, owning_organisation: organisation) } let(:log) { create(:sales_log, :duplicate, staircase: 2, owning_organisation: organisation) }
let!(:different_ecstat1) { create(:sales_log, :duplicate, staircase: 2, ecstat1: 0, owning_organisation: organisation) }
before do
Timecop.freeze(Time.zone.local(2024, 5, 2))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
end
it "does not return a log with a different ecstat1 as a duplicate" do it "does not return a log with a different ecstat1 as a duplicate" do
expect(described_class.duplicate_logs(log)).not_to include(different_ecstat1) expect(described_class.duplicate_logs(log)).not_to include(different_ecstat1)

Loading…
Cancel
Save