Browse Source
* feat: add field import service and test * feat: use old visible org id * feat: tweak test * feat: update rake task * feat: split sales and lettings rake tasks * feat: update rake task * feat: PR comment tweaks * feat: rename and update tests * refactor: lintpull/1852/head v0.3.49
natdeanlewissoftwire
1 year ago
committed by
GitHub
5 changed files with 235 additions and 81 deletions
@ -1,106 +1,176 @@ |
|||||||
require "rails_helper" |
require "rails_helper" |
||||||
require "rake" |
require "rake" |
||||||
|
|
||||||
describe "rake core:data_import_field", type: :task do |
describe "data_import_field imports" do |
||||||
subject(:task) { Rake::Task["core:data_import_field"] } |
context "with rake core:lettings_data_import_field", type: :task do |
||||||
|
subject(:task) { Rake::Task["core:lettings_data_import_field"] } |
||||||
let(:instance_name) { "paas_import_instance" } |
|
||||||
let(:storage_service) { instance_double(Storage::S3Service) } |
|
||||||
let(:env_config_service) { instance_double(Configuration::EnvConfigurationService) } |
|
||||||
let(:paas_config_service) { instance_double(Configuration::PaasConfigurationService) } |
|
||||||
|
|
||||||
before do |
|
||||||
Rake.application.rake_require("tasks/data_import_field") |
|
||||||
Rake::Task.define_task(:environment) |
|
||||||
task.reenable |
|
||||||
|
|
||||||
allow(Storage::S3Service).to receive(:new).and_return(storage_service) |
|
||||||
allow(Configuration::EnvConfigurationService).to receive(:new).and_return(env_config_service) |
|
||||||
allow(Configuration::PaasConfigurationService).to receive(:new).and_return(paas_config_service) |
|
||||||
allow(ENV).to receive(:[]) |
|
||||||
allow(ENV).to receive(:[]).with("IMPORT_PAAS_INSTANCE").and_return(instance_name) |
|
||||||
allow(ENV).to receive(:[]).with("VCAP_SERVICES").and_return("dummy") |
|
||||||
allow(Imports::LettingsLogsFieldImportService).to receive(:new).and_return(import_service) |
|
||||||
end |
|
||||||
|
|
||||||
context "when importing a lettings log field" do |
let(:instance_name) { "paas_import_instance" } |
||||||
let(:import_service) { instance_double(Imports::LettingsLogsFieldImportService) } |
let(:storage_service) { instance_double(Storage::S3Service) } |
||||||
let(:fixture_path) { "spec/fixtures/imports/logs" } |
let(:env_config_service) { instance_double(Configuration::EnvConfigurationService) } |
||||||
let(:archive_service) { instance_double(Storage::ArchiveService) } |
let(:paas_config_service) { instance_double(Configuration::PaasConfigurationService) } |
||||||
|
|
||||||
before do |
before do |
||||||
allow(import_service).to receive(:update_field) |
Rake.application.rake_require("tasks/data_import_field") |
||||||
allow(Storage::ArchiveService).to receive(:new).and_return(archive_service) |
Rake::Task.define_task(:environment) |
||||||
allow(archive_service).to receive(:folder_present?).with("logs").and_return(true) |
task.reenable |
||||||
|
|
||||||
|
allow(Storage::S3Service).to receive(:new).and_return(storage_service) |
||||||
|
allow(Configuration::EnvConfigurationService).to receive(:new).and_return(env_config_service) |
||||||
|
allow(Configuration::PaasConfigurationService).to receive(:new).and_return(paas_config_service) |
||||||
|
allow(ENV).to receive(:[]) |
||||||
|
allow(ENV).to receive(:[]).with("IMPORT_PAAS_INSTANCE").and_return(instance_name) |
||||||
|
allow(ENV).to receive(:[]).with("VCAP_SERVICES").and_return("dummy") |
||||||
|
allow(Imports::LettingsLogsFieldImportService).to receive(:new).and_return(import_service) |
||||||
end |
end |
||||||
|
|
||||||
context "and we update the tenancycode field" do |
context "when importing a lettings log field" do |
||||||
let(:field) { "tenancycode" } |
let(:import_service) { instance_double(Imports::LettingsLogsFieldImportService) } |
||||||
|
let(:fixture_path) { "spec/fixtures/imports/logs" } |
||||||
|
let(:archive_service) { instance_double(Storage::ArchiveService) } |
||||||
|
|
||||||
it "updates the logs from the given XML file when the VCAP_SERVICES environment variable exists" do |
before do |
||||||
expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) |
allow(import_service).to receive(:update_field) |
||||||
expect(storage_service).to receive(:get_file_io).with("spec/fixtures/imports/logs") |
allow(Storage::ArchiveService).to receive(:new).and_return(archive_service) |
||||||
expect(Imports::LettingsLogsFieldImportService).to receive(:new).with(archive_service) |
allow(archive_service).to receive(:folder_present?).with("logs").and_return(true) |
||||||
expect(import_service).to receive(:update_field).with(field, "logs") |
|
||||||
task.invoke(field, fixture_path) |
|
||||||
end |
end |
||||||
|
|
||||||
it "updates the logs from the given XML file when the VCAP_SERVICES environment variable does not exist" do |
context "and we update the tenancycode field" do |
||||||
allow(ENV).to receive(:[]).with("VCAP_SERVICES") |
let(:field) { "tenancycode" } |
||||||
expect(Storage::S3Service).to receive(:new).with(env_config_service, instance_name) |
|
||||||
expect(storage_service).to receive(:get_file_io).with("spec/fixtures/imports/logs") |
it "updates the logs from the given XML file when the VCAP_SERVICES environment variable exists" do |
||||||
expect(Imports::LettingsLogsFieldImportService).to receive(:new).with(archive_service) |
expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) |
||||||
expect(import_service).to receive(:update_field).with(field, "logs") |
expect(storage_service).to receive(:get_file_io).with("spec/fixtures/imports/logs") |
||||||
task.invoke(field, fixture_path) |
expect(Imports::LettingsLogsFieldImportService).to receive(:new).with(archive_service) |
||||||
|
expect(import_service).to receive(:update_field).with(field, "logs") |
||||||
|
task.invoke(field, fixture_path) |
||||||
|
end |
||||||
|
|
||||||
|
it "updates the logs from the given XML file when the VCAP_SERVICES environment variable does not exist" do |
||||||
|
allow(ENV).to receive(:[]).with("VCAP_SERVICES") |
||||||
|
expect(Storage::S3Service).to receive(:new).with(env_config_service, instance_name) |
||||||
|
expect(storage_service).to receive(:get_file_io).with("spec/fixtures/imports/logs") |
||||||
|
expect(Imports::LettingsLogsFieldImportService).to receive(:new).with(archive_service) |
||||||
|
expect(import_service).to receive(:update_field).with(field, "logs") |
||||||
|
task.invoke(field, fixture_path) |
||||||
|
end |
||||||
end |
end |
||||||
end |
|
||||||
|
|
||||||
context "and we update the lettings_allocation fields" do |
context "and we update the lettings_allocation fields" do |
||||||
let(:field) { "lettings_allocation" } |
let(:field) { "lettings_allocation" } |
||||||
|
|
||||||
it "updates the logs from the given XML file" do |
it "updates the logs from the given XML file" do |
||||||
expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) |
expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) |
||||||
expect(storage_service).to receive(:get_file_io).with("spec/fixtures/imports/logs") |
expect(storage_service).to receive(:get_file_io).with("spec/fixtures/imports/logs") |
||||||
expect(Imports::LettingsLogsFieldImportService).to receive(:new).with(archive_service) |
expect(Imports::LettingsLogsFieldImportService).to receive(:new).with(archive_service) |
||||||
expect(import_service).to receive(:update_field).with(field, "logs") |
expect(import_service).to receive(:update_field).with(field, "logs") |
||||||
task.invoke(field, fixture_path) |
task.invoke(field, fixture_path) |
||||||
|
end |
||||||
end |
end |
||||||
end |
|
||||||
|
|
||||||
context "and we update the major repairs fields" do |
context "and we update the major repairs fields" do |
||||||
let(:field) { "major_repairs" } |
let(:field) { "major_repairs" } |
||||||
|
|
||||||
it "updates the logs from the given XML file" do |
it "updates the logs from the given XML file" do |
||||||
expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) |
expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) |
||||||
expect(storage_service).to receive(:get_file_io).with("spec/fixtures/imports/logs") |
expect(storage_service).to receive(:get_file_io).with("spec/fixtures/imports/logs") |
||||||
expect(Imports::LettingsLogsFieldImportService).to receive(:new).with(archive_service) |
expect(Imports::LettingsLogsFieldImportService).to receive(:new).with(archive_service) |
||||||
expect(import_service).to receive(:update_field).with(field, "logs") |
expect(import_service).to receive(:update_field).with(field, "logs") |
||||||
task.invoke(field, fixture_path) |
task.invoke(field, fixture_path) |
||||||
|
end |
||||||
end |
end |
||||||
end |
|
||||||
|
|
||||||
context "and we update the offered fields" do |
context "and we update the offered fields" do |
||||||
let(:field) { "offered" } |
let(:field) { "offered" } |
||||||
|
|
||||||
it "updates the logs from the given XML file" do |
it "updates the logs from the given XML file" do |
||||||
expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) |
expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) |
||||||
expect(storage_service).to receive(:get_file_io).with("spec/fixtures/imports/logs") |
expect(storage_service).to receive(:get_file_io).with("spec/fixtures/imports/logs") |
||||||
expect(Imports::LettingsLogsFieldImportService).to receive(:new).with(archive_service) |
expect(Imports::LettingsLogsFieldImportService).to receive(:new).with(archive_service) |
||||||
expect(import_service).to receive(:update_field).with(field, "logs") |
expect(import_service).to receive(:update_field).with(field, "logs") |
||||||
task.invoke(field, fixture_path) |
task.invoke(field, fixture_path) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
it "raises an exception if no parameters are provided" do |
||||||
|
expect { task.invoke }.to raise_error(/Usage/) |
||||||
|
end |
||||||
|
|
||||||
|
it "raises an exception if a single parameter is provided" do |
||||||
|
expect { task.invoke("one_parameter") }.to raise_error(/Usage/) |
||||||
end |
end |
||||||
end |
|
||||||
|
|
||||||
it "raises an exception if no parameters are provided" do |
it "raises an exception if the field is not supported" do |
||||||
expect { task.invoke }.to raise_error(/Usage/) |
expect { task.invoke("random_field", "my_path") }.to raise_error("Field random_field cannot be updated by lettings_data_import_field") |
||||||
|
end |
||||||
end |
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with rake core:sales_data_import_field", type: :task do |
||||||
|
subject(:task) { Rake::Task["core:sales_data_import_field"] } |
||||||
|
|
||||||
it "raises an exception if a single parameter is provided" do |
let(:instance_name) { "paas_import_instance" } |
||||||
expect { task.invoke("one_parameter") }.to raise_error(/Usage/) |
let(:storage_service) { instance_double(Storage::S3Service) } |
||||||
|
let(:env_config_service) { instance_double(Configuration::EnvConfigurationService) } |
||||||
|
let(:paas_config_service) { instance_double(Configuration::PaasConfigurationService) } |
||||||
|
|
||||||
|
before do |
||||||
|
Rake.application.rake_require("tasks/data_import_field") |
||||||
|
Rake::Task.define_task(:environment) |
||||||
|
task.reenable |
||||||
|
|
||||||
|
allow(Storage::S3Service).to receive(:new).and_return(storage_service) |
||||||
|
allow(Configuration::EnvConfigurationService).to receive(:new).and_return(env_config_service) |
||||||
|
allow(Configuration::PaasConfigurationService).to receive(:new).and_return(paas_config_service) |
||||||
|
allow(ENV).to receive(:[]) |
||||||
|
allow(ENV).to receive(:[]).with("IMPORT_PAAS_INSTANCE").and_return(instance_name) |
||||||
|
allow(ENV).to receive(:[]).with("VCAP_SERVICES").and_return("dummy") |
||||||
|
allow(Imports::SalesLogsFieldImportService).to receive(:new).and_return(import_service) |
||||||
end |
end |
||||||
|
|
||||||
it "raises an exception if the field is not supported" do |
context "when importing a sales log field" do |
||||||
expect { task.invoke("random_field", "my_path") }.to raise_error("Field random_field cannot be updated by data_import_field") |
let(:import_service) { instance_double(Imports::SalesLogsFieldImportService) } |
||||||
|
let(:fixture_path) { "spec/fixtures/imports/sales_logs" } |
||||||
|
let(:archive_service) { instance_double(Storage::ArchiveService) } |
||||||
|
|
||||||
|
before do |
||||||
|
allow(import_service).to receive(:update_field) |
||||||
|
allow(Storage::ArchiveService).to receive(:new).and_return(archive_service) |
||||||
|
allow(archive_service).to receive(:folder_present?).with("logs").and_return(true) |
||||||
|
end |
||||||
|
|
||||||
|
context "and we update the owning_organisation_id field" do |
||||||
|
let(:field) { "owning_organisation_id" } |
||||||
|
|
||||||
|
it "updates the logs from the given XML file when the VCAP_SERVICES environment variable exists" do |
||||||
|
expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) |
||||||
|
expect(storage_service).to receive(:get_file_io).with("spec/fixtures/imports/sales_logs") |
||||||
|
expect(Imports::SalesLogsFieldImportService).to receive(:new).with(archive_service) |
||||||
|
expect(import_service).to receive(:update_field).with(field, "logs") |
||||||
|
task.invoke(field, fixture_path) |
||||||
|
end |
||||||
|
|
||||||
|
it "updates the logs from the given XML file when the VCAP_SERVICES environment variable does not exist" do |
||||||
|
allow(ENV).to receive(:[]).with("VCAP_SERVICES") |
||||||
|
expect(Storage::S3Service).to receive(:new).with(env_config_service, instance_name) |
||||||
|
expect(storage_service).to receive(:get_file_io).with("spec/fixtures/imports/sales_logs") |
||||||
|
expect(Imports::SalesLogsFieldImportService).to receive(:new).with(archive_service) |
||||||
|
expect(import_service).to receive(:update_field).with(field, "logs") |
||||||
|
task.invoke(field, fixture_path) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
it "raises an exception if no parameters are provided" do |
||||||
|
expect { task.invoke }.to raise_error(/Usage/) |
||||||
|
end |
||||||
|
|
||||||
|
it "raises an exception if a single parameter is provided" do |
||||||
|
expect { task.invoke("one_parameter") }.to raise_error(/Usage/) |
||||||
|
end |
||||||
|
|
||||||
|
it "raises an exception if the field is not supported" do |
||||||
|
expect { task.invoke("random_field", "my_path") }.to raise_error("Field random_field cannot be updated by sales_data_import_field") |
||||||
|
end |
||||||
end |
end |
||||||
end |
end |
||||||
end |
end |
||||||
|
Loading…
Reference in new issue