|
|
@ -5,14 +5,38 @@ RSpec.describe BulkUpload::Sales::LogCreator do |
|
|
|
|
|
|
|
|
|
|
|
let(:owning_org) { create(:organisation, old_visible_id: 123) } |
|
|
|
let(:owning_org) { create(:organisation, old_visible_id: 123) } |
|
|
|
let(:user) { create(:user, organisation: owning_org) } |
|
|
|
let(:user) { create(:user, organisation: owning_org) } |
|
|
|
|
|
|
|
|
|
|
|
let(:bulk_upload) { create(:bulk_upload, :sales, user:, year: 2025) } |
|
|
|
|
|
|
|
let(:csv_parser) { instance_double(BulkUpload::Sales::Year2025::CsvParser) } |
|
|
|
|
|
|
|
let(:row_parser) { instance_double(BulkUpload::Sales::Year2025::RowParser) } |
|
|
|
|
|
|
|
let(:log) { build(:sales_log, :completed, assigned_to: user, owning_organisation: owning_org, managing_organisation: owning_org) } |
|
|
|
let(:log) { build(:sales_log, :completed, assigned_to: user, owning_organisation: owning_org, managing_organisation: owning_org) } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[2023, 2024, 2025].each do |year| |
|
|
|
|
|
|
|
context "when #{year}" do |
|
|
|
|
|
|
|
let(:bulk_upload) { create(:bulk_upload, :sales, user:, year:) } |
|
|
|
|
|
|
|
let(:year_csv_parser) { instance_double("BulkUpload::Sales::Year#{year}::CsvParser".constantize) } |
|
|
|
|
|
|
|
let(:year_row_parser) { instance_double("BulkUpload::Sales::Year#{year}::RowParser".constantize) } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
allow("BulkUpload::Sales::Year#{year}::CsvParser".constantize).to receive(:new).and_return(year_csv_parser) |
|
|
|
|
|
|
|
allow(year_csv_parser).to receive(:row_parsers).and_return([year_row_parser]) |
|
|
|
|
|
|
|
allow(year_row_parser).to receive(:log).and_return(log) |
|
|
|
|
|
|
|
allow(year_row_parser).to receive(:bulk_upload=).and_return(true) |
|
|
|
|
|
|
|
allow(year_row_parser).to receive(:valid?).and_return(true) |
|
|
|
|
|
|
|
allow(year_row_parser).to receive(:blank_row?).and_return(false) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "creates a parser for the correct year" do |
|
|
|
|
|
|
|
# This would fail without parser stubs, so the parser must be for the expected year |
|
|
|
|
|
|
|
expect { service.call }.to change(SalesLog, :count) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Apart from picking the correct year's parser, everything else is year-independent |
|
|
|
|
|
|
|
context "when 2024" do |
|
|
|
|
|
|
|
let(:bulk_upload) { create(:bulk_upload, :sales, user:, year: 2024) } |
|
|
|
|
|
|
|
let(:csv_parser) { instance_double(BulkUpload::Sales::Year2024::CsvParser) } |
|
|
|
|
|
|
|
let(:row_parser) { instance_double(BulkUpload::Sales::Year2024::RowParser) } |
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
before do |
|
|
|
allow(BulkUpload::Sales::Year2025::CsvParser).to receive(:new).and_return(csv_parser) |
|
|
|
allow(BulkUpload::Sales::Year2024::CsvParser).to receive(:new).and_return(csv_parser) |
|
|
|
allow(csv_parser).to receive(:row_parsers).and_return([row_parser]) |
|
|
|
allow(csv_parser).to receive(:row_parsers).and_return([row_parser]) |
|
|
|
allow(row_parser).to receive(:log).and_return(log) |
|
|
|
allow(row_parser).to receive(:log).and_return(log) |
|
|
|
allow(row_parser).to receive(:bulk_upload=).and_return(true) |
|
|
|
allow(row_parser).to receive(:bulk_upload=).and_return(true) |
|
|
@ -164,4 +188,5 @@ RSpec.describe BulkUpload::Sales::LogCreator do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|