|
|
|
@ -6,17 +6,19 @@ RSpec.describe SalesLog, type: :model do |
|
|
|
let(:owning_organisation) { create(:organisation) } |
|
|
|
let(:owning_organisation) { create(:organisation) } |
|
|
|
let(:assigned_to_user) { create(:user) } |
|
|
|
let(:assigned_to_user) { create(:user) } |
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
context "with shared examples" do |
|
|
|
Timecop.freeze(Time.zone.local(2024, 3, 1)) |
|
|
|
before do |
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
Timecop.freeze(Time.zone.local(2024, 3, 1)) |
|
|
|
end |
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
after do |
|
|
|
Timecop.return |
|
|
|
Timecop.return |
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
include_examples "shared log examples", :sales_log |
|
|
|
include_examples "shared log examples", :sales_log |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "inherits from log" do |
|
|
|
it "inherits from log" do |
|
|
|
expect(described_class).to be < Log |
|
|
|
expect(described_class).to be < Log |
|
|
|
@ -143,11 +145,7 @@ RSpec.describe SalesLog, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
context "when proplen is not given" do |
|
|
|
context "when proplen is not given" do |
|
|
|
before do |
|
|
|
before do |
|
|
|
Timecop.freeze(Time.zone.local(2023, 5, 1)) |
|
|
|
allow(Time).to receive(:now).and_return(Time.zone.local(2023, 5, 1)) |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "is set to completed for a log with a saledate before 23/24" do |
|
|
|
it "is set to completed for a log with a saledate before 23/24" do |
|
|
|
@ -232,18 +230,16 @@ RSpec.describe SalesLog, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
context "when filtering by year or nil" do |
|
|
|
context "when filtering by year or nil" do |
|
|
|
before do |
|
|
|
before do |
|
|
|
Timecop.freeze(Time.utc(2021, 5, 3)) |
|
|
|
|
|
|
|
create(:sales_log, :in_progress, saledate: nil) |
|
|
|
create(:sales_log, :in_progress, saledate: nil) |
|
|
|
create(:sales_log, :in_progress, saledate: Time.zone.local(2021, 4, 1)) |
|
|
|
sales_log_2021 = build(:sales_log, :in_progress) |
|
|
|
sales_log_3 = create(:sales_log, :in_progress) |
|
|
|
sales_log_2021.saledate = Time.zone.local(2021, 4, 1) |
|
|
|
|
|
|
|
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.saledate = Time.zone.local(2022, 5, 1) |
|
|
|
sales_log_3.save!(validate: false) |
|
|
|
sales_log_3.save!(validate: false) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
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(%w[2021]).count).to eq(2) |
|
|
|
end |
|
|
|
end |
|
|
|
@ -580,36 +576,6 @@ RSpec.describe SalesLog, type: :model do |
|
|
|
expect(record_from_db["la"]).to eq("E08000003") |
|
|
|
expect(record_from_db["la"]).to eq("E08000003") |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "with 22/23 logs" do |
|
|
|
|
|
|
|
let(:address_sales_log_22_23) do |
|
|
|
|
|
|
|
described_class.create({ |
|
|
|
|
|
|
|
owning_organisation:, |
|
|
|
|
|
|
|
assigned_to: assigned_to_user, |
|
|
|
|
|
|
|
ppcodenk: 1, |
|
|
|
|
|
|
|
postcode_full: "CA10 1AA", |
|
|
|
|
|
|
|
saledate: Time.zone.local(2022, 5, 2), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
WebMock.stub_request(:get, /api\.postcodes\.io\/postcodes\/CA101AA/) |
|
|
|
|
|
|
|
.to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Cumberland","codes":{"admin_district":"E06000064"}}}', headers: {}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Timecop.freeze(2023, 5, 1) |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "correctly sets la as nil" do |
|
|
|
|
|
|
|
record_from_db = described_class.find(address_sales_log_22_23.id) |
|
|
|
|
|
|
|
expect(address_sales_log_22_23.la).to eq(nil) |
|
|
|
|
|
|
|
expect(record_from_db["la"]).to eq(nil) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "with 23/24 logs" do |
|
|
|
context "with 23/24 logs" do |
|
|
|
let(:address_sales_log_23_24) do |
|
|
|
let(:address_sales_log_23_24) do |
|
|
|
described_class.create({ |
|
|
|
described_class.create({ |
|
|
|
@ -624,13 +590,6 @@ RSpec.describe SalesLog, type: :model do |
|
|
|
before do |
|
|
|
before do |
|
|
|
WebMock.stub_request(:get, /api\.postcodes\.io\/postcodes\/CA101AA/) |
|
|
|
WebMock.stub_request(:get, /api\.postcodes\.io\/postcodes\/CA101AA/) |
|
|
|
.to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Eden","codes":{"admin_district":"E07000030"}}}', headers: {}) |
|
|
|
.to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Eden","codes":{"admin_district":"E07000030"}}}', headers: {}) |
|
|
|
|
|
|
|
|
|
|
|
Timecop.freeze(2023, 5, 2) |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "correctly infers new la" do |
|
|
|
it "correctly infers new la" do |
|
|
|
@ -664,13 +623,6 @@ RSpec.describe SalesLog, type: :model do |
|
|
|
before do |
|
|
|
before do |
|
|
|
WebMock.stub_request(:get, /api\.postcodes\.io\/postcodes\/CA101AA/) |
|
|
|
WebMock.stub_request(:get, /api\.postcodes\.io\/postcodes\/CA101AA/) |
|
|
|
.to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Eden","codes":{"admin_district":"E07000030"}}}', headers: {}) |
|
|
|
.to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Eden","codes":{"admin_district":"E07000030"}}}', headers: {}) |
|
|
|
|
|
|
|
|
|
|
|
Timecop.freeze(2024, 5, 2) |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "sets previous postcode for discounted sale" do |
|
|
|
it "sets previous postcode for discounted sale" do |
|
|
|
|