Browse Source

Merge branch 'main' into CLDC-2636.2-set-uprn-known-no

CLDC-2632.2-set-uprn-known-no
natdeanlewissoftwire 1 year ago
parent
commit
0b0b6b4502
  1. 6
      app/controllers/sessions_controller.rb
  2. 8
      app/helpers/duplicate_logs_helper.rb
  3. 4
      app/helpers/filters_helper.rb
  4. 4
      app/helpers/schemes_helper.rb
  5. 16
      app/models/form_handler.rb
  6. 4
      app/models/lettings_log.rb
  7. 8
      app/models/organisation.rb
  8. 4
      app/models/sales_log.rb
  9. 2
      app/models/scheme.rb
  10. 10
      app/models/user.rb
  11. 2
      app/views/logs/_log_filters.html.erb
  12. 4
      app/views/schemes/_scheme_filters.html.erb
  13. 4
      app/views/users/_user_filters.html.erb
  14. 2
      config/locales/devise.en.yml
  15. 4
      config/locales/en.yml
  16. 2
      spec/features/schemes_spec.rb
  17. 4
      spec/features/user_spec.rb
  18. 25
      spec/helpers/schemes_helper_spec.rb
  19. 39
      spec/lib/tasks/blank_migrated_soctenant_values_spec.rb
  20. 11
      spec/models/lettings_log_spec.rb
  21. 2
      spec/models/scheme_spec.rb
  22. 2
      spec/requests/auth/passwords_controller_spec.rb
  23. 32
      spec/requests/duplicate_logs_controller_spec.rb
  24. 9
      spec/requests/form_controller_spec.rb
  25. 35
      spec/requests/lettings_logs_controller_spec.rb
  26. 10
      spec/requests/organisations_controller_spec.rb
  27. 75
      spec/requests/sales_logs_controller_spec.rb
  28. 2
      spec/requests/users_controller_spec.rb
  29. 7
      spec/services/bulk_upload/lettings/log_creator_spec.rb
  30. 7
      spec/services/bulk_upload/lettings/validator_spec.rb
  31. 9
      spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb
  32. 8
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb
  33. 7
      spec/services/bulk_upload/processor_spec.rb
  34. 4
      spec/services/bulk_upload/sales/year2023/row_parser_spec.rb
  35. 7
      spec/services/csv/missing_addresses_csv_service_spec.rb
  36. 7
      spec/services/imports/sales_logs_field_import_service_spec.rb

6
app/controllers/sessions_controller.rb

@ -3,7 +3,11 @@ class SessionsController < ApplicationController
session[session_name_for(params[:filter_type])] = "{}" session[session_name_for(params[:filter_type])] = "{}"
path_params = params[:path_params].presence || {} path_params = params[:path_params].presence || {}
redirect_to send("#{params[:filter_type]}_path", scheme_id: path_params[:scheme_id], search: path_params[:search]) if path_params[:organisation_id].present?
redirect_to send("#{params[:filter_type]}_organisation_path", id: path_params[:organisation_id], scheme_id: path_params[:scheme_id], search: path_params[:search])
else
redirect_to send("#{params[:filter_type]}_path", scheme_id: path_params[:scheme_id], search: path_params[:search])
end
end end
private private

8
app/helpers/duplicate_logs_helper.rb

@ -33,15 +33,15 @@ module DuplicateLogsHelper
def duplicates_for_user(user) def duplicates_for_user(user)
{ {
lettings: user.duplicate_lettings_logs_sets, lettings: user.editable_duplicate_lettings_logs_sets,
sales: user.duplicate_sales_logs_sets, sales: user.editable_duplicate_sales_logs_sets,
} }
end end
def duplicates_for_organisation(organisation) def duplicates_for_organisation(organisation)
{ {
lettings: organisation.duplicate_lettings_logs_sets, lettings: organisation.editable_duplicate_lettings_logs_sets,
sales: organisation.duplicate_sales_logs_sets, sales: organisation.editable_duplicate_sales_logs_sets,
} }
end end

4
app/helpers/filters_helper.rb

@ -139,6 +139,10 @@ module FiltersHelper
request.path.include?("/lettings-logs") request.path.include?("/lettings-logs")
end end
def specific_organisation_path?
request.path.include?("/organisations")
end
def applied_filters_count(filter_type) def applied_filters_count(filter_type)
filters_count(applied_filters(filter_type)) filters_count(applied_filters(filter_type))
end end

4
app/helpers/schemes_helper.rb

@ -11,11 +11,11 @@ module SchemesHelper
{ name: "Support services provided by", value: scheme.arrangement_type }, { name: "Support services provided by", value: scheme.arrangement_type },
{ name: "Primary client group", value: scheme.primary_client_group }, { name: "Primary client group", value: scheme.primary_client_group },
{ name: "Has another client group", value: scheme.has_other_client_group }, { name: "Has another client group", value: scheme.has_other_client_group },
{ name: "Secondary client group", value: scheme.secondary_client_group }, scheme.has_other_client_group == "Yes" ? { name: "Secondary client group", value: scheme.secondary_client_group } : nil,
{ name: "Level of support given", value: scheme.support_type }, { name: "Level of support given", value: scheme.support_type },
{ name: "Intended length of stay", value: scheme.intended_stay }, { name: "Intended length of stay", value: scheme.intended_stay },
{ name: "Availability", value: scheme_availability(scheme) }, { name: "Availability", value: scheme_availability(scheme) },
] ].compact
end end
def scheme_availability(scheme) def scheme_availability(scheme)

16
app/models/form_handler.rb

@ -178,6 +178,22 @@ class FormHandler
end end
end end
def lettings_earliest_open_for_editing_collection_start_date(now: Time.zone.now)
if lettings_in_edit_crossover_period?(now:)
collection_start_date(now) - 1.year
else
collection_start_date(now)
end
end
def sales_earliest_open_for_editing_collection_start_date(now: Time.zone.now)
if sales_in_edit_crossover_period?(now:)
collection_start_date(now) - 1.year
else
collection_start_date(now)
end
end
private private
def get_all_forms def get_all_forms

4
app/models/lettings_log.rb

@ -659,7 +659,7 @@ private
not_required << "tshortfall" if tshortfall_unknown? not_required << "tshortfall" if tshortfall_unknown?
not_required << "tenancylength" if tenancylength_optional? not_required << "tenancylength" if tenancylength_optional?
not_required |= %w[address_line2 county postcode_full] if startdate && startdate.year >= 2023 not_required |= %w[address_line2 county postcode_full] if startdate && collection_start_year_for_date(startdate) >= 2023
not_required not_required
end end
@ -780,6 +780,6 @@ private
end end
def should_process_uprn_change? def should_process_uprn_change?
uprn && startdate && (uprn_changed? || startdate_changed?) && startdate.year >= 2023 uprn && startdate && (uprn_changed? || startdate_changed?) && collection_start_year_for_date(startdate) >= 2023
end end
end end

8
app/models/organisation.rb

@ -133,12 +133,12 @@ class Organisation < ApplicationRecord
:active :active
end end
def duplicate_lettings_logs_sets def editable_duplicate_lettings_logs_sets
lettings_logs.duplicate_sets.map { |array_str| array_str ? array_str.map(&:to_i) : [] } lettings_logs.after_date(FormHandler.instance.lettings_earliest_open_for_editing_collection_start_date).duplicate_sets.map { |array_str| array_str ? array_str.map(&:to_i) : [] }
end end
def duplicate_sales_logs_sets def editable_duplicate_sales_logs_sets
sales_logs.duplicate_sets.map { |array_str| array_str ? array_str.map(&:to_i) : [] } sales_logs.after_date(FormHandler.instance.sales_earliest_open_for_editing_collection_start_date).duplicate_sets.map { |array_str| array_str ? array_str.map(&:to_i) : [] }
end end
def recently_absorbed_organisations_grouped_by_merge_date def recently_absorbed_organisations_grouped_by_merge_date

4
app/models/sales_log.rb

@ -115,7 +115,7 @@ class SalesLog < Log
not_required << "mortlen" if mortlen_optional? not_required << "mortlen" if mortlen_optional?
not_required << "frombeds" if frombeds_optional? not_required << "frombeds" if frombeds_optional?
not_required |= %w[address_line2 county postcode_full] if saledate && saledate.year >= 2023 not_required |= %w[address_line2 county postcode_full] if saledate && collection_start_year_for_date(saledate) >= 2023
not_required not_required
end end
@ -393,7 +393,7 @@ class SalesLog < Log
end end
def should_process_uprn_change? def should_process_uprn_change?
uprn && saledate && (uprn_changed? || saledate_changed?) && saledate.year >= 2023 uprn && saledate && (uprn_changed? || saledate_changed?) && collection_start_year_for_date(saledate) >= 2023
end end
def value_with_discount def value_with_discount

2
app/models/scheme.rb

@ -6,7 +6,7 @@ class Scheme < ApplicationRecord
has_paper_trail has_paper_trail
scope :filter_by_id, ->(id) { where(id: (id.start_with?("S") ? id[1..] : id)) } scope :filter_by_id, ->(id) { where(id: (id.start_with?("S", "s") ? id[1..] : id)) }
scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") } scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") }
scope :search_by_postcode, ->(postcode) { where("schemes.id IN (SELECT DISTINCT scheme_id FROM locations WHERE REPLACE(locations.postcode, ' ', '') ILIKE ?)", "%#{postcode.delete(' ')}%") } scope :search_by_postcode, ->(postcode) { where("schemes.id IN (SELECT DISTINCT scheme_id FROM locations WHERE REPLACE(locations.postcode, ' ', '') ILIKE ?)", "%#{postcode.delete(' ')}%") }
scope :search_by_location_name, ->(name) { where("schemes.id IN (SELECT DISTINCT scheme_id FROM locations WHERE locations.name ILIKE ?)", "%#{name}%") } scope :search_by_location_name, ->(name) { where("schemes.id IN (SELECT DISTINCT scheme_id FROM locations WHERE locations.name ILIKE ?)", "%#{name}%") }

10
app/models/user.rb

@ -15,8 +15,8 @@ class User < ApplicationRecord
validates :email, uniqueness: { allow_blank: true, case_sensitive: true, if: :will_save_change_to_email? } validates :email, uniqueness: { allow_blank: true, case_sensitive: true, if: :will_save_change_to_email? }
validates :email, format: { with: Devise.email_regexp, allow_blank: true, if: :will_save_change_to_email? } validates :email, format: { with: Devise.email_regexp, allow_blank: true, if: :will_save_change_to_email? }
validates :password, presence: { if: :password_required? } validates :password, presence: { if: :password_required? }
validates :password, confirmation: { if: :password_required? }
validates :password, length: { within: Devise.password_length, allow_blank: true } validates :password, length: { within: Devise.password_length, allow_blank: true }
validates :password, confirmation: { if: :password_required? }
after_validation :send_data_protection_confirmation_reminder, if: :is_dpo_changed? after_validation :send_data_protection_confirmation_reminder, if: :is_dpo_changed?
@ -203,12 +203,12 @@ class User < ApplicationRecord
super && active? super && active?
end end
def duplicate_lettings_logs_sets def editable_duplicate_lettings_logs_sets
lettings_logs.duplicate_sets(id).map { |array_str| array_str ? array_str.map(&:to_i) : [] } lettings_logs.after_date(FormHandler.instance.lettings_earliest_open_for_editing_collection_start_date).duplicate_sets(id).map { |array_str| array_str ? array_str.map(&:to_i) : [] }
end end
def duplicate_sales_logs_sets def editable_duplicate_sales_logs_sets
sales_logs.duplicate_sets(id).map { |array_str| array_str ? array_str.map(&:to_i) : [] } sales_logs.after_date(FormHandler.instance.sales_earliest_open_for_editing_collection_start_date).duplicate_sets(id).map { |array_str| array_str ? array_str.map(&:to_i) : [] }
end end
protected protected

2
app/views/logs/_log_filters.html.erb

@ -12,7 +12,7 @@
<%= filters_applied_text(@filter_type) %> <%= filters_applied_text(@filter_type) %>
</p> </p>
<p class="govuk-!-text-align-right govuk-grid-column-one-half"> <p class="govuk-!-text-align-right govuk-grid-column-one-half">
<%= reset_filters_link(@filter_type, { search: request.params["search"] }.compact) %> <%= reset_filters_link(@filter_type, { search: request.params["search"], organisation_id: @organisation&.id }.compact) %>
</p> </p>
</div> </div>
<% if bulk_upload_options(@bulk_upload).present? %> <% if bulk_upload_options(@bulk_upload).present? %>

4
app/views/schemes/_scheme_filters.html.erb

@ -5,13 +5,13 @@
</div> </div>
<div class="app-filter__content"> <div class="app-filter__content">
<%= form_with url: schemes_path, html: { method: :get } do |f| %> <%= form_with url: specific_organisation_path? ? schemes_organisation_path(@organisation) : schemes_path, html: { method: :get } do |f| %>
<div class="govuk-grid-row" style="white-space: nowrap"> <div class="govuk-grid-row" style="white-space: nowrap">
<p class="govuk-grid-column-one-half"> <p class="govuk-grid-column-one-half">
<%= filters_applied_text(@filter_type) %> <%= filters_applied_text(@filter_type) %>
</p> </p>
<p class="govuk-!-text-align-right govuk-grid-column-one-half"> <p class="govuk-!-text-align-right govuk-grid-column-one-half">
<%= reset_filters_link(@filter_type, { search: request.params["search"] }.compact) %> <%= reset_filters_link(@filter_type, { search: request.params["search"], organisation_id: @organisation&.id }.compact) %>
</p> </p>
</div> </div>

4
app/views/users/_user_filters.html.erb

@ -5,13 +5,13 @@
</div> </div>
<div class="app-filter__content"> <div class="app-filter__content">
<%= form_with url: users_path, html: { method: :get } do |f| %> <%= form_with url: specific_organisation_path? ? users_organisation_path(@organisation) : users_path, html: { method: :get } do |f| %>
<div class="govuk-grid-row" style="white-space: nowrap"> <div class="govuk-grid-row" style="white-space: nowrap">
<p class="govuk-grid-column-one-half"> <p class="govuk-grid-column-one-half">
<%= filters_applied_text(@filter_type) %> <%= filters_applied_text(@filter_type) %>
</p> </p>
<p class="govuk-!-text-align-right govuk-grid-column-one-half"> <p class="govuk-!-text-align-right govuk-grid-column-one-half">
<%= reset_filters_link(@filter_type, { search: request.params["search"] }.compact) %> <%= reset_filters_link(@filter_type, { search: request.params["search"], organisation_id: @organisation&.id }.compact) %>
</p> </p>
</div> </div>

2
config/locales/devise.en.yml

@ -62,7 +62,7 @@ en:
messages: messages:
already_confirmed: "Email has already been confirmed. Sign in." already_confirmed: "Email has already been confirmed. Sign in."
blank: "can’t be blank" blank: "can’t be blank"
confirmation: "Password confirmation doesn’t match new password" confirmation: "The passwords you entered do not match. Try again."
confirmation_period_expired: "Email needs to be confirmed within %{period}. Request a new link below." confirmation_period_expired: "Email needs to be confirmed within %{period}. Request a new link below."
expired: "Token has expired. Request a new token." expired: "Token has expired. Request a new token."
not_found: "was not found" not_found: "was not found"

4
config/locales/en.yml

@ -164,7 +164,9 @@ en:
blank: "Select role" blank: "Select role"
password: password:
blank: Enter a password blank: Enter a password
too_short: Password is too short (minimum is %{count} characters) too_short: The password you entered is too short. Enter a password that is %{count} characters or longer.
reset_password_token:
invalid: "That link is invalid. Check you are using the correct link."
merge_request: merge_request:
attributes: attributes:
absorbing_organisation_id: absorbing_organisation_id:

2
spec/features/schemes_spec.rb

@ -81,7 +81,7 @@ RSpec.describe "Schemes scheme Features" do
it "displays the filters component with a correct count and clear button" do it "displays the filters component with a correct count and clear button" do
expect(page).to have_content("2 filters applied") expect(page).to have_content("2 filters applied")
expect(page).to have_link("Clear", href: "/clear-filters?filter_type=schemes") expect(page).to have_link("Clear", href: /clear-filters\?filter_type=schemes/)
end end
context "when clearing the filters" do context "when clearing the filters" do

4
spec/features/user_spec.rb

@ -252,7 +252,7 @@ RSpec.describe "User Features" do
context "when no filters are selected" do context "when no filters are selected" do
it "displays the filters component with no clear button" do it "displays the filters component with no clear button" do
expect(page).to have_content("No filters applied") expect(page).to have_content("No filters applied")
expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=users") expect(page).not_to have_link("Clear", href: /clear-filters\?filter_type=users/)
end end
end end
@ -265,7 +265,7 @@ RSpec.describe "User Features" do
it "displays the filters component with a correct count and clear button" do it "displays the filters component with a correct count and clear button" do
expect(page).to have_content("2 filters applied") expect(page).to have_content("2 filters applied")
expect(page).to have_link("Clear", href: "/clear-filters?filter_type=users") expect(page).to have_link("Clear", href: /clear-filters\?filter_type=users/)
end end
context "when clearing the filters" do context "when clearing the filters" do

25
spec/helpers/schemes_helper_spec.rb

@ -266,6 +266,31 @@ RSpec.describe SchemesHelper do
end end
end end
end end
context "when scheme has no secondary client group" do
before do
scheme.update!(has_other_client_group: 0)
end
it "returns correct display attributes" do
attributes = [
{ name: "Scheme code", value: "S#{scheme.id}" },
{ name: "Name", value: "Test service_name", edit: true },
{ name: "Status", value: status_tag(:incomplete) },
{ name: "Confidential information", value: "No", edit: true },
{ name: "Type of scheme", value: "Housing for older people" },
{ name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" },
{ name: "Housing stock owned by", value: "Acme LTD Owning", edit: true },
{ name: "Support services provided by", value: "A registered charity or voluntary organisation" },
{ name: "Primary client group", value: "Rough sleepers" },
{ name: "Has another client group", value: "No" },
{ name: "Level of support given", value: "High level" },
{ name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2021" },
]
expect(display_scheme_attributes(scheme)).to eq(attributes)
end
end
end end
describe "edit_scheme_text" do describe "edit_scheme_text" do

39
spec/lib/tasks/blank_migrated_soctenant_values_spec.rb

@ -30,21 +30,30 @@ RSpec.describe "blank_migrated_soctenant_values" do
expect(sales_log.values_updated_at).not_to be_nil expect(sales_log.values_updated_at).not_to be_nil
end end
it "does not blank soctenant (and subsequent questions) values from 2022 logs" do context "with 2022 logs" do
sales_log.old_id = "404" around do |example|
sales_log.frombeds = nil Timecop.freeze(Time.zone.local(2022, 5, 5)) do
sales_log.fromprop = 0 # don't know Singleton.__init__(FormHandler)
sales_log.socprevten = 10 # don't know example.run
sales_log.soctenant = 0 # don't know end
sales_log.saledate = Time.zone.local(2022, 5, 5) end
sales_log.save!
task.invoke it "does not blank soctenant (and subsequent questions) values" do
sales_log.reload sales_log.old_id = "404"
expect(sales_log.soctenant).to eq(0) sales_log.frombeds = nil
expect(sales_log.frombeds).to eq(nil) sales_log.fromprop = 0 # don't know
expect(sales_log.fromprop).to eq(0) sales_log.socprevten = 10 # don't know
expect(sales_log.socprevten).to eq(10) sales_log.soctenant = 0 # don't know
expect(sales_log.values_updated_at).to be_nil sales_log.saledate = Time.zone.local(2022, 5, 5)
sales_log.save!
task.invoke
sales_log.reload
expect(sales_log.soctenant).to eq(0)
expect(sales_log.frombeds).to eq(nil)
expect(sales_log.fromprop).to eq(0)
expect(sales_log.socprevten).to eq(10)
expect(sales_log.values_updated_at).to be_nil
end
end end
it "does not blank soctenant (and subsequent questions) values from non imported logs" do it "does not blank soctenant (and subsequent questions) values from non imported logs" do

11
spec/models/lettings_log_spec.rb

@ -1576,7 +1576,7 @@ RSpec.describe LettingsLog do
expect { lettings_log.update!(renewal: 1) }.to change(lettings_log, :underoccupation_benefitcap).to 2 expect { lettings_log.update!(renewal: 1) }.to change(lettings_log, :underoccupation_benefitcap).to 2
Timecop.return Timecop.return
Singleton.__init__(FormHandler) Singleton.__init__(FormHandler)
expect { lettings_log.update!(startdate: Time.zone.local(2023, 1, 1)) }.to change(lettings_log, :underoccupation_benefitcap).from(2).to nil expect { lettings_log.update!(startdate: Time.zone.local(2023, 4, 1)) }.to change(lettings_log, :underoccupation_benefitcap).from(2).to nil
end end
context "when the log is general needs" do context "when the log is general needs" do
@ -2122,10 +2122,15 @@ RSpec.describe LettingsLog do
context "and the location no local authorities associated with the location_code" do context "and the location no local authorities associated with the location_code" do
before do before do
Timecop.freeze(Time.zone.local(2022, 4, 2))
location.update!(location_code: "E01231231") location.update!(location_code: "E01231231")
lettings_log.update!(location:) lettings_log.update!(location:)
end end
after do
Timecop.return
end
it "returns the correct la" do it "returns the correct la" do
expect(location.location_code).to eq("E01231231") expect(location.location_code).to eq("E01231231")
expect(lettings_log["location_id"]).to eq(location.id) expect(lettings_log["location_id"]).to eq(location.id)
@ -2334,7 +2339,7 @@ RSpec.describe LettingsLog do
end end
end end
context "when saledate is before 2023" do context "when startdate is before 2023" do
let(:lettings_log) { build(:lettings_log, startdate: Time.zone.parse("2022-07-01")) } let(:lettings_log) { build(:lettings_log, startdate: Time.zone.parse("2022-07-01")) }
it "returns optional fields" do it "returns optional fields" do
@ -2347,7 +2352,7 @@ RSpec.describe LettingsLog do
end end
end end
context "when saledate is after 2023" do context "when startdate is after 2023" do
let(:lettings_log) { build(:lettings_log, startdate: Time.zone.parse("2023-07-01")) } let(:lettings_log) { build(:lettings_log, startdate: Time.zone.parse("2023-07-01")) }
it "returns optional fields" do it "returns optional fields" do

2
spec/models/scheme_spec.rb

@ -77,6 +77,8 @@ RSpec.describe Scheme, type: :model do
it "returns case insensitive matching records" do it "returns case insensitive matching records" do
expect(described_class.search_by(scheme_1.id.to_s).count).to eq(1) expect(described_class.search_by(scheme_1.id.to_s).count).to eq(1)
expect(described_class.search_by("S#{scheme_1.id}").count).to eq(1)
expect(described_class.search_by("s#{scheme_1.id}").count).to eq(1)
expect(described_class.search_by(scheme_1.id.to_s).first.id).to eq(scheme_1.id) expect(described_class.search_by(scheme_1.id.to_s).first.id).to eq(scheme_1.id)
expect(described_class.search_by(scheme_2.service_name.upcase).count).to eq(1) expect(described_class.search_by(scheme_2.service_name.upcase).count).to eq(1)
expect(described_class.search_by(scheme_2.service_name.downcase).count).to eq(1) expect(described_class.search_by(scheme_2.service_name.downcase).count).to eq(1)

2
spec/requests/auth/passwords_controller_spec.rb

@ -107,7 +107,7 @@ RSpec.describe Auth::PasswordsController, type: :request do
put "/account/password", headers: headers, params: params put "/account/password", headers: headers, params: params
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_css("h1", text: "Reset your password") expect(page).to have_css("h1", text: "Reset your password")
expect(page).to have_content("doesn’t match new password") expect(page).to have_content("passwords you entered do not match")
end end
end end

32
spec/requests/duplicate_logs_controller_spec.rb

@ -717,13 +717,13 @@ RSpec.describe DuplicateLogsController, type: :request do
before do before do
allow(Organisation).to receive(:find).with(user.organisation_id.to_s).and_return(user.organisation) allow(Organisation).to receive(:find).with(user.organisation_id.to_s).and_return(user.organisation)
allow(user.organisation).to receive(:duplicate_lettings_logs_sets).and_return([[1, 2], [3, 4, 5]]) allow(user.organisation).to receive(:editable_duplicate_lettings_logs_sets).and_return([[1, 2], [3, 4, 5]])
allow(user.organisation).to receive(:duplicate_sales_logs_sets).and_return([[11, 12]]) allow(user.organisation).to receive(:editable_duplicate_sales_logs_sets).and_return([[11, 12]])
end end
it "gets organisation duplicates" do it "gets organisation duplicates" do
expect(user.organisation).to receive(:duplicate_lettings_logs_sets) expect(user.organisation).to receive(:editable_duplicate_lettings_logs_sets)
expect(user.organisation).to receive(:duplicate_sales_logs_sets) expect(user.organisation).to receive(:editable_duplicate_sales_logs_sets)
get organisation_duplicates_path(organisation_id: user.organisation_id) get organisation_duplicates_path(organisation_id: user.organisation_id)
end end
@ -759,8 +759,8 @@ RSpec.describe DuplicateLogsController, type: :request do
context "when there are no duplicate logs" do context "when there are no duplicate logs" do
before do before do
allow(Organisation).to receive(:find).with(user.organisation_id.to_s).and_return(user.organisation) allow(Organisation).to receive(:find).with(user.organisation_id.to_s).and_return(user.organisation)
allow(user.organisation).to receive(:duplicate_lettings_logs_sets).and_return([]) allow(user.organisation).to receive(:editable_duplicate_lettings_logs_sets).and_return([])
allow(user.organisation).to receive(:duplicate_sales_logs_sets).and_return([]) allow(user.organisation).to receive(:editable_duplicate_sales_logs_sets).and_return([])
get organisation_duplicates_path(organisation_id: user.organisation_id) get organisation_duplicates_path(organisation_id: user.organisation_id)
end end
@ -780,13 +780,13 @@ RSpec.describe DuplicateLogsController, type: :request do
let(:user) { create(:user, :data_coordinator) } let(:user) { create(:user, :data_coordinator) }
before do before do
allow(user.organisation).to receive(:duplicate_lettings_logs_sets).and_return([[1, 2], [3, 4, 5]]) allow(user.organisation).to receive(:editable_duplicate_lettings_logs_sets).and_return([[1, 2], [3, 4, 5]])
allow(user.organisation).to receive(:duplicate_sales_logs_sets).and_return([[11, 12]]) allow(user.organisation).to receive(:editable_duplicate_sales_logs_sets).and_return([[11, 12]])
end end
it "gets organisation duplicates" do it "gets organisation duplicates" do
expect(user.organisation).to receive(:duplicate_lettings_logs_sets) expect(user.organisation).to receive(:editable_duplicate_lettings_logs_sets)
expect(user.organisation).to receive(:duplicate_sales_logs_sets) expect(user.organisation).to receive(:editable_duplicate_sales_logs_sets)
get duplicate_logs_path(organisation_id: user.organisation.id) get duplicate_logs_path(organisation_id: user.organisation.id)
end end
end end
@ -795,13 +795,13 @@ RSpec.describe DuplicateLogsController, type: :request do
let(:user) { create(:user) } let(:user) { create(:user) }
before do before do
allow(user).to receive(:duplicate_lettings_logs_sets).and_return([[1, 2], [3, 4, 5]]) allow(user).to receive(:editable_duplicate_lettings_logs_sets).and_return([[1, 2], [3, 4, 5]])
allow(user).to receive(:duplicate_sales_logs_sets).and_return([[11, 12]]) allow(user).to receive(:editable_duplicate_sales_logs_sets).and_return([[11, 12]])
end end
it "calls the helper method to retrieve duplicates for the current user" do it "calls the helper method to retrieve duplicates for the current user" do
expect(user).to receive(:duplicate_lettings_logs_sets) expect(user).to receive(:editable_duplicate_lettings_logs_sets)
expect(user).to receive(:duplicate_sales_logs_sets) expect(user).to receive(:editable_duplicate_sales_logs_sets)
get duplicate_logs_path get duplicate_logs_path
end end
@ -836,8 +836,8 @@ RSpec.describe DuplicateLogsController, type: :request do
context "when there are no duplicate logs" do context "when there are no duplicate logs" do
before do before do
allow(user).to receive(:duplicate_lettings_logs_sets).and_return([]) allow(user).to receive(:editable_duplicate_lettings_logs_sets).and_return([])
allow(user).to receive(:duplicate_sales_logs_sets).and_return([]) allow(user).to receive(:editable_duplicate_sales_logs_sets).and_return([])
get duplicate_logs_path get duplicate_logs_path
end end

9
spec/requests/form_controller_spec.rb

@ -254,6 +254,15 @@ RSpec.describe FormController, type: :request do
end end
describe "GET" do describe "GET" do
around do |example|
Timecop.freeze(Time.zone.local(2022, 5, 1)) do
Singleton.__init__(FormHandler)
example.run
end
Timecop.return
Singleton.__init__(FormHandler)
end
context "with form pages" do context "with form pages" do
context "when forms exist" do context "when forms exist" do
let(:lettings_log) { create(:lettings_log, :setup_completed, startdate: Time.zone.local(2022, 5, 1), owning_organisation: organisation, created_by: user) } let(:lettings_log) { create(:lettings_log, :setup_completed, startdate: Time.zone.local(2022, 5, 1), owning_organisation: organisation, created_by: user) }

35
spec/requests/lettings_logs_controller_spec.rb

@ -889,14 +889,12 @@ RSpec.describe LettingsLogsController, type: :request do
end end
context "and there are duplicate logs for this user" do context "and there are duplicate logs for this user" do
before do let!(:duplicate_logs) { FactoryBot.create_list(:lettings_log, 2, :duplicate, owning_organisation: user.organisation, created_by: user) }
FactoryBot.create_list(:lettings_log, 2, :duplicate, owning_organisation: user.organisation, created_by: user)
end
it "displays a notification banner with a link to review logs" do it "displays a notification banner with a link to review logs" do
get lettings_logs_path get lettings_logs_path
expect(page).to have_content "duplicate logs" expect(page).to have_content "duplicate logs"
expect(page).to have_link "Review logs" # add an href when routing done expect(page).to have_link "Review logs", href: "/duplicate-logs?referrer=duplicate_logs_banner"
end end
context "when there is one set of duplicates" do context "when there is one set of duplicates" do
@ -904,6 +902,20 @@ RSpec.describe LettingsLogsController, type: :request do
get lettings_logs_path get lettings_logs_path
expect(page).to have_content "There is 1 set of duplicate logs" expect(page).to have_content "There is 1 set of duplicate logs"
end end
context "when the set is not editable" do
before do
duplicate_logs.each do |log|
log.startdate = Time.zone.now - 3.years
log.save!(validate: false)
end
end
it "does not display the banner" do
get lettings_logs_path
expect(page).not_to have_content "duplicate logs"
end
end
end end
context "when there are multiple sets of duplicates" do context "when there are multiple sets of duplicates" do
@ -914,6 +926,21 @@ RSpec.describe LettingsLogsController, type: :request do
it "displays the correct copy in the banner" do it "displays the correct copy in the banner" do
get lettings_logs_path get lettings_logs_path
expect(page).to have_content "There are 2 sets of duplicate logs" expect(page).to have_content "There are 2 sets of duplicate logs"
expect(page).to have_link "Review logs", href: "/duplicate-logs?referrer=duplicate_logs_banner"
end
context "when one set is not editable" do
before do
log = duplicate_logs.first
log.startdate = Time.zone.now - 3.years
log.save!(validate: false)
end
it "displays the correct copy in the banner" do
get lettings_logs_path
expect(page).to have_content "There is 1 set of duplicate logs"
expect(page).to have_link "Review logs", href: "/duplicate-logs?referrer=duplicate_logs_banner"
end
end end
end end
end end

10
spec/requests/organisations_controller_spec.rb

@ -1440,6 +1440,16 @@ RSpec.describe OrganisationsController, type: :request do
}.to enqueue_job(EmailCsvJob).with(user, nil, {}, false, organisation, codes_only_export_type) }.to enqueue_job(EmailCsvJob).with(user, nil, {}, false, organisation, codes_only_export_type)
end end
end end
context "when filters are applied" do
before do
get lettings_logs_organisation_path(organisation, status: %w[completed])
end
it "has clear filters link" do
expect(page).to have_link("Clear", href: clear_filters_path(filter_type: "lettings_logs", path_params: { organisation_id: organisation.id }))
end
end
end end
context "when they view the sales logs tab" do context "when they view the sales logs tab" do

75
spec/requests/sales_logs_controller_spec.rb

@ -235,6 +235,18 @@ RSpec.describe SalesLogsController, type: :request do
expect(page).to have_link("Download (CSV, codes only)", href: "/sales-logs/csv-download?codes_only=true") expect(page).to have_link("Download (CSV, codes only)", href: "/sales-logs/csv-download?codes_only=true")
end end
context "when there are duplicate logs for this user" do
before do
FactoryBot.create_list(:sales_log, 2, :duplicate, owning_organisation: user.organisation, created_by: user)
end
it "does not show a notification banner even if there are duplicate logs for this user" do
get sales_logs_path
expect(page).not_to have_content "duplicate logs"
expect(page).not_to have_link "Review logs"
end
end
context "when there are no logs in the database" do context "when there are no logs in the database" do
before do before do
SalesLog.destroy_all SalesLog.destroy_all
@ -566,6 +578,12 @@ RSpec.describe SalesLogsController, type: :request do
expect(page).not_to have_link("Download (CSV, codes only)") expect(page).not_to have_link("Download (CSV, codes only)")
end end
it "does not show a notification banner even if there are duplicate logs for this user" do
get sales_logs_path
expect(page).not_to have_content "duplicate logs"
expect(page).not_to have_link "Review logs"
end
context "when using a search query" do context "when using a search query" do
let(:logs) { FactoryBot.create_list(:sales_log, 3, :completed, owning_organisation: user.organisation, created_by: user) } let(:logs) { FactoryBot.create_list(:sales_log, 3, :completed, owning_organisation: user.organisation, created_by: user) }
let(:log_to_search) { FactoryBot.create(:sales_log, :completed, owning_organisation: user.organisation, created_by: user) } let(:log_to_search) { FactoryBot.create(:sales_log, :completed, owning_organisation: user.organisation, created_by: user) }
@ -727,6 +745,63 @@ RSpec.describe SalesLogsController, type: :request do
end end
end end
end end
context "and there are duplicate logs for this user" do
let!(:duplicate_logs) { FactoryBot.create_list(:lettings_log, 2, :duplicate, owning_organisation: user.organisation, created_by: user) }
it "displays a notification banner with a link to review logs" do
get sales_logs_path
expect(page).to have_content "duplicate logs"
expect(page).to have_link "Review logs", href: "/duplicate-logs?referrer=duplicate_logs_banner"
end
context "when there is one set of duplicates" do
it "displays the correct copy in the banner" do
get sales_logs_path
expect(page).to have_content "There is 1 set of duplicate logs"
end
context "when the set is not editable" do
before do
duplicate_logs.each do |log|
log.startdate = Time.zone.now - 3.years
log.save!(validate: false)
end
end
it "does not display the banner" do
get sales_logs_path
expect(page).not_to have_content "duplicate logs"
end
end
end
context "when there are multiple sets of duplicates" do
before do
FactoryBot.create_list(:sales_log, 2, :duplicate, owning_organisation: user.organisation, created_by: user)
end
it "displays the correct copy in the banner" do
get sales_logs_path
expect(page).to have_content "There are 2 sets of duplicate logs"
expect(page).to have_link "Review logs", href: "/duplicate-logs?referrer=duplicate_logs_banner"
end
context "when one set is not editable" do
before do
log = duplicate_logs.first
log.startdate = Time.zone.now - 3.years
log.save!(validate: false)
end
it "displays the correct copy in the banner" do
get sales_logs_path
expect(page).to have_content "There is 1 set of duplicate logs"
expect(page).to have_link "Review logs", href: "/duplicate-logs?referrer=duplicate_logs_banner"
end
end
end
end
end end
end end

2
spec/requests/users_controller_spec.rb

@ -67,7 +67,7 @@ RSpec.describe UsersController, type: :request do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_css("h1", class: "govuk-heading-l", text: "Change your password") expect(page).to have_css("h1", class: "govuk-heading-l", text: "Change your password")
expect(page).to have_selector("#error-summary-title") expect(page).to have_selector("#error-summary-title")
expect(page).to have_content("Password confirmation doesn’t match new password") expect(page).to have_content("passwords you entered do not match")
end end
end end
end end

7
spec/services/bulk_upload/lettings/log_creator_spec.rb

@ -9,6 +9,13 @@ RSpec.describe BulkUpload::Lettings::LogCreator do
let(:bulk_upload) { create(:bulk_upload, :lettings, user:) } let(:bulk_upload) { create(:bulk_upload, :lettings, user:) }
let(:path) { file_fixture("2022_23_lettings_bulk_upload.csv") } let(:path) { file_fixture("2022_23_lettings_bulk_upload.csv") }
around do |example|
Timecop.freeze(Time.zone.local(2023, 1, 1)) do
Singleton.__init__(FormHandler)
example.run
end
end
describe "#call" do describe "#call" do
context "when a valid csv with new log" do context "when a valid csv with new log" do
it "creates a new log" do it "creates a new log" do

7
spec/services/bulk_upload/lettings/validator_spec.rb

@ -10,6 +10,13 @@ RSpec.describe BulkUpload::Lettings::Validator do
let(:path) { file.path } let(:path) { file.path }
let(:file) { Tempfile.new } let(:file) { Tempfile.new }
around do |example|
Timecop.freeze(Date.new(2023, 10, 1)) do
example.run
end
Timecop.return
end
describe "validations" do describe "validations" do
context "when 2022" do context "when 2022" do
let(:bulk_upload) { create(:bulk_upload, user:, year: 2022) } let(:bulk_upload) { create(:bulk_upload, user:, year: 2022) }

9
spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb

@ -153,11 +153,14 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
end end
around do |example| around do |example|
FormHandler.instance.use_real_forms! Timecop.freeze(Date.new(2023, 3, 1)) do
FormHandler.instance.use_real_forms!
example.run example.run
FormHandler.instance.use_fake_forms! FormHandler.instance.use_fake_forms!
end
Timecop.return
end end
describe "#blank_row?" do describe "#blank_row?" do

8
spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

@ -47,9 +47,11 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end end
around do |example| around do |example|
FormHandler.instance.use_real_forms! Timecop.freeze(Date.new(2023, 10, 1)) do
FormHandler.instance.use_real_forms!
example.run example.run
end
Timecop.return
end end
describe "#blank_row?" do describe "#blank_row?" do

7
spec/services/bulk_upload/processor_spec.rb

@ -7,6 +7,13 @@ RSpec.describe BulkUpload::Processor do
let(:user) { create(:user, organisation: owning_org) } let(:user) { create(:user, organisation: owning_org) }
let(:owning_org) { create(:organisation, old_visible_id: 123) } let(:owning_org) { create(:organisation, old_visible_id: 123) }
around do |example|
Timecop.freeze(Time.utc(2023, 1, 1)) do
Singleton.__init__(FormHandler)
example.run
end
end
describe "#call" do describe "#call" do
context "when errors exist from prior job run" do context "when errors exist from prior job run" do
let!(:existing_error) { create(:bulk_upload_error, bulk_upload:) } let!(:existing_error) { create(:bulk_upload_error, bulk_upload:) }

4
spec/services/bulk_upload/sales/year2023/row_parser_spec.rb

@ -3,7 +3,7 @@ require "rails_helper"
RSpec.describe BulkUpload::Sales::Year2023::RowParser do RSpec.describe BulkUpload::Sales::Year2023::RowParser do
subject(:parser) { described_class.new(attributes) } subject(:parser) { described_class.new(attributes) }
let(:now) { Time.zone.parse("01/03/2023") } let(:now) { Time.zone.parse("01/05/2023") }
let(:attributes) { { bulk_upload: } } let(:attributes) { { bulk_upload: } }
let(:bulk_upload) { create(:bulk_upload, :sales, user:, year: 2023) } let(:bulk_upload) { create(:bulk_upload, :sales, user:, year: 2023) }
@ -760,7 +760,7 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
let(:attributes) { setup_section_params.merge({ field_19: "3", data[:field] => nil }) } let(:attributes) { setup_section_params.merge({ field_19: "3", data[:field] => nil }) }
it "cannot be blank" do it "cannot be blank" do
expect(parser.errors[data[:field]]).not_to be_blank expect(parser.errors[data[:field]]).to be_present
end end
end end
end end

7
spec/services/csv/missing_addresses_csv_service_spec.rb

@ -38,6 +38,13 @@ RSpec.describe Csv::MissingAddressesCsvService do
.to_return(status: 200, body: body_2, headers: {}) .to_return(status: 200, body: body_2, headers: {})
end end
around do |example|
Timecop.freeze(Time.zone.local(2023, 4, 5)) do
Singleton.__init__(FormHandler)
example.run
end
end
def replace_entity_ids(lettings_log, export_template) def replace_entity_ids(lettings_log, export_template)
export_template.sub!(/\{id\}/, lettings_log.id.to_s) export_template.sub!(/\{id\}/, lettings_log.id.to_s)
end end

7
spec/services/imports/sales_logs_field_import_service_spec.rb

@ -27,6 +27,13 @@ RSpec.describe Imports::SalesLogsFieldImportService do
.and_return(sales_log_file) .and_return(sales_log_file)
end end
around do |example|
Timecop.freeze(Time.zone.local(2023, 1, 17)) do
Singleton.__init__(FormHandler)
example.run
end
end
context "when updating creation method" do context "when updating creation method" do
let(:field) { "creation_method" } let(:field) { "creation_method" }
let(:sales_log) { SalesLog.find_by(old_id: sales_log_filename) } let(:sales_log) { SalesLog.find_by(old_id: sales_log_filename) }

Loading…
Cancel
Save