diff --git a/.github/workflows/review_pipeline.yml b/.github/workflows/review_pipeline.yml index 1e7ae0efb..5656898bc 100644 --- a/.github/workflows/review_pipeline.yml +++ b/.github/workflows/review_pipeline.yml @@ -72,6 +72,9 @@ jobs: runs-on: ubuntu-latest environment: staging needs: [postgres, redis] + permissions: + issues: write + pull-requests: write steps: - name: Checkout code diff --git a/Gemfile b/Gemfile index b20b7fe97..f77a70899 100644 --- a/Gemfile +++ b/Gemfile @@ -68,6 +68,7 @@ group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem "byebug", platforms: %i[mri mingw x64_mingw] gem "dotenv-rails" + gem "factory_bot_rails" gem "pry-byebug" gem "parallel_tests" @@ -90,7 +91,6 @@ end group :test do gem "capybara", require: false gem "capybara-lockstep" - gem "factory_bot_rails" gem "faker" gem "rspec-rails", require: false gem "selenium-webdriver", require: false diff --git a/app/helpers/collection_time_helper.rb b/app/helpers/collection_time_helper.rb index 8478d06e7..be0abae20 100644 --- a/app/helpers/collection_time_helper.rb +++ b/app/helpers/collection_time_helper.rb @@ -1,16 +1,26 @@ 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 - today = Time.zone.now - window_end_date = Time.zone.local(today.year, 4, 1) - today < window_end_date ? today.year - 1 : today.year + collection_start_year(Time.zone.now) end def collection_start_date(date) - window_end_date = Time.zone.local(date.year, 4, 1) - date < window_end_date ? Time.zone.local(date.year - 1, 4, 1) : Time.zone.local(date.year, 4, 1) + Time.zone.local(collection_start_year(date), 4, 1) end def current_collection_start_date Time.zone.local(current_collection_start_year, 4, 1) 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 diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb index a1875081c..7f906b4ea 100644 --- a/app/helpers/filters_helper.rb +++ b/app/helpers/filters_helper.rb @@ -27,4 +27,12 @@ module FiltersHelper 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) } 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 diff --git a/app/helpers/tasklist_helper.rb b/app/helpers/tasklist_helper.rb index f297de2ff..f4f1d51dd 100644 --- a/app/helpers/tasklist_helper.rb +++ b/app/helpers/tasklist_helper.rb @@ -39,7 +39,9 @@ module TasklistHelper def review_log_text(log) 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 "This log is from the #{log.form.start_date.year}/#{log.form.start_date.year + 1} collection window, which is now closed." end diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb index 96b937ab4..7d664e48f 100644 --- a/app/models/derived_variables/lettings_log_variables.rb +++ b/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.referral = 1 self.waityear = 2 + self.offered = 0 + self.voiddate = startdate + self.first_time_property_let_as_social_housing = 0 if is_general_needs? # fixed term self.prevten = 32 if managing_organisation&.provider_type == "PRP" @@ -60,7 +63,6 @@ module DerivedVariables::LettingsLogVariables if is_supported_housing? && location self.wchair = location.mobility_type_before_type_cast == "W" ? 1 : 2 end - self.voiddate = startdate if is_renewal? self.vacdays = property_vacant_days set_housingneeds_fields if housingneeds? diff --git a/app/models/form/lettings/questions/working_situation1.rb b/app/models/form/lettings/questions/working_situation1.rb index 866271f4d..20f5dc984 100644 --- a/app/models/form/lettings/questions/working_situation1.rb +++ b/app/models/form/lettings/questions/working_situation1.rb @@ -11,8 +11,8 @@ class Form::Lettings::Questions::WorkingSituation1 < ::Form::Question end ANSWER_OPTIONS = { - "2" => { "value" => "Part-time – Less than 30 hours" }, "1" => { "value" => "Full-time – 30 hours or more" }, + "2" => { "value" => "Part-time – Less than 30 hours" }, "7" => { "value" => "Full-time student" }, "3" => { "value" => "In government training into work, such as New Deal" }, "4" => { "value" => "Jobseeker" }, diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 66f622270..02236f70b 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -70,6 +70,14 @@ class LettingsLog < Log collection_start_year end + def lettings? + true + end + + def sales? + false + end + def form_name return unless startdate @@ -481,10 +489,6 @@ class LettingsLog < Log location.type_of_unit_before_type_cast if location end - def lettings? - true - end - def rent_type_detail form.get_question("rent_type", self)&.label_from_value(rent_type) end diff --git a/app/models/log.rb b/app/models/log.rb index 1b43fd1cb..0cd3add92 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -43,6 +43,10 @@ class Log < ApplicationRecord false end + def sales? + false + end + def ethnic_refused? ethnic_group == 17 end diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index add706f7c..6ed653955 100644 --- a/app/models/sales_log.rb +++ b/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 RETIREMENT_AGES = { "M" => 65, "F" => 60, "X" => 65 }.freeze + def lettings? + false + end + + def sales? + true + end + def startdate saledate end diff --git a/app/services/bulk_upload/lettings/row_parser.rb b/app/services/bulk_upload/lettings/row_parser.rb index bf1f62eba..005d5caf9 100644 --- a/app/services/bulk_upload/lettings/row_parser.rb +++ b/app/services/bulk_upload/lettings/row_parser.rb @@ -147,7 +147,7 @@ class BulkUpload::Lettings::RowParser validate :validate_nulls validate :validate_relevant_collection_window 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_lettings_type_matches_bulk_upload validate :validate_only_one_housing_needs_type @@ -219,8 +219,8 @@ private end end - def validate_cannot_be_la_referral_if_general_needs - if field_78 == 4 && bulk_upload.general_needs? + def validate_cannot_be_la_referral_if_general_needs_and_la + 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") end end diff --git a/app/services/exports/lettings_log_export_constants.rb b/app/services/exports/lettings_log_export_constants.rb index 332f22550..3ae7d71fa 100644 --- a/app/services/exports/lettings_log_export_constants.rb +++ b/app/services/exports/lettings_log_export_constants.rb @@ -7,13 +7,6 @@ module Exports::LettingsLogExportConstants csv: 2, }.freeze - QUARTERS = { - 0 => "jan_mar", - 1 => "apr_jun", - 2 => "jul_sep", - 3 => "oct_dec", - }.freeze - EXPORT_FIELDS = Set[ "armedforces", "beds", diff --git a/app/services/exports/lettings_log_export_service.rb b/app/services/exports/lettings_log_export_service.rb index fb985f931..197e0ed4b 100644 --- a/app/services/exports/lettings_log_export_service.rb +++ b/app/services/exports/lettings_log_export_service.rb @@ -1,6 +1,7 @@ module Exports class LettingsLogExportService include Exports::LettingsLogExportConstants + include CollectionTimeHelper def initialize(storage_service, logger = Rails.logger) @storage_service = storage_service @@ -66,11 +67,11 @@ module Exports return unless lettings_log.startdate collection_start = lettings_log.collection_start_year - month = lettings_log.startdate.month - quarter = QUARTERS[(month - 1) / 3] + start_month = collection_start_date(lettings_log.startdate).strftime("%b") + end_month = collection_end_date(lettings_log.startdate).strftime("%b") base_number_str = "f#{base_number.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 def write_export_archive(export, lettings_logs) diff --git a/app/views/form/review.html.erb b/app/views/form/review.html.erb index a95b577bd..bc46c89d8 100644 --- a/app/views/form/review.html.erb +++ b/app/views/form/review.html.erb @@ -1,9 +1,18 @@ -<% content_for :title, "Review lettings log" %> -<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { - "Logs" => "/logs", - "Log #{@log.id}" => "/lettings-logs/#{@log.id}", - "Review lettings log" => "", -}) %> +<% 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 :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { + "Logs" => "/logs", + "Log #{@log.id}" => "/lettings-logs/#{@log.id}", + "Review lettings log" => "", + }) %> +<% end %>
@@ -16,17 +25,16 @@ <% @log.form.sections.map do |section| %>

<%= section.label %>

<% section.subsections.map do |subsection| %> -
-
-

<%= subsection.label %>

+ <% if total_applicable_questions(subsection, @log, current_user).any? %> +
+
+

<%= subsection.label %>

+
+
+ <%= render partial: "form/check_answers_summary_list", locals: { subsection: } %> +
-
- <%= render partial: "form/check_answers_summary_list", locals: { - subsection:, - lettings_log: @log, - } %> -
-
+ <% end %> <% end %> <% end %>
diff --git a/app/views/logs/_log_filters.erb b/app/views/logs/_log_filters.erb index 8fb4f2ba4..a1aa752c3 100644 --- a/app/views/logs/_log_filters.erb +++ b/app/views/logs/_log_filters.erb @@ -6,7 +6,6 @@
<%= form_with html: { method: :get } do |f| %> - <% years = { "2021": "2021/22", "2022": "2022/23" } %> <% all_or_yours = { "all": { label: "All" }, "yours": { label: "Yours" } } %> <% if bulk_upload_options(@bulk_upload).present? %> @@ -23,7 +22,7 @@ <%= render partial: "filters/checkbox_filter", locals: { f: f, - options: years, + options: collection_year_options, label: "Collection year", category: "years", } %> diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc index 69dad9f7a..c9d564782 100644 --- a/config/credentials.yml.enc +++ b/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== \ No newline at end of file +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== \ No newline at end of file diff --git a/config/initializers/feature_toggle.rb b/config/initializers/feature_toggle.rb index de00a8fc9..39c607804 100644 --- a/config/initializers/feature_toggle.rb +++ b/config/initializers/feature_toggle.rb @@ -1,10 +1,10 @@ class FeatureToggle def self.startdate_two_week_validation_enabled? - Rails.env.production? || Rails.env.test? + Rails.env.production? || Rails.env.test? || Rails.env.staging? end def self.saledate_collection_window_validation_enabled? - Rails.env.production? || Rails.env.test? + Rails.env.production? || Rails.env.test? || Rails.env.staging? end def self.sales_log_enabled? @@ -38,4 +38,8 @@ class FeatureToggle def self.validate_valid_radio_options? !(Rails.env.production? || Rails.env.staging?) end + + def self.collection_2023_2024_year_enabled? + !Rails.env.production? + end end diff --git a/config/routes.rb b/config/routes.rb index be765c8c0..74b613989 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -171,6 +171,10 @@ Rails.application.routes.draw do resources :bulk_upload_sales_results, path: "bulk-upload-results", only: [:show] end + member do + get "review", to: "form#review" + end + FormHandler.instance.sales_forms.each do |_key, form| form.pages.map do |page| get page.id.to_s.dasherize, to: "form#show_page" diff --git a/docs/Gemfile.lock b/docs/Gemfile.lock index 8d38e2e0a..c8a433b8f 100644 --- a/docs/Gemfile.lock +++ b/docs/Gemfile.lock @@ -1,12 +1,11 @@ GEM remote: https://rubygems.org/ specs: - activesupport (6.0.6) + activesupport (7.0.4.2) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.2, >= 2.2.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) addressable (2.8.1) public_suffix (>= 2.0.2, < 6.0) coffee-script (2.4.1) @@ -14,30 +13,30 @@ GEM execjs coffee-script-source (1.11.1) colorator (1.1.0) - commonmarker (0.23.6) - concurrent-ruby (1.1.10) + commonmarker (0.23.8) + concurrent-ruby (1.2.0) dnsruby (1.61.9) simpleidn (~> 0.1) em-websocket (0.5.3) eventmachine (>= 0.12.9) http_parser.rb (~> 0) - ethon (0.15.0) + ethon (0.16.0) ffi (>= 1.15.0) eventmachine (1.2.7) execjs (2.8.1) - faraday (2.5.2) + faraday (2.7.4) faraday-net_http (>= 2.0, < 3.1) ruby2_keywords (>= 0.0.4) - faraday-net_http (3.0.0) + faraday-net_http (3.0.2) ffi (1.15.5) forwardable-extended (2.6.0) gemoji (3.0.1) - github-pages (227) + github-pages (228) github-pages-health-check (= 1.17.9) - jekyll (= 3.9.2) + jekyll (= 3.9.3) jekyll-avatar (= 0.7.0) jekyll-coffeescript (= 1.1.1) - jekyll-commonmark-ghpages (= 0.2.0) + jekyll-commonmark-ghpages (= 0.4.0) jekyll-default-layout (= 0.1.4) jekyll-feed (= 0.15.1) jekyll-gist (= 1.5.0) @@ -71,7 +70,7 @@ GEM jemoji (= 0.12.0) kramdown (= 2.3.2) kramdown-parser-gfm (= 1.1.0) - liquid (= 4.0.3) + liquid (= 4.0.4) mercenary (~> 0.3) minima (= 2.5.1) nokogiri (>= 1.13.6, < 2.0) @@ -83,17 +82,17 @@ GEM octokit (~> 4.0) public_suffix (>= 3.0, < 5.0) typhoeus (~> 1.3) - html-pipeline (2.14.2) + html-pipeline (2.14.3) activesupport (>= 2) nokogiri (>= 1.4) http_parser.rb (0.8.0) - i18n (0.9.5) + i18n (1.12.0) concurrent-ruby (~> 1.0) - jekyll (3.9.2) + jekyll (3.9.3) addressable (~> 2.4) colorator (~> 1.0) em-websocket (~> 0.5) - i18n (~> 0.7) + i18n (>= 0.7, < 2) jekyll-sass-converter (~> 1.0) jekyll-watch (~> 2.0) kramdown (>= 1.17, < 3) @@ -109,11 +108,11 @@ GEM coffee-script-source (~> 1.11.1) jekyll-commonmark (1.4.0) commonmarker (~> 0.22) - jekyll-commonmark-ghpages (0.2.0) - commonmarker (~> 0.23.4) + jekyll-commonmark-ghpages (0.4.0) + commonmarker (~> 0.23.7) jekyll (~> 3.9.0) jekyll-commonmark (~> 1.4.0) - rouge (>= 2.0, < 4.0) + rouge (>= 2.0, < 5.0) jekyll-default-layout (0.1.4) jekyll (~> 3.0) jekyll-feed (0.15.1) @@ -201,8 +200,8 @@ GEM rexml kramdown-parser-gfm (1.1.0) kramdown (~> 2.0) - liquid (4.0.3) - listen (3.7.1) + liquid (4.0.4) + listen (3.8.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) mercenary (0.3.6) @@ -210,12 +209,12 @@ GEM jekyll (>= 3.5, < 5.0) jekyll-feed (~> 0.9) jekyll-seo-tag (~> 2.1) - minitest (5.16.3) - nokogiri (1.13.10-arm64-darwin) + minitest (5.17.0) + nokogiri (1.14.2-arm64-darwin) racc (~> 1.4) - nokogiri (1.13.10-x86_64-darwin) + nokogiri (1.14.2-x86_64-darwin) racc (~> 1.4) - nokogiri (1.13.10-x86_64-linux) + nokogiri (1.14.2-x86_64-linux) racc (~> 1.4) octokit (4.25.1) faraday (>= 1, < 3) @@ -223,7 +222,7 @@ GEM pathutil (0.16.2) forwardable-extended (~> 2.6) public_suffix (4.0.7) - racc (1.6.1) + racc (1.6.2) rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) @@ -244,17 +243,15 @@ GEM unf (~> 0.1.4) terminal-table (1.8.0) unicode-display_width (~> 1.1, >= 1.1.1) - thread_safe (0.3.6) typhoeus (1.4.0) ethon (>= 0.9.0) - tzinfo (1.2.10) - thread_safe (~> 0.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) unf (0.1.4) unf_ext unf_ext (0.0.8.2) unicode-display_width (1.8.0) - webrick (1.7.0) - zeitwerk (2.6.0) + webrick (1.8.1) PLATFORMS arm64-darwin-21 diff --git a/lib/tasks/data_export.rake b/lib/tasks/data_export.rake index 17f258293..a86712d83 100644 --- a/lib/tasks/data_export.rake +++ b/lib/tasks/data_export.rake @@ -11,21 +11,3 @@ namespace :core do DataExportXmlJob.perform_later(full_update:) 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 diff --git a/spec/factories/organisation.rb b/spec/factories/organisation.rb index 147f847d6..7aee3ad66 100644 --- a/spec/factories/organisation.rb +++ b/spec/factories/organisation.rb @@ -13,6 +13,10 @@ FactoryBot.define do trait :with_old_visible_id do old_visible_id { rand(9_999_999).to_s } end + + trait :prp do + provider_type { "PRP" } + end end factory :organisation_rent_period do diff --git a/spec/helpers/collection_time_helper_spec.rb b/spec/helpers/collection_time_helper_spec.rb index 3b02802f2..c2eb2fedb 100644 --- a/spec/helpers/collection_time_helper_spec.rb +++ b/spec/helpers/collection_time_helper_spec.rb @@ -21,6 +21,10 @@ RSpec.describe CollectionTimeHelper do it "returns the correct current start date" do expect(current_collection_start_date).to eq(Time.zone.local(2022, 4, 1)) end + + it "returns the correct current end date" do + expect(current_collection_end_date).to eq(Time.zone.local(2023, 3, 31)) + end end 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 expect(current_collection_start_year).to eq(2021) 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 diff --git a/spec/helpers/filters_helper_spec.rb b/spec/helpers/filters_helper_spec.rb index 656578326..3eccac743 100644 --- a/spec/helpers/filters_helper_spec.rb +++ b/spec/helpers/filters_helper_spec.rb @@ -116,4 +116,30 @@ RSpec.describe FiltersHelper do 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 diff --git a/spec/helpers/tasklist_helper_spec.rb b/spec/helpers/tasklist_helper_spec.rb index f7726745d..e14e06ea4 100644 --- a/spec/helpers/tasklist_helper_spec.rb +++ b/spec/helpers/tasklist_helper_spec.rb @@ -136,7 +136,7 @@ RSpec.describe TasklistHelper do it "returns relevant text" do 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 diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index c8cdc466e..d4bbd8378 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -18,6 +18,11 @@ RSpec.describe LettingsLog do expect(described_class).to be < ApplicationRecord 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 lettings_log = FactoryBot.build(:lettings_log, created_by: created_by_user) expect(lettings_log).to be_lettings @@ -1454,6 +1459,15 @@ RSpec.describe LettingsLog do expect(record_from_db["vacdays"]).to eq(0) expect(lettings_log["vacdays"]).to eq(0) 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 context "when answering the household characteristics questions" do @@ -1946,12 +1960,12 @@ RSpec.describe LettingsLog do end 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 - lettings_log.update!({ offered: 4 }) + lettings_log.update!({ unitletas: 1 }) lettings_log.reload - expect(lettings_log.offered).to eq(4) + expect(lettings_log.unitletas).to eq(1) end end diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb index 42bf9d4cd..523c2924b 100644 --- a/spec/models/sales_log_spec.rb +++ b/spec/models/sales_log_spec.rb @@ -12,11 +12,16 @@ RSpec.describe SalesLog, type: :model do expect(described_class).to be < ApplicationRecord 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) expect(sales_log.lettings?).to be false 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 context "when creating a record" do let(:sales_log) do diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index dcf67cb71..d5a8dbcf8 100644 --- a/spec/requests/form_controller_spec.rb +++ b/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: {} expect(response.body).to match("Review lettings log") 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 context "when viewing a user dependent page" do diff --git a/spec/services/bulk_upload/lettings/row_parser_spec.rb b/spec/services/bulk_upload/lettings/row_parser_spec.rb index 1bebd6444..4c0788033 100644 --- a/spec/services/bulk_upload/lettings/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/row_parser_spec.rb @@ -396,14 +396,24 @@ RSpec.describe BulkUpload::Lettings::RowParser do end end - context "when 4 ie referred by LA and is general needs" do - let(:attributes) { { bulk_upload:, field_78: "4" } } + context "when 4 ie referred by LA and is general needs and owning org is LA" do + let(:attributes) { { bulk_upload:, field_78: "4", field_111: owning_org.old_visible_id.to_s } } it "is not permitted" do expect(parser.errors[:field_78]).to be_present 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 let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: 2) } let(:attributes) { { bulk_upload:, field_78: "4" } } diff --git a/spec/services/exports/lettings_log_export_service_spec.rb b/spec/services/exports/lettings_log_export_service_spec.rb index 36adda071..55897c354 100644 --- a/spec/services/exports/lettings_log_export_service_spec.rb +++ b/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_rerun) { "Manifest_2022_05_01_0002.csv" } - let(:expected_zip_filename) { "core_2021_2022_jan_mar_f0001_inc0001.zip" } - let(:expected_data_filename) { "core_2021_2022_jan_mar_f0001_inc0001_pt001.xml" } + let(:expected_zip_filename) { "core_2021_2022_apr_mar_f0001_inc0001.zip" } + let(:expected_data_filename) { "core_2021_2022_apr_mar_f0001_inc0001_pt001.xml" } let(:expected_manifest_filename) { "manifest.xml" } let(:start_time) { Time.zone.local(2022, 5, 1) } @@ -108,7 +108,7 @@ RSpec.describe Exports::LettingsLogExportService do end 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 FactoryBot.create(:lettings_log, startdate: Time.zone.local(2022, 2, 1)) @@ -206,7 +206,7 @@ RSpec.describe Exports::LettingsLogExportService do end 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) end end