Browse Source

Merge remote-tracking branch 'origin/CLDC-1917-allow-23/24-form' into CLDC-1917-allow-23/24-form

CLDC-1917-allow-23/24-form
natdeanlewissoftwire 2 years ago
parent
commit
3d15283e43
  1. 3
      .github/workflows/review_pipeline.yml
  2. 2
      Gemfile
  3. 20
      app/helpers/collection_time_helper.rb
  4. 8
      app/helpers/filters_helper.rb
  5. 4
      app/helpers/tasklist_helper.rb
  6. 4
      app/models/derived_variables/lettings_log_variables.rb
  7. 2
      app/models/form/lettings/questions/working_situation1.rb
  8. 12
      app/models/lettings_log.rb
  9. 4
      app/models/log.rb
  10. 8
      app/models/sales_log.rb
  11. 6
      app/services/bulk_upload/lettings/row_parser.rb
  12. 7
      app/services/exports/lettings_log_export_constants.rb
  13. 7
      app/services/exports/lettings_log_export_service.rb
  14. 16
      app/views/form/review.html.erb
  15. 3
      app/views/logs/_log_filters.erb
  16. 2
      config/credentials.yml.enc
  17. 8
      config/initializers/feature_toggle.rb
  18. 4
      config/routes.rb
  19. 63
      docs/Gemfile.lock
  20. 18
      lib/tasks/data_export.rake
  21. 4
      spec/factories/organisation.rb
  22. 46
      spec/helpers/collection_time_helper_spec.rb
  23. 26
      spec/helpers/filters_helper_spec.rb
  24. 2
      spec/helpers/tasklist_helper_spec.rb
  25. 20
      spec/models/lettings_log_spec.rb
  26. 7
      spec/models/sales_log_spec.rb
  27. 6
      spec/requests/form_controller_spec.rb
  28. 14
      spec/services/bulk_upload/lettings/row_parser_spec.rb
  29. 8
      spec/services/exports/lettings_log_export_service_spec.rb

3
.github/workflows/review_pipeline.yml

@ -72,6 +72,9 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
environment: staging environment: staging
needs: [postgres, redis] needs: [postgres, redis]
permissions:
issues: write
pull-requests: write
steps: steps:
- name: Checkout code - name: Checkout code

2
Gemfile

@ -68,6 +68,7 @@ group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console # Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem "byebug", platforms: %i[mri mingw x64_mingw] gem "byebug", platforms: %i[mri mingw x64_mingw]
gem "dotenv-rails" gem "dotenv-rails"
gem "factory_bot_rails"
gem "pry-byebug" gem "pry-byebug"
gem "parallel_tests" gem "parallel_tests"
@ -90,7 +91,6 @@ end
group :test do group :test do
gem "capybara", require: false gem "capybara", require: false
gem "capybara-lockstep" gem "capybara-lockstep"
gem "factory_bot_rails"
gem "faker" gem "faker"
gem "rspec-rails", require: false gem "rspec-rails", require: false
gem "selenium-webdriver", require: false gem "selenium-webdriver", require: false

20
app/helpers/collection_time_helper.rb

@ -1,16 +1,26 @@
module CollectionTimeHelper module CollectionTimeHelper
def collection_start_year(date)
window_end_date = Time.zone.local(date.year, 4, 1)
date < window_end_date ? date.year - 1 : date.year
end
def current_collection_start_year def current_collection_start_year
today = Time.zone.now collection_start_year(Time.zone.now)
window_end_date = Time.zone.local(today.year, 4, 1)
today < window_end_date ? today.year - 1 : today.year
end end
def collection_start_date(date) def collection_start_date(date)
window_end_date = Time.zone.local(date.year, 4, 1) Time.zone.local(collection_start_year(date), 4, 1)
date < window_end_date ? Time.zone.local(date.year - 1, 4, 1) : Time.zone.local(date.year, 4, 1)
end end
def current_collection_start_date def current_collection_start_date
Time.zone.local(current_collection_start_year, 4, 1) Time.zone.local(current_collection_start_year, 4, 1)
end end
def collection_end_date(date)
Time.zone.local(collection_start_year(date) + 1, 3, 31)
end
def current_collection_end_date
Time.zone.local(current_collection_start_year + 1, 3, 31)
end
end end

8
app/helpers/filters_helper.rb

@ -27,4 +27,12 @@ module FiltersHelper
organisation_options = user.support? ? Organisation.all : [user.organisation] + user.organisation.managing_agents organisation_options = user.support? ? Organisation.all : [user.organisation] + user.organisation.managing_agents
[OpenStruct.new(id: "", name: "Select an option")] + organisation_options.map { |org| OpenStruct.new(id: org.id, name: org.name) } [OpenStruct.new(id: "", name: "Select an option")] + organisation_options.map { |org| OpenStruct.new(id: org.id, name: org.name) }
end end
def collection_year_options
if FeatureToggle.collection_2023_2024_year_enabled?
{ "2023": "2023/24", "2022": "2022/23", "2021": "2021/22" }
else
{ "2022": "2022/23", "2021": "2021/22" }
end
end
end end

4
app/helpers/tasklist_helper.rb

@ -39,7 +39,9 @@ module TasklistHelper
def review_log_text(log) def review_log_text(log)
if log.collection_period_open? if log.collection_period_open?
"You can #{govuk_link_to 'review and make changes to this log', review_lettings_log_path(log)} until #{log.form.end_date.to_formatted_s(:govuk_date)}.".html_safe link = log.sales? ? review_sales_log_path(id: log, sales_log: true) : review_lettings_log_path(log)
"You can #{govuk_link_to 'review and make changes to this log', link} until #{log.form.end_date.to_formatted_s(:govuk_date)}.".html_safe
else else
"This log is from the #{log.form.start_date.year}/#{log.form.start_date.year + 1} collection window, which is now closed." "This log is from the #{log.form.start_date.year}/#{log.form.start_date.year + 1} collection window, which is now closed."
end end

4
app/models/derived_variables/lettings_log_variables.rb

@ -45,6 +45,9 @@ module DerivedVariables::LettingsLogVariables
self.underoccupation_benefitcap = 2 if collection_start_year == 2021 self.underoccupation_benefitcap = 2 if collection_start_year == 2021
self.referral = 1 self.referral = 1
self.waityear = 2 self.waityear = 2
self.offered = 0
self.voiddate = startdate
self.first_time_property_let_as_social_housing = 0
if is_general_needs? if is_general_needs?
# fixed term # fixed term
self.prevten = 32 if managing_organisation&.provider_type == "PRP" self.prevten = 32 if managing_organisation&.provider_type == "PRP"
@ -60,7 +63,6 @@ module DerivedVariables::LettingsLogVariables
if is_supported_housing? && location if is_supported_housing? && location
self.wchair = location.mobility_type_before_type_cast == "W" ? 1 : 2 self.wchair = location.mobility_type_before_type_cast == "W" ? 1 : 2
end end
self.voiddate = startdate if is_renewal?
self.vacdays = property_vacant_days self.vacdays = property_vacant_days
set_housingneeds_fields if housingneeds? set_housingneeds_fields if housingneeds?

2
app/models/form/lettings/questions/working_situation1.rb

@ -11,8 +11,8 @@ class Form::Lettings::Questions::WorkingSituation1 < ::Form::Question
end end
ANSWER_OPTIONS = { ANSWER_OPTIONS = {
"2" => { "value" => "Part-time – Less than 30 hours" },
"1" => { "value" => "Full-time – 30 hours or more" }, "1" => { "value" => "Full-time – 30 hours or more" },
"2" => { "value" => "Part-time – Less than 30 hours" },
"7" => { "value" => "Full-time student" }, "7" => { "value" => "Full-time student" },
"3" => { "value" => "In government training into work, such as New Deal" }, "3" => { "value" => "In government training into work, such as New Deal" },
"4" => { "value" => "Jobseeker" }, "4" => { "value" => "Jobseeker" },

12
app/models/lettings_log.rb

@ -70,6 +70,14 @@ class LettingsLog < Log
collection_start_year collection_start_year
end end
def lettings?
true
end
def sales?
false
end
def form_name def form_name
return unless startdate return unless startdate
@ -481,10 +489,6 @@ class LettingsLog < Log
location.type_of_unit_before_type_cast if location location.type_of_unit_before_type_cast if location
end end
def lettings?
true
end
def rent_type_detail def rent_type_detail
form.get_question("rent_type", self)&.label_from_value(rent_type) form.get_question("rent_type", self)&.label_from_value(rent_type)
end end

4
app/models/log.rb

@ -43,6 +43,10 @@ class Log < ApplicationRecord
false false
end end
def sales?
false
end
def ethnic_refused? def ethnic_refused?
ethnic_group == 17 ethnic_group == 17
end end

8
app/models/sales_log.rb

@ -38,6 +38,14 @@ class SalesLog < Log
OPTIONAL_FIELDS = %w[saledate_check purchid monthly_charges_value_check old_persons_shared_ownership_value_check].freeze OPTIONAL_FIELDS = %w[saledate_check purchid monthly_charges_value_check old_persons_shared_ownership_value_check].freeze
RETIREMENT_AGES = { "M" => 65, "F" => 60, "X" => 65 }.freeze RETIREMENT_AGES = { "M" => 65, "F" => 60, "X" => 65 }.freeze
def lettings?
false
end
def sales?
true
end
def startdate def startdate
saledate saledate
end end

6
app/services/bulk_upload/lettings/row_parser.rb

@ -147,7 +147,7 @@ class BulkUpload::Lettings::RowParser
validate :validate_nulls validate :validate_nulls
validate :validate_relevant_collection_window validate :validate_relevant_collection_window
validate :validate_la_with_local_housing_referral validate :validate_la_with_local_housing_referral
validate :validate_cannot_be_la_referral_if_general_needs validate :validate_cannot_be_la_referral_if_general_needs_and_la
validate :validate_leaving_reason_for_renewal validate :validate_leaving_reason_for_renewal
validate :validate_lettings_type_matches_bulk_upload validate :validate_lettings_type_matches_bulk_upload
validate :validate_only_one_housing_needs_type validate :validate_only_one_housing_needs_type
@ -219,8 +219,8 @@ private
end end
end end
def validate_cannot_be_la_referral_if_general_needs def validate_cannot_be_la_referral_if_general_needs_and_la
if field_78 == 4 && bulk_upload.general_needs? if field_78 == 4 && bulk_upload.general_needs? && owning_organisation && owning_organisation.la?
errors.add :field_78, I18n.t("validations.household.referral.la_general_needs.prp_referred_by_la") errors.add :field_78, I18n.t("validations.household.referral.la_general_needs.prp_referred_by_la")
end end
end end

7
app/services/exports/lettings_log_export_constants.rb

@ -7,13 +7,6 @@ module Exports::LettingsLogExportConstants
csv: 2, csv: 2,
}.freeze }.freeze
QUARTERS = {
0 => "jan_mar",
1 => "apr_jun",
2 => "jul_sep",
3 => "oct_dec",
}.freeze
EXPORT_FIELDS = Set[ EXPORT_FIELDS = Set[
"armedforces", "armedforces",
"beds", "beds",

7
app/services/exports/lettings_log_export_service.rb

@ -1,6 +1,7 @@
module Exports module Exports
class LettingsLogExportService class LettingsLogExportService
include Exports::LettingsLogExportConstants include Exports::LettingsLogExportConstants
include CollectionTimeHelper
def initialize(storage_service, logger = Rails.logger) def initialize(storage_service, logger = Rails.logger)
@storage_service = storage_service @storage_service = storage_service
@ -66,11 +67,11 @@ module Exports
return unless lettings_log.startdate return unless lettings_log.startdate
collection_start = lettings_log.collection_start_year collection_start = lettings_log.collection_start_year
month = lettings_log.startdate.month start_month = collection_start_date(lettings_log.startdate).strftime("%b")
quarter = QUARTERS[(month - 1) / 3] end_month = collection_end_date(lettings_log.startdate).strftime("%b")
base_number_str = "f#{base_number.to_s.rjust(4, '0')}" base_number_str = "f#{base_number.to_s.rjust(4, '0')}"
increment_str = "inc#{increment.to_s.rjust(4, '0')}" increment_str = "inc#{increment.to_s.rjust(4, '0')}"
"core_#{collection_start}_#{collection_start + 1}_#{quarter}_#{base_number_str}_#{increment_str}" "core_#{collection_start}_#{collection_start + 1}_#{start_month}_#{end_month}_#{base_number_str}_#{increment_str}".downcase
end end
def write_export_archive(export, lettings_logs) def write_export_archive(export, lettings_logs)

16
app/views/form/review.html.erb

@ -1,9 +1,18 @@
<% if @log.sales? %>
<% content_for :title, "Review sales log" %>
<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
"Logs" => "/logs",
"Log #{@log.id}" => "/sales-logs/#{@log.id}",
"Review sales log" => "",
}) %>
<% else %>
<% content_for :title, "Review lettings log" %> <% content_for :title, "Review lettings log" %>
<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { <% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
"Logs" => "/logs", "Logs" => "/logs",
"Log #{@log.id}" => "/lettings-logs/#{@log.id}", "Log #{@log.id}" => "/lettings-logs/#{@log.id}",
"Review lettings log" => "", "Review lettings log" => "",
}) %> }) %>
<% end %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop"> <div class="govuk-grid-column-two-thirds-from-desktop">
@ -16,18 +25,17 @@
<% @log.form.sections.map do |section| %> <% @log.form.sections.map do |section| %>
<h2 class="govuk-heading-m"><%= section.label %></h2> <h2 class="govuk-heading-m"><%= section.label %></h2>
<% section.subsections.map do |subsection| %> <% section.subsections.map do |subsection| %>
<% if total_applicable_questions(subsection, @log, current_user).any? %>
<div class="x-govuk-summary-card govuk-!-margin-bottom-6"> <div class="x-govuk-summary-card govuk-!-margin-bottom-6">
<div class="x-govuk-summary-card__header"> <div class="x-govuk-summary-card__header">
<h3 class="x-govuk-summary-card__title"><%= subsection.label %></h3> <h3 class="x-govuk-summary-card__title"><%= subsection.label %></h3>
</div> </div>
<div class="x-govuk-summary-card__body"> <div class="x-govuk-summary-card__body">
<%= render partial: "form/check_answers_summary_list", locals: { <%= render partial: "form/check_answers_summary_list", locals: { subsection: } %>
subsection:,
lettings_log: @log,
} %>
</div> </div>
</div> </div>
<% end %> <% end %>
<% end %> <% end %>
<% end %>
</div> </div>
</div> </div>

3
app/views/logs/_log_filters.erb

@ -6,7 +6,6 @@
<div class="app-filter__content"> <div class="app-filter__content">
<%= form_with html: { method: :get } do |f| %> <%= form_with html: { method: :get } do |f| %>
<% years = { "2021": "2021/22", "2022": "2022/23" } %>
<% all_or_yours = { "all": { label: "All" }, "yours": { label: "Yours" } } %> <% all_or_yours = { "all": { label: "All" }, "yours": { label: "Yours" } } %>
<% if bulk_upload_options(@bulk_upload).present? %> <% if bulk_upload_options(@bulk_upload).present? %>
@ -23,7 +22,7 @@
<%= render partial: "filters/checkbox_filter", <%= render partial: "filters/checkbox_filter",
locals: { locals: {
f: f, f: f,
options: years, options: collection_year_options,
label: "Collection year", label: "Collection year",
category: "years", category: "years",
} %> } %>

2
config/credentials.yml.enc

@ -1 +1 @@
PWC9A1AmalyFv4A63MG9jCm2YtwE1Eyu1BJKodtbmq2nW7FD9svZZ3V4yC0JO9J8sLfCS6UrxQC4TOKKYWP5iYpOr5TKPi9MqNCVueLsoErN+nMAPhCJVpl8+eJ4BOvNYGlmle4bcwbAvHLq6IoANTBjktFh5/tgJS+IHBWK1FwPzK1eAhgQ1fE1jluWslee4iYesmh+ufHIMZAkoWuGJVky4i4uN5nKnwQfaPN5MUxBlvGiDH+s+yex4pcIaJ6hxYWAQRZXJRQVpZcf/agwU0Tk/S/fuDMm8zVeHCQkkmsCYzH5czB8b8IWYwyslqFBZNCix7YnbgwgYk8MUh7wPBuF8CFoPKVyteqic9HgUp9KY8kkt/RcWJ4zpv+Vwz3cre+iZ3S1bxFcSxXqO0MGRug2H9iwhAnBQDLl3vXLNNRYEL5LhNv0Z9Cy7at1fnYe1FcvF+3DR9kG/RAYzR8S2eEDdzBl797+DG81yhfkjP3/gfWxD+J+Mx0F4SDEOaGK5c/MqNTdiRRbnhzuRaQFMg6itoJbZybe+EOQScNft1QLqC4QwPd4Qevhj/A=--QffpsNB1u+1Lk/tD--spkCqBIGHl8g6HGwd89yCg== EZNV2LiNWzf52erbQ41Dz3Bh+2f3Uih8liEyhXp5XzHCLzAbmN6/IJqr7b9cTZiCiroFo4n/dFoG3yYrospp3frKsDXxF1K2/MTCJWjpgnn7wc+HiPQWG0W3HRtQCNkyyrHes0YKcYyDWIP6kztYv1I/Me3p0pGEx6t3CpSTg1v46eRnOlDWiUz3rVxPauwq9IYZ75gmnThqvg/Z8wcYsWLx0arago0SXtRPASCNj4uO/lbqTcAfyIXOTSiOlcAIjoPFRSQY7UqY0o2p8jRR/1L16SmGDsk8ijm+UygNmMexa3Khy5WcKctpQICakHs4NRjHNflqgXpXKL9dVBmNc9d7h+gbhbGJQ53Y0d+a35UbhPRMiv4SRH98FwB+WEsLCDdGSHvdmM6ArfOLljTrqrsmSRf0JfUrvzyVYmMCxjv4xgJwUS/TD5lQD1yPwkp2ss00kQJqzNmB7qwFhA8a3e2iNzV8qtAV/Nj+tMlr99Hb7vZZs98/38G2p5RAsE/5Xl9taKhc/ACnVc/bwJND4JWaBB7duCa08xVB8nkjlt5cCwMurzAcy1ZT+e8JepR+g6s8fpScMEWVJXE0hd8=--rZ41rY9TMXmiBUJw--QiLRVNVXZzTW446s7cec1g==

8
config/initializers/feature_toggle.rb

@ -1,10 +1,10 @@
class FeatureToggle class FeatureToggle
def self.startdate_two_week_validation_enabled? def self.startdate_two_week_validation_enabled?
Rails.env.production? || Rails.env.test? Rails.env.production? || Rails.env.test? || Rails.env.staging?
end end
def self.saledate_collection_window_validation_enabled? def self.saledate_collection_window_validation_enabled?
Rails.env.production? || Rails.env.test? Rails.env.production? || Rails.env.test? || Rails.env.staging?
end end
def self.sales_log_enabled? def self.sales_log_enabled?
@ -38,4 +38,8 @@ class FeatureToggle
def self.validate_valid_radio_options? def self.validate_valid_radio_options?
!(Rails.env.production? || Rails.env.staging?) !(Rails.env.production? || Rails.env.staging?)
end end
def self.collection_2023_2024_year_enabled?
!Rails.env.production?
end
end end

4
config/routes.rb

@ -171,6 +171,10 @@ Rails.application.routes.draw do
resources :bulk_upload_sales_results, path: "bulk-upload-results", only: [:show] resources :bulk_upload_sales_results, path: "bulk-upload-results", only: [:show]
end end
member do
get "review", to: "form#review"
end
FormHandler.instance.sales_forms.each do |_key, form| FormHandler.instance.sales_forms.each do |_key, form|
form.pages.map do |page| form.pages.map do |page|
get page.id.to_s.dasherize, to: "form#show_page" get page.id.to_s.dasherize, to: "form#show_page"

63
docs/Gemfile.lock

@ -1,12 +1,11 @@
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
activesupport (6.0.6) activesupport (7.0.4.2)
concurrent-ruby (~> 1.0, >= 1.0.2) concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2) i18n (>= 1.6, < 2)
minitest (~> 5.1) minitest (>= 5.1)
tzinfo (~> 1.1) tzinfo (~> 2.0)
zeitwerk (~> 2.2, >= 2.2.2)
addressable (2.8.1) addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0) public_suffix (>= 2.0.2, < 6.0)
coffee-script (2.4.1) coffee-script (2.4.1)
@ -14,30 +13,30 @@ GEM
execjs execjs
coffee-script-source (1.11.1) coffee-script-source (1.11.1)
colorator (1.1.0) colorator (1.1.0)
commonmarker (0.23.6) commonmarker (0.23.8)
concurrent-ruby (1.1.10) concurrent-ruby (1.2.0)
dnsruby (1.61.9) dnsruby (1.61.9)
simpleidn (~> 0.1) simpleidn (~> 0.1)
em-websocket (0.5.3) em-websocket (0.5.3)
eventmachine (>= 0.12.9) eventmachine (>= 0.12.9)
http_parser.rb (~> 0) http_parser.rb (~> 0)
ethon (0.15.0) ethon (0.16.0)
ffi (>= 1.15.0) ffi (>= 1.15.0)
eventmachine (1.2.7) eventmachine (1.2.7)
execjs (2.8.1) execjs (2.8.1)
faraday (2.5.2) faraday (2.7.4)
faraday-net_http (>= 2.0, < 3.1) faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4) ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.0) faraday-net_http (3.0.2)
ffi (1.15.5) ffi (1.15.5)
forwardable-extended (2.6.0) forwardable-extended (2.6.0)
gemoji (3.0.1) gemoji (3.0.1)
github-pages (227) github-pages (228)
github-pages-health-check (= 1.17.9) github-pages-health-check (= 1.17.9)
jekyll (= 3.9.2) jekyll (= 3.9.3)
jekyll-avatar (= 0.7.0) jekyll-avatar (= 0.7.0)
jekyll-coffeescript (= 1.1.1) jekyll-coffeescript (= 1.1.1)
jekyll-commonmark-ghpages (= 0.2.0) jekyll-commonmark-ghpages (= 0.4.0)
jekyll-default-layout (= 0.1.4) jekyll-default-layout (= 0.1.4)
jekyll-feed (= 0.15.1) jekyll-feed (= 0.15.1)
jekyll-gist (= 1.5.0) jekyll-gist (= 1.5.0)
@ -71,7 +70,7 @@ GEM
jemoji (= 0.12.0) jemoji (= 0.12.0)
kramdown (= 2.3.2) kramdown (= 2.3.2)
kramdown-parser-gfm (= 1.1.0) kramdown-parser-gfm (= 1.1.0)
liquid (= 4.0.3) liquid (= 4.0.4)
mercenary (~> 0.3) mercenary (~> 0.3)
minima (= 2.5.1) minima (= 2.5.1)
nokogiri (>= 1.13.6, < 2.0) nokogiri (>= 1.13.6, < 2.0)
@ -83,17 +82,17 @@ GEM
octokit (~> 4.0) octokit (~> 4.0)
public_suffix (>= 3.0, < 5.0) public_suffix (>= 3.0, < 5.0)
typhoeus (~> 1.3) typhoeus (~> 1.3)
html-pipeline (2.14.2) html-pipeline (2.14.3)
activesupport (>= 2) activesupport (>= 2)
nokogiri (>= 1.4) nokogiri (>= 1.4)
http_parser.rb (0.8.0) http_parser.rb (0.8.0)
i18n (0.9.5) i18n (1.12.0)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
jekyll (3.9.2) jekyll (3.9.3)
addressable (~> 2.4) addressable (~> 2.4)
colorator (~> 1.0) colorator (~> 1.0)
em-websocket (~> 0.5) em-websocket (~> 0.5)
i18n (~> 0.7) i18n (>= 0.7, < 2)
jekyll-sass-converter (~> 1.0) jekyll-sass-converter (~> 1.0)
jekyll-watch (~> 2.0) jekyll-watch (~> 2.0)
kramdown (>= 1.17, < 3) kramdown (>= 1.17, < 3)
@ -109,11 +108,11 @@ GEM
coffee-script-source (~> 1.11.1) coffee-script-source (~> 1.11.1)
jekyll-commonmark (1.4.0) jekyll-commonmark (1.4.0)
commonmarker (~> 0.22) commonmarker (~> 0.22)
jekyll-commonmark-ghpages (0.2.0) jekyll-commonmark-ghpages (0.4.0)
commonmarker (~> 0.23.4) commonmarker (~> 0.23.7)
jekyll (~> 3.9.0) jekyll (~> 3.9.0)
jekyll-commonmark (~> 1.4.0) jekyll-commonmark (~> 1.4.0)
rouge (>= 2.0, < 4.0) rouge (>= 2.0, < 5.0)
jekyll-default-layout (0.1.4) jekyll-default-layout (0.1.4)
jekyll (~> 3.0) jekyll (~> 3.0)
jekyll-feed (0.15.1) jekyll-feed (0.15.1)
@ -201,8 +200,8 @@ GEM
rexml rexml
kramdown-parser-gfm (1.1.0) kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0) kramdown (~> 2.0)
liquid (4.0.3) liquid (4.0.4)
listen (3.7.1) listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3) rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10) rb-inotify (~> 0.9, >= 0.9.10)
mercenary (0.3.6) mercenary (0.3.6)
@ -210,12 +209,12 @@ GEM
jekyll (>= 3.5, < 5.0) jekyll (>= 3.5, < 5.0)
jekyll-feed (~> 0.9) jekyll-feed (~> 0.9)
jekyll-seo-tag (~> 2.1) jekyll-seo-tag (~> 2.1)
minitest (5.16.3) minitest (5.17.0)
nokogiri (1.13.10-arm64-darwin) nokogiri (1.14.2-arm64-darwin)
racc (~> 1.4) racc (~> 1.4)
nokogiri (1.13.10-x86_64-darwin) nokogiri (1.14.2-x86_64-darwin)
racc (~> 1.4) racc (~> 1.4)
nokogiri (1.13.10-x86_64-linux) nokogiri (1.14.2-x86_64-linux)
racc (~> 1.4) racc (~> 1.4)
octokit (4.25.1) octokit (4.25.1)
faraday (>= 1, < 3) faraday (>= 1, < 3)
@ -223,7 +222,7 @@ GEM
pathutil (0.16.2) pathutil (0.16.2)
forwardable-extended (~> 2.6) forwardable-extended (~> 2.6)
public_suffix (4.0.7) public_suffix (4.0.7)
racc (1.6.1) racc (1.6.2)
rb-fsevent (0.11.2) rb-fsevent (0.11.2)
rb-inotify (0.10.1) rb-inotify (0.10.1)
ffi (~> 1.0) ffi (~> 1.0)
@ -244,17 +243,15 @@ GEM
unf (~> 0.1.4) unf (~> 0.1.4)
terminal-table (1.8.0) terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1) unicode-display_width (~> 1.1, >= 1.1.1)
thread_safe (0.3.6)
typhoeus (1.4.0) typhoeus (1.4.0)
ethon (>= 0.9.0) ethon (>= 0.9.0)
tzinfo (1.2.10) tzinfo (2.0.6)
thread_safe (~> 0.1) concurrent-ruby (~> 1.0)
unf (0.1.4) unf (0.1.4)
unf_ext unf_ext
unf_ext (0.0.8.2) unf_ext (0.0.8.2)
unicode-display_width (1.8.0) unicode-display_width (1.8.0)
webrick (1.7.0) webrick (1.8.1)
zeitwerk (2.6.0)
PLATFORMS PLATFORMS
arm64-darwin-21 arm64-darwin-21

18
lib/tasks/data_export.rake

@ -11,21 +11,3 @@ namespace :core do
DataExportXmlJob.perform_later(full_update:) DataExportXmlJob.perform_later(full_update:)
end end
end end
namespace :illness_type_0 do
desc "Export log data where illness_type_0 == 1"
task export: :environment do |_task|
logs = LettingsLog.where(illness_type_0: 1, status: "completed").includes(created_by: :organisation)
puts "log_id,created_by_id,organisation_id,organisation_name,startdate"
logs.each do |log|
puts [
log.id,
log.created_by_id,
log.created_by.organisation.id,
log.created_by.organisation.name,
log.startdate&.strftime("%d/%m/%Y"),
].join(",")
end
end
end

4
spec/factories/organisation.rb

@ -13,6 +13,10 @@ FactoryBot.define do
trait :with_old_visible_id do trait :with_old_visible_id do
old_visible_id { rand(9_999_999).to_s } old_visible_id { rand(9_999_999).to_s }
end end
trait :prp do
provider_type { "PRP" }
end
end end
factory :organisation_rent_period do factory :organisation_rent_period do

46
spec/helpers/collection_time_helper_spec.rb

@ -21,6 +21,10 @@ RSpec.describe CollectionTimeHelper do
it "returns the correct current start date" do it "returns the correct current start date" do
expect(current_collection_start_date).to eq(Time.zone.local(2022, 4, 1)) expect(current_collection_start_date).to eq(Time.zone.local(2022, 4, 1))
end end
it "returns the correct current end date" do
expect(current_collection_end_date).to eq(Time.zone.local(2023, 3, 31))
end
end end
context "with the date before 1st of April" do context "with the date before 1st of April" do
@ -29,6 +33,48 @@ RSpec.describe CollectionTimeHelper do
it "returns the previous year as the current start year" do it "returns the previous year as the current start year" do
expect(current_collection_start_year).to eq(2021) expect(current_collection_start_year).to eq(2021)
end end
it "returns the correct current start date" do
expect(current_collection_start_date).to eq(Time.zone.local(2021, 4, 1))
end
it "returns the correct current end date" do
expect(current_collection_end_date).to eq(Time.zone.local(2022, 3, 31))
end
end
end
describe "Any collection year" do
context "when the date is after 1st of April" do
let(:now) { Time.utc(2022, 8, 3) }
it "returns the same year as the current start year" do
expect(collection_start_year(now)).to eq(2022)
end
it "returns the correct current start date" do
expect(collection_start_date(now)).to eq(Time.zone.local(2022, 4, 1))
end
it "returns the correct current end date" do
expect(collection_end_date(now)).to eq(Time.zone.local(2023, 3, 31))
end
end
context "with the date before 1st of April" do
let(:now) { Time.utc(2022, 2, 3) }
it "returns the previous year as the current start year" do
expect(collection_start_year(now)).to eq(2021)
end
it "returns the correct current start date" do
expect(collection_start_date(now)).to eq(Time.zone.local(2021, 4, 1))
end
it "returns the correct current end date" do
expect(collection_end_date(now)).to eq(Time.zone.local(2022, 3, 31))
end
end end
end end
end end

26
spec/helpers/filters_helper_spec.rb

@ -116,4 +116,30 @@ RSpec.describe FiltersHelper do
end end
end end
end end
describe "#collection_year_options" do
context "when not production" do
it "includes 2023/2024 option" do
expect(collection_year_options).to eq(
{
"2021": "2021/22", "2022": "2022/23", "2023": "2023/24"
},
)
end
end
context "when production" do
before do
allow(Rails.env).to receive(:production?).and_return(true)
end
it "includes 2023/2024 option" do
expect(collection_year_options).to eq(
{
"2021": "2021/22", "2022": "2022/23"
},
)
end
end
end
end end

2
spec/helpers/tasklist_helper_spec.rb

@ -136,7 +136,7 @@ RSpec.describe TasklistHelper do
it "returns relevant text" do it "returns relevant text" do
expect(review_log_text(sales_log)).to eq( expect(review_log_text(sales_log)).to eq(
"You can #{govuk_link_to 'review and make changes to this log', review_lettings_log_path(sales_log)} until 1 July 2023.".html_safe, "You can #{govuk_link_to 'review and make changes to this log', review_sales_log_path(id: sales_log, sales_log: true)} until 1 July 2023.".html_safe,
) )
end end
end end

20
spec/models/lettings_log_spec.rb

@ -18,6 +18,11 @@ RSpec.describe LettingsLog do
expect(described_class).to be < ApplicationRecord expect(described_class).to be < ApplicationRecord
end end
it "is a not a sales log" do
lettings_log = FactoryBot.build(:lettings_log, created_by: created_by_user)
expect(lettings_log.sales?).to be false
end
it "is a lettings log" do it "is a lettings log" do
lettings_log = FactoryBot.build(:lettings_log, created_by: created_by_user) lettings_log = FactoryBot.build(:lettings_log, created_by: created_by_user)
expect(lettings_log).to be_lettings expect(lettings_log).to be_lettings
@ -1454,6 +1459,15 @@ RSpec.describe LettingsLog do
expect(record_from_db["vacdays"]).to eq(0) expect(record_from_db["vacdays"]).to eq(0)
expect(lettings_log["vacdays"]).to eq(0) expect(lettings_log["vacdays"]).to eq(0)
end end
it "correctly derives and saves first_time_property_let_as_social_housing" do
record_from_db = ActiveRecord::Base.connection.execute(
"select first_time_property_let_as_social_housing" \
" from lettings_logs where id=#{lettings_log.id}",
).to_a[0]
expect(record_from_db["first_time_property_let_as_social_housing"]).to eq(0)
expect(lettings_log["first_time_property_let_as_social_housing"]).to eq(0)
end
end end
context "when answering the household characteristics questions" do context "when answering the household characteristics questions" do
@ -1946,12 +1960,12 @@ RSpec.describe LettingsLog do
end end
context "when a non select question associated with several pages is routed to" do context "when a non select question associated with several pages is routed to" do
let(:lettings_log) { FactoryBot.create(:lettings_log, :in_progress, period: 2) } let(:lettings_log) { FactoryBot.create(:lettings_log, :in_progress, period: 2, needstype: 1) }
it "does not clear the answer value" do it "does not clear the answer value" do
lettings_log.update!({ offered: 4 }) lettings_log.update!({ unitletas: 1 })
lettings_log.reload lettings_log.reload
expect(lettings_log.offered).to eq(4) expect(lettings_log.unitletas).to eq(1)
end end
end end

7
spec/models/sales_log_spec.rb

@ -12,11 +12,16 @@ RSpec.describe SalesLog, type: :model do
expect(described_class).to be < ApplicationRecord expect(described_class).to be < ApplicationRecord
end end
it "is a sales log" do it "is a not a lettings log" do
sales_log = build(:sales_log, created_by: created_by_user) sales_log = build(:sales_log, created_by: created_by_user)
expect(sales_log.lettings?).to be false expect(sales_log.lettings?).to be false
end end
it "is a sales log" do
sales_log = build(:sales_log, created_by: created_by_user)
expect(sales_log.sales?).to be true
end
describe "#new" do describe "#new" do
context "when creating a record" do context "when creating a record" do
let(:sales_log) do let(:sales_log) do

6
spec/requests/form_controller_spec.rb

@ -314,6 +314,12 @@ RSpec.describe FormController, type: :request do
get "/lettings-logs/#{setup_complete_lettings_log.id}/review", headers: headers, params: {} get "/lettings-logs/#{setup_complete_lettings_log.id}/review", headers: headers, params: {}
expect(response.body).to match("Review lettings log") expect(response.body).to match("Review lettings log")
end end
it "renders the review page for the sales log" do
log = create(:sales_log, :completed, created_by: user)
get "/sales-logs/#{log.id}/review", headers: headers, params: { sales_log: true }
expect(response.body).to match("Review sales log")
end
end end
context "when viewing a user dependent page" do context "when viewing a user dependent page" do

14
spec/services/bulk_upload/lettings/row_parser_spec.rb

@ -396,14 +396,24 @@ RSpec.describe BulkUpload::Lettings::RowParser do
end end
end end
context "when 4 ie referred by LA and is general needs" do context "when 4 ie referred by LA and is general needs and owning org is LA" do
let(:attributes) { { bulk_upload:, field_78: "4" } } let(:attributes) { { bulk_upload:, field_78: "4", field_111: owning_org.old_visible_id.to_s } }
it "is not permitted" do it "is not permitted" do
expect(parser.errors[:field_78]).to be_present expect(parser.errors[:field_78]).to be_present
end end
end end
context "when 4 ie referred by LA and is general needs and owning org is PRP" do
let(:owning_org) { create(:organisation, :prp, :with_old_visible_id) }
let(:attributes) { { bulk_upload:, field_78: "4", field_111: owning_org.old_visible_id.to_s } }
it "is permitted" do
expect(parser.errors[:field_78]).to be_blank
end
end
context "when 4 ie referred by LA and is not general needs" do context "when 4 ie referred by LA and is not general needs" do
let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: 2) } let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: 2) }
let(:attributes) { { bulk_upload:, field_78: "4" } } let(:attributes) { { bulk_upload:, field_78: "4" } }

8
spec/services/exports/lettings_log_export_service_spec.rb

@ -13,8 +13,8 @@ RSpec.describe Exports::LettingsLogExportService do
let(:expected_master_manifest_filename) { "Manifest_2022_05_01_0001.csv" } let(:expected_master_manifest_filename) { "Manifest_2022_05_01_0001.csv" }
let(:expected_master_manifest_rerun) { "Manifest_2022_05_01_0002.csv" } let(:expected_master_manifest_rerun) { "Manifest_2022_05_01_0002.csv" }
let(:expected_zip_filename) { "core_2021_2022_jan_mar_f0001_inc0001.zip" } let(:expected_zip_filename) { "core_2021_2022_apr_mar_f0001_inc0001.zip" }
let(:expected_data_filename) { "core_2021_2022_jan_mar_f0001_inc0001_pt001.xml" } let(:expected_data_filename) { "core_2021_2022_apr_mar_f0001_inc0001_pt001.xml" }
let(:expected_manifest_filename) { "manifest.xml" } let(:expected_manifest_filename) { "manifest.xml" }
let(:start_time) { Time.zone.local(2022, 5, 1) } let(:start_time) { Time.zone.local(2022, 5, 1) }
@ -108,7 +108,7 @@ RSpec.describe Exports::LettingsLogExportService do
end end
context "and multiple lettings logs are available for export on different periods" do context "and multiple lettings logs are available for export on different periods" do
let(:expected_zip_filename2) { "core_2022_2023_apr_jun_f0001_inc0001.zip" } let(:expected_zip_filename2) { "core_2022_2023_apr_mar_f0001_inc0001.zip" }
before do before do
FactoryBot.create(:lettings_log, startdate: Time.zone.local(2022, 2, 1)) FactoryBot.create(:lettings_log, startdate: Time.zone.local(2022, 2, 1))
@ -206,7 +206,7 @@ RSpec.describe Exports::LettingsLogExportService do
end end
it "generates a ZIP export file with the expected filename" do it "generates a ZIP export file with the expected filename" do
expect(storage_service).to receive(:write_file).with("core_2021_2022_jan_mar_f0002_inc0001.zip", any_args) expect(storage_service).to receive(:write_file).with("core_2021_2022_apr_mar_f0002_inc0001.zip", any_args)
export_service.export_xml_lettings_logs(full_update: true) export_service.export_xml_lettings_logs(full_update: true)
end end
end end

Loading…
Cancel
Save