From 6e1db7b02453312ac00bddf7df5b879a16a6259e Mon Sep 17 00:00:00 2001 From: Sam Seed Date: Tue, 8 Aug 2023 11:13:44 +0100 Subject: [PATCH] test: update suite to work with new paas/env config service logic test: new PlatformHelper --- spec/helpers/platform_helper_spec.rb | 15 +++++++++++++++ spec/lib/tasks/data_import_spec.rb | 14 +++++++++++++- spec/lib/tasks/date_import_field_spec.rb | 14 +++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 spec/helpers/platform_helper_spec.rb diff --git a/spec/helpers/platform_helper_spec.rb b/spec/helpers/platform_helper_spec.rb new file mode 100644 index 000000000..2a90f7762 --- /dev/null +++ b/spec/helpers/platform_helper_spec.rb @@ -0,0 +1,15 @@ +require "rails_helper" + +RSpec.describe PlatformHelper do + describe "is_paas?" do + it "returns true if the VCAP_SERVICES environment variable exists" do + allow(ENV).to receive(:[]).with("VCAP_SERVICES").and_return("dummy") + expect(described_class.is_paas?).to eq(true) + end + + it "returns false if the VCAP_SERVICES environment variable doesn't exist" do + allow(ENV).to receive(:[]).with("VCAP_SERVICES") + expect(described_class.is_paas?).to eq(false) + end + end +end diff --git a/spec/lib/tasks/data_import_spec.rb b/spec/lib/tasks/data_import_spec.rb index b8b56801a..0cba6952f 100644 --- a/spec/lib/tasks/data_import_spec.rb +++ b/spec/lib/tasks/data_import_spec.rb @@ -3,6 +3,7 @@ require "rake" describe "data import", type: :task do let(:instance_name) { "paas_import_instance" } + let(:env_config_service) { instance_double(Configuration::EnvConfigurationService) } let(:paas_config_service) { instance_double(Configuration::PaasConfigurationService) } let(:storage_service) { instance_double(Storage::S3Service) } @@ -16,8 +17,10 @@ describe "data import", type: :task do allow(Storage::S3Service).to receive(:new).and_return(storage_service) allow(Configuration::PaasConfigurationService).to receive(:new).and_return(paas_config_service) + allow(Configuration::EnvConfigurationService).to receive(:new).and_return(env_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") end context "when importing organisation data" do @@ -29,13 +32,22 @@ describe "data import", type: :task do allow(Imports::OrganisationImportService).to receive(:new).and_return(import_service) end - it "creates an organisation from the given XML file" do + it "creates an organisation 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(Imports::OrganisationImportService).to receive(:new).with(storage_service) expect(import_service).to receive(:create_organisations).with(fixture_path) task.invoke(type, fixture_path) end + + it "creates an organisation 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(Imports::OrganisationImportService).to receive(:new).with(storage_service) + expect(import_service).to receive(:create_organisations).with(fixture_path) + + task.invoke(type, fixture_path) + end end context "when importing user data" do diff --git a/spec/lib/tasks/date_import_field_spec.rb b/spec/lib/tasks/date_import_field_spec.rb index a30920694..c34427e04 100644 --- a/spec/lib/tasks/date_import_field_spec.rb +++ b/spec/lib/tasks/date_import_field_spec.rb @@ -6,6 +6,7 @@ describe "rake core:data_import_field", type: :task do 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 @@ -14,9 +15,11 @@ describe "rake core:data_import_field", type: :task do 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 @@ -34,13 +37,22 @@ describe "rake core:data_import_field", type: :task do context "and we update the tenancycode field" do let(:field) { "tenancycode" } - it "updates the logs from the given XML file" do + 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/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 + + 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 context "and we update the lettings_allocation fields" do