Browse Source

Add tests

pull/335/head
baarkerlounger 3 years ago
parent
commit
a401cbba0f
  1. 26
      spec/lib/tasks/data_import_spec.rb
  2. 4
      spec/models/case_log_spec.rb
  3. 12
      spec/models/validations/household_validations_spec.rb

26
spec/lib/tasks/data_import_spec.rb

@ -6,7 +6,7 @@ describe "rake core:data_import", type: :task do
let(:fixture_path) { "spec/fixtures/softwire_imports/organisations" } let(:fixture_path) { "spec/fixtures/softwire_imports/organisations" }
let(:instance_name) { "paas_import_instance" } let(:instance_name) { "paas_import_instance" }
let(:organisation_type) { "organisation" } let(:type) { "organisation" }
let(:storage_service) { instance_double(StorageService) } let(:storage_service) { instance_double(StorageService) }
let(:paas_config_service) { instance_double(PaasConfigurationService) } let(:paas_config_service) { instance_double(PaasConfigurationService) }
@ -19,18 +19,38 @@ describe "rake core:data_import", type: :task do
allow(StorageService).to receive(:new).and_return(storage_service) allow(StorageService).to receive(:new).and_return(storage_service)
allow(PaasConfigurationService).to receive(:new).and_return(paas_config_service) allow(PaasConfigurationService).to receive(:new).and_return(paas_config_service)
allow(Imports::OrganisationImportService).to receive(:new).and_return(import_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)
end end
context "when importing organisation data" do context "when importing organisation data" do
before 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" do
expect(StorageService).to receive(:new).with(paas_config_service, instance_name) expect(StorageService).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(organisation_type, fixture_path) task.invoke(type, fixture_path)
end
end
context "when importing user data" do
let(:type) { "user" }
let(:import_service) { instance_double(Imports::UserImportService) }
before do
allow(Imports::UserImportService).to receive(:new).and_return(import_service)
end
it "creates a user from the given XML file" do
expect(StorageService).to receive(:new).with(paas_config_service, instance_name)
expect(Imports::UserImportService).to receive(:new).with(storage_service)
expect(import_service).to receive(:create_users).with(fixture_path)
task.invoke(type, fixture_path)
end end
end end

4
spec/models/case_log_spec.rb

@ -123,6 +123,10 @@ RSpec.describe CaseLog do
expect(validator).to receive(:validate_reason_for_leaving_last_settled_home) expect(validator).to receive(:validate_reason_for_leaving_last_settled_home)
end end
it "validates previous housing situation" do
expect(validator).to receive(:validate_previous_housing_situation)
end
it "validates armed forces" do it "validates armed forces" do
expect(validator).to receive(:validate_armed_forces) expect(validator).to receive(:validate_armed_forces)
end end

12
spec/models/validations/household_validations_spec.rb

@ -547,4 +547,16 @@ RSpec.describe Validations::HouseholdValidations do
end end
end end
end end
describe "previous housing situation validations" do
context "when the property is being relet to a previously temporary tenant" do
it "validates that previous tenancy was temporary" do
record.rsnvac = 2
record.prevten = 4
household_validator.validate_previous_housing_situation(record)
expect(record.errors["prevten"])
.to include(match I18n.t("validations.household.prevten.non_temp_accommodation"))
end
end
end
end end

Loading…
Cancel
Save