Browse Source

test: update suite to work with new paas/env config service logic

test: new PlatformHelper
pull/1822/head
Sam Seed 3 years ago committed by Chirag-Bhatti
parent
commit
6e1db7b024
  1. 15
      spec/helpers/platform_helper_spec.rb
  2. 14
      spec/lib/tasks/data_import_spec.rb
  3. 14
      spec/lib/tasks/date_import_field_spec.rb

15
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

14
spec/lib/tasks/data_import_spec.rb

@ -3,6 +3,7 @@ require "rake"
describe "data import", type: :task do describe "data import", type: :task do
let(:instance_name) { "paas_import_instance" } let(:instance_name) { "paas_import_instance" }
let(:env_config_service) { instance_double(Configuration::EnvConfigurationService) }
let(:paas_config_service) { instance_double(Configuration::PaasConfigurationService) } let(:paas_config_service) { instance_double(Configuration::PaasConfigurationService) }
let(:storage_service) { instance_double(Storage::S3Service) } 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(Storage::S3Service).to receive(:new).and_return(storage_service)
allow(Configuration::PaasConfigurationService).to receive(:new).and_return(paas_config_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(:[])
allow(ENV).to receive(:[]).with("IMPORT_PAAS_INSTANCE").and_return(instance_name) allow(ENV).to receive(:[]).with("IMPORT_PAAS_INSTANCE").and_return(instance_name)
allow(ENV).to receive(:[]).with("VCAP_SERVICES").and_return("dummy")
end end
context "when importing organisation data" do 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) allow(Imports::OrganisationImportService).to receive(:new).and_return(import_service)
end 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(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name)
expect(Imports::OrganisationImportService).to receive(:new).with(storage_service) expect(Imports::OrganisationImportService).to receive(:new).with(storage_service)
expect(import_service).to receive(:create_organisations).with(fixture_path) expect(import_service).to receive(:create_organisations).with(fixture_path)
task.invoke(type, fixture_path) task.invoke(type, fixture_path)
end 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 end
context "when importing user data" do context "when importing user data" do

14
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(:instance_name) { "paas_import_instance" }
let(:storage_service) { instance_double(Storage::S3Service) } let(:storage_service) { instance_double(Storage::S3Service) }
let(:env_config_service) { instance_double(Configuration::EnvConfigurationService) }
let(:paas_config_service) { instance_double(Configuration::PaasConfigurationService) } let(:paas_config_service) { instance_double(Configuration::PaasConfigurationService) }
before do before do
@ -14,9 +15,11 @@ describe "rake core:data_import_field", type: :task do
task.reenable task.reenable
allow(Storage::S3Service).to receive(:new).and_return(storage_service) 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(Configuration::PaasConfigurationService).to receive(:new).and_return(paas_config_service)
allow(ENV).to receive(:[]) allow(ENV).to receive(:[])
allow(ENV).to receive(:[]).with("IMPORT_PAAS_INSTANCE").and_return(instance_name) 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) allow(Imports::LettingsLogsFieldImportService).to receive(:new).and_return(import_service)
end end
@ -34,13 +37,22 @@ describe "rake core:data_import_field", type: :task do
context "and we update the tenancycode field" do context "and we update the tenancycode field" do
let(:field) { "tenancycode" } 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::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 "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
context "and we update the lettings_allocation fields" do context "and we update the lettings_allocation fields" do

Loading…
Cancel
Save