Browse Source

Fix validations in tests

pull/1022/head
Kat 4 years ago
parent
commit
1ab17c527b
  1. 3
      app/models/location.rb
  2. 2
      spec/components/check_answers_summary_list_card_component_spec.rb
  3. 4
      spec/factories/lettings_log.rb
  4. 2
      spec/factories/location.rb
  5. 3
      spec/features/form/check_answers_page_spec.rb
  6. 1
      spec/features/form/validations_spec.rb
  7. 3
      spec/jobs/email_csv_job_spec.rb
  8. 4
      spec/models/lettings_log_spec.rb
  9. 1
      spec/requests/form_controller_spec.rb
  10. 10
      spec/requests/locations_controller_spec.rb
  11. 8
      spec/services/exports/lettings_log_export_service_spec.rb
  12. 6
      spec/services/imports/lettings_logs_import_service_spec.rb

3
app/models/location.rb

@ -394,7 +394,8 @@ class Location < ApplicationRecord
end
def status_during(date)
return unless date.present?
return if date.blank?
closest_reactivation = location_deactivation_periods.reverse.find { |period| period.reactivation_date.present? && date.between?(period.deactivation_date, period.reactivation_date) }
return { status: :reactivating_soon, date: closest_reactivation.reactivation_date } if closest_reactivation.present?
return { status: :reactivating_soon, date: available_from } if available_from.present? && available_from > date

2
spec/components/check_answers_summary_list_card_component_spec.rb

@ -3,7 +3,7 @@ require "rails_helper"
RSpec.describe CheckAnswersSummaryListCardComponent, type: :component do
context "when given a set of questions" do
let(:user) { FactoryBot.build(:user) }
let(:log) { FactoryBot.build(:lettings_log, :completed, age2: 99) }
let(:log) { FactoryBot.build(:lettings_log, :completed, age2: 99, startdate: Time.zone.local(2021, 5, 1)) }
let(:subsection_id) { "household_characteristics" }
let(:subsection) { log.form.get_subsection(subsection_id) }
let(:questions) { subsection.applicable_questions(log) }

4
spec/factories/lettings_log.rb

@ -60,7 +60,7 @@ FactoryBot.define do
illness { 1 }
preg_occ { 2 }
startertenancy { 1 }
tenancylength { 5 }
tenancylength { nil }
tenancy { 1 }
ppostcode_full { Faker::Address.postcode }
rsnvac { 6 }
@ -134,7 +134,7 @@ FactoryBot.define do
property_relet { 0 }
mrcdate { Time.zone.local(2020, 5, 5, 10, 36, 49) }
incref { 0 }
startdate { Time.utc(2022, 2, 2, 10, 36, 49) }
startdate { Time.zone.today }
armedforces { 1 }
builtype { 1 }
unitletas { 2 }

2
spec/factories/location.rb

@ -7,7 +7,7 @@ FactoryBot.define do
mobility_type { %w[A M N W X].sample }
location_code { "E09000033" }
location_admin_district { "Westminster" }
startdate { Faker::Date.between(from: 6.months.ago, to: Time.zone.today) }
startdate { nil }
confirmed { true }
scheme
trait :export do

3
spec/features/form/check_answers_page_spec.rb

@ -7,7 +7,7 @@ RSpec.describe "Form Check Answers Page" do
let(:subsection) { "household-characteristics" }
let(:conditional_subsection) { "conditional-question" }
let(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let(:location) { FactoryBot.create(:location, scheme:, mobility_type: "N") }
let(:location) { FactoryBot.create(:location, scheme:, mobility_type: "N", startdate: Time.zone.local(2021, 4, 1)) }
let(:lettings_log) do
FactoryBot.create(
@ -36,6 +36,7 @@ RSpec.describe "Form Check Answers Page" do
:completed,
owning_organisation: user.organisation,
managing_organisation: user.organisation,
startdate: Time.zone.local(2021, 5, 1),
)
end
let(:id) { lettings_log.id }

1
spec/features/form/validations_spec.rb

@ -28,6 +28,7 @@ RSpec.describe "validations" do
managing_organisation: user.organisation,
status: 1,
declaration: nil,
startdate: Time.zone.local(2021, 5, 1),
)
end
let(:id) { lettings_log.id }

3
spec/jobs/email_csv_job_spec.rb

@ -33,7 +33,8 @@ describe EmailCsvJob do
:completed,
owning_organisation: organisation,
managing_organisation: organisation,
created_by: user)
created_by: user,
startdate: Time.zone.local(2021, 5, 1))
allow(Storage::S3Service).to receive(:new).and_return(storage_service)
allow(storage_service).to receive(:write_file)

4
spec/models/lettings_log_spec.rb

@ -1672,7 +1672,7 @@ RSpec.describe LettingsLog do
let(:scheme) { FactoryBot.create(:scheme) }
let!(:location) { FactoryBot.create(:location, scheme:) }
before { lettings_log.update!(scheme:) }
before { lettings_log.update!(startdate: Time.zone.local(2022, 4, 2), scheme:) }
it "derives the scheme location" do
record_from_db = ActiveRecord::Base.connection.execute("select location_id from lettings_logs where id=#{lettings_log.id}").to_a[0]
@ -2375,7 +2375,7 @@ RSpec.describe LettingsLog do
describe "csv download" do
let(:scheme) { FactoryBot.create(:scheme) }
let(:location) { FactoryBot.create(:location, :export, scheme:, type_of_unit: 6, postcode: "SE11TE") }
let(:location) { FactoryBot.create(:location, :export, scheme:, type_of_unit: 6, postcode: "SE11TE", startdate: Time.zone.local(2021, 10, 1)) }
let(:user) { FactoryBot.create(:user, organisation: location.scheme.owning_organisation) }
let(:expected_content) { csv_export_file.read }

1
spec/requests/form_controller_spec.rb

@ -28,6 +28,7 @@ RSpec.describe FormController, type: :request do
:completed,
owning_organisation: organisation,
managing_organisation: organisation,
startdate: Time.zone.local(2021, 5, 1),
)
end
let(:headers) { { "Accept" => "text/html" } }

10
spec/requests/locations_controller_spec.rb

@ -847,7 +847,7 @@ RSpec.describe LocationsController, type: :request do
context "when signed in as a data coordinator user" do
let(:user) { FactoryBot.create(:user, :data_coordinator) }
let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let!(:locations) { FactoryBot.create_list(:location, 3, scheme:) }
let!(:locations) { FactoryBot.create_list(:location, 3, scheme:, startdate: Time.zone.local(2022, 4, 1)) }
before do
sign_in user
@ -858,7 +858,7 @@ RSpec.describe LocationsController, type: :request do
let!(:another_scheme) { FactoryBot.create(:scheme) }
before do
FactoryBot.create(:location, scheme:)
FactoryBot.create(:location, scheme:, startdate: Time.zone.local(2022, 4, 1))
end
it "returns 404 not found" do
@ -874,7 +874,7 @@ RSpec.describe LocationsController, type: :request do
expect(page).to have_content(location.type_of_unit)
expect(page).to have_content(location.mobility_type)
expect(page).to have_content(location.location_admin_district)
expect(page).to have_content(location.startdate&.to_formatted_s(:govuk_date))
expect(page).to have_content(location.startdate.to_formatted_s(:govuk_date))
end
end
@ -964,7 +964,7 @@ RSpec.describe LocationsController, type: :request do
context "when signed in as a support user" do
let(:user) { FactoryBot.create(:user, :support) }
let!(:scheme) { FactoryBot.create(:scheme) }
let!(:locations) { FactoryBot.create_list(:location, 3, scheme:) }
let!(:locations) { FactoryBot.create_list(:location, 3, scheme:, startdate: Time.zone.local(2022, 4, 1)) }
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
@ -977,7 +977,7 @@ RSpec.describe LocationsController, type: :request do
expect(page).to have_content(location.id)
expect(page).to have_content(location.postcode)
expect(page).to have_content(location.type_of_unit)
expect(page).to have_content(location.startdate&.to_formatted_s(:govuk_date))
expect(page).to have_content(location.startdate.to_formatted_s(:govuk_date))
end
end

8
spec/services/exports/lettings_log_export_service_spec.rb

@ -59,7 +59,7 @@ RSpec.describe Exports::LettingsLogExportService do
end
context "and one lettings log is available for export" do
let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenancycode: "BZ737") }
let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenancycode: "BZ737", startdate: Time.utc(2022, 2, 2, 10, 36, 49), tenancylength: 5) }
it "generates a ZIP export file with the expected filename" do
expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args)
@ -237,7 +237,7 @@ RSpec.describe Exports::LettingsLogExportService do
let(:csv_export_file) { File.open("spec/fixtures/exports/general_needs_log.csv", "r:UTF-8") }
let(:expected_csv_filename) { "export_2022_05_01.csv" }
let(:lettings_log) { FactoryBot.create(:lettings_log, :completed, propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenancycode: "BZ737") }
let(:lettings_log) { FactoryBot.create(:lettings_log, :completed, propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenancycode: "BZ737", startdate: Time.utc(2022, 2, 2, 10, 36, 49), tenancylength: 5) }
it "generates an CSV export file with the expected content" do
expected_content = replace_entity_ids(lettings_log, csv_export_file.read)
@ -254,9 +254,9 @@ RSpec.describe Exports::LettingsLogExportService do
let(:organisation) { FactoryBot.create(:organisation, provider_type: "LA") }
let(:user) { FactoryBot.create(:user, organisation:) }
let(:scheme) { FactoryBot.create(:scheme, :export, owning_organisation: organisation) }
let(:location) { FactoryBot.create(:location, :export, scheme:) }
let(:location) { FactoryBot.create(:location, :export, scheme:, startdate: Time.zone.local(2021, 4, 1)) }
let(:lettings_log) { FactoryBot.create(:lettings_log, :completed, :export, :sh, scheme:, location:, created_by: user, owning_organisation: organisation) }
let(:lettings_log) { FactoryBot.create(:lettings_log, :completed, :export, :sh, scheme:, location:, created_by: user, owning_organisation: organisation, startdate: Time.utc(2022, 2, 2, 10, 36, 49)) }
it "generates an XML export file with the expected content" do
expected_content = replace_entity_ids(lettings_log, export_file.read)

6
spec/services/imports/lettings_logs_import_service_spec.rb

@ -30,9 +30,9 @@ RSpec.describe Imports::LettingsLogsImportService do
FactoryBot.create(:user, old_user_id: "e29c492473446dca4d50224f2bb7cf965a261d6f", organisation:)
# Location setup
FactoryBot.create(:location, old_visible_id: "10", postcode: "LS166FT", scheme_id: scheme1.id, mobility_type: "W")
FactoryBot.create(:location, scheme_id: scheme1.id)
FactoryBot.create(:location, old_visible_id: "10", postcode: "LS166FT", scheme_id: scheme2.id, mobility_type: "W")
FactoryBot.create(:location, old_visible_id: "10", postcode: "LS166FT", scheme_id: scheme1.id, mobility_type: "W", startdate: Time.zone.local(2021, 4, 1))
FactoryBot.create(:location, scheme_id: scheme1.id, startdate: Time.zone.local(2021, 4, 1))
FactoryBot.create(:location, old_visible_id: "10", postcode: "LS166FT", scheme_id: scheme2.id, mobility_type: "W", startdate: Time.zone.local(2021, 4, 1))
# Stub the form handler to use the real form
allow(FormHandler.instance).to receive(:get_form).with("previous_lettings").and_return(real_2021_2022_form)

Loading…
Cancel
Save