From b6274412e815e6d2cf357bf15ed03ae9a5602ec9 Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 15 Mar 2023 14:45:59 +0000 Subject: [PATCH] Add template question to lettings bulk upload --- .../bulk_upload_lettings_logs_controller.rb | 4 +- .../forms/bulk_upload_lettings/needstype.rb | 3 +- .../bulk_upload_lettings/prepare_your_file.rb | 9 +- .../forms/bulk_upload_lettings/template.rb | 43 +++++++++ .../bulk_upload_lettings/upload_your_file.rb | 11 ++- .../forms/needstype.erb | 1 + .../forms/template.erb | 20 ++++ .../forms/upload_your_file.html.erb | 1 + config/locales/en.yml | 4 + .../20230315113252_add_ordered_template.rb | 7 ++ db/schema.rb | 26 ++++-- .../bulk_upload_lettings_logs_spec.rb | 93 +++++++++++++++++-- .../bulk_upload_lettings/template_spec.rb | 12 +++ 13 files changed, 215 insertions(+), 19 deletions(-) create mode 100644 app/models/forms/bulk_upload_lettings/template.rb create mode 100644 app/views/bulk_upload_lettings_logs/forms/template.erb create mode 100644 db/migrate/20230315113252_add_ordered_template.rb create mode 100644 spec/models/forms/bulk_upload_lettings/template_spec.rb diff --git a/app/controllers/bulk_upload_lettings_logs_controller.rb b/app/controllers/bulk_upload_lettings_logs_controller.rb index 9b37cd2b5..e82a8bdcf 100644 --- a/app/controllers/bulk_upload_lettings_logs_controller.rb +++ b/app/controllers/bulk_upload_lettings_logs_controller.rb @@ -42,6 +42,8 @@ private Forms::BulkUploadLettings::Year.new(form_params) when "prepare-your-file" Forms::BulkUploadLettings::PrepareYourFile.new(form_params) + when "template" + Forms::BulkUploadLettings::Template.new(form_params) when "needstype" Forms::BulkUploadLettings::Needstype.new(form_params) when "upload-your-file" @@ -54,6 +56,6 @@ private end def form_params - params.fetch(:form, {}).permit(:year, :needstype, :file) + params.fetch(:form, {}).permit(:year, :needstype, :ordered_template, :file) end end diff --git a/app/models/forms/bulk_upload_lettings/needstype.rb b/app/models/forms/bulk_upload_lettings/needstype.rb index 0cadd647c..8b7fc6b26 100644 --- a/app/models/forms/bulk_upload_lettings/needstype.rb +++ b/app/models/forms/bulk_upload_lettings/needstype.rb @@ -7,6 +7,7 @@ module Forms attribute :needstype, :integer attribute :year, :integer + attribute :ordered_template, :boolean validates :needstype, presence: true @@ -19,7 +20,7 @@ module Forms end def back_path - bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year:, needstype: }) + bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year:, needstype:, ordered_template: }) end def next_path diff --git a/app/models/forms/bulk_upload_lettings/prepare_your_file.rb b/app/models/forms/bulk_upload_lettings/prepare_your_file.rb index bfaa622b2..79020f79b 100644 --- a/app/models/forms/bulk_upload_lettings/prepare_your_file.rb +++ b/app/models/forms/bulk_upload_lettings/prepare_your_file.rb @@ -7,6 +7,7 @@ module Forms attribute :year, :integer attribute :needstype, :integer + attribute :ordered_template, :boolean def view_path "bulk_upload_lettings_logs/forms/prepare_your_file" @@ -21,7 +22,13 @@ module Forms end def next_path - page_id = year == 2022 ? "needstype" : "upload-your-file" + page_id = if year == 2022 + "needstype" + elsif year >= 2023 + "template" + else + "upload-your-file" + end bulk_upload_lettings_log_path(id: page_id, form: { year:, needstype: }) end diff --git a/app/models/forms/bulk_upload_lettings/template.rb b/app/models/forms/bulk_upload_lettings/template.rb new file mode 100644 index 000000000..a5fd12c9b --- /dev/null +++ b/app/models/forms/bulk_upload_lettings/template.rb @@ -0,0 +1,43 @@ +module Forms + module BulkUploadLettings + class Template + include ActiveModel::Model + include ActiveModel::Attributes + include Rails.application.routes.url_helpers + + attribute :ordered_template, :boolean + attribute :year, :integer + attribute :needstype, :integer + + validates :ordered_template, presence: true + + def view_path + "bulk_upload_lettings_logs/forms/template" + end + + def options + [ + OpenStruct.new(id: true, name: "Legacy-style template"), + OpenStruct.new(id: false, name: "New-style template"), + ] + end + + def back_path + page_id = year == 2022 ? "needstype" : "prepare-your-file" + bulk_upload_lettings_log_path(id: page_id, form: { year:, needstype: }) + end + + def next_path + bulk_upload_lettings_log_path(id: "upload-your-file", form: { year:, needstype:, ordered_template: }) + end + + def save! + true + end + + def year_combo + "#{year}/#{year + 1 - 2000}" + end + end + end +end diff --git a/app/models/forms/bulk_upload_lettings/upload_your_file.rb b/app/models/forms/bulk_upload_lettings/upload_your_file.rb index 57ac017a3..1e67cb71a 100644 --- a/app/models/forms/bulk_upload_lettings/upload_your_file.rb +++ b/app/models/forms/bulk_upload_lettings/upload_your_file.rb @@ -11,6 +11,7 @@ module Forms attribute :needstype, :integer attribute :file attribute :current_user + attribute :ordered_template, :boolean validates :file, presence: true validate :validate_file_is_csv @@ -20,8 +21,14 @@ module Forms end def back_path - page_id = year == 2022 ? "needstype" : "prepare-your-file" - bulk_upload_lettings_log_path(id: page_id, form: { year:, needstype: }) + page_id = if year == 2022 + "needstype" + elsif year >= 2023 + "template" + else + "prepare-your-file" + end + bulk_upload_lettings_log_path(id: page_id, form: { year:, needstype:, ordered_template: }) end def year_combo diff --git a/app/views/bulk_upload_lettings_logs/forms/needstype.erb b/app/views/bulk_upload_lettings_logs/forms/needstype.erb index a9bc28c4f..ecee94f79 100644 --- a/app/views/bulk_upload_lettings_logs/forms/needstype.erb +++ b/app/views/bulk_upload_lettings_logs/forms/needstype.erb @@ -6,6 +6,7 @@ <%= form_with model: @form, scope: :form, url: bulk_upload_lettings_log_path(id: "needstype"), method: :patch do |f| %> <%= f.govuk_error_summary %> <%= f.hidden_field :year %> + <%= f.hidden_field :ordered_template %> <%= f.govuk_collection_radio_buttons :needstype, @form.options, diff --git a/app/views/bulk_upload_lettings_logs/forms/template.erb b/app/views/bulk_upload_lettings_logs/forms/template.erb new file mode 100644 index 000000000..3e790c043 --- /dev/null +++ b/app/views/bulk_upload_lettings_logs/forms/template.erb @@ -0,0 +1,20 @@ +<% content_for :before_content do %> + <%= govuk_back_link href: @form.back_path %> +<% end %> +
+
+ <%= form_with model: @form, scope: :form, url: bulk_upload_lettings_log_path(id: "template"), method: :patch do |f| %> + <%= f.govuk_error_summary %> + <%= f.hidden_field :year %> + + <%= f.govuk_collection_radio_buttons :ordered_template, + @form.options, + :id, + :name, + legend: { text: "Which style of template is being uploaded?", size: "l" }, + caption: { text: "Upload lettings logs in bulk (#{@form.year_combo})", size: "l" }%> + + <%= f.govuk_submit %> + <% end %> +
+
diff --git a/app/views/bulk_upload_lettings_logs/forms/upload_your_file.html.erb b/app/views/bulk_upload_lettings_logs/forms/upload_your_file.html.erb index bbafc28b3..453c40f88 100644 --- a/app/views/bulk_upload_lettings_logs/forms/upload_your_file.html.erb +++ b/app/views/bulk_upload_lettings_logs/forms/upload_your_file.html.erb @@ -7,6 +7,7 @@ <%= form_with model: @form, scope: :form, url: bulk_upload_lettings_log_path(id: "upload-your-file"), method: :patch do |f| %> <%= f.hidden_field :year %> <%= f.hidden_field :needstype %> + <%= f.hidden_field :ordered_template %> <%= f.govuk_error_summary %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 9c8324d34..2646ee9ab 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -63,6 +63,10 @@ en: attributes: needstype: blank: You must answer needs type + forms/bulk_upload_lettings/template: + attributes: + ordered_template: + blank: You must answer template style activerecord: errors: diff --git a/db/migrate/20230315113252_add_ordered_template.rb b/db/migrate/20230315113252_add_ordered_template.rb new file mode 100644 index 000000000..a71129d3c --- /dev/null +++ b/db/migrate/20230315113252_add_ordered_template.rb @@ -0,0 +1,7 @@ +class AddOrderedTemplate < ActiveRecord::Migration[7.0] + def change + change_table :bulk_uploads, bulk: true do |t| + t.column :ordered_template, :boolean + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 085419473..ca83b44af 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_03_08_101826) do +ActiveRecord::Schema[7.0].define(version: 2023_03_15_113252) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -39,6 +39,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_08_101826) do t.datetime "updated_at", null: false t.text "filename" t.integer "needstype" + t.boolean "ordered_template" t.index ["identifier"], name: "index_bulk_uploads_on_identifier", unique: true t.index ["user_id"], name: "index_bulk_uploads_on_user_id" end @@ -279,6 +280,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_08_101826) do t.boolean "unresolved" t.bigint "updated_by_id" t.bigint "bulk_upload_id" + t.integer "carehome_charges_value_check" t.index ["bulk_upload_id"], name: "index_lettings_logs_on_bulk_upload_id" t.index ["created_by_id"], name: "index_lettings_logs_on_created_by_id" t.index ["location_id"], name: "index_lettings_logs_on_location_id" @@ -299,6 +301,15 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_08_101826) do t.index ["code"], name: "index_local_authority_code", unique: true end + create_table "local_authority_links", force: :cascade do |t| + t.bigint "local_authority_id" + t.bigint "linked_local_authority_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["linked_local_authority_id"], name: "index_local_authority_links_on_linked_local_authority_id" + t.index ["local_authority_id"], name: "index_local_authority_links_on_local_authority_id" + end + create_table "location_deactivation_periods", force: :cascade do |t| t.datetime "deactivation_date" t.datetime "reactivation_date" @@ -500,7 +511,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_08_101826) do t.integer "prevten" t.integer "mortgageused" t.integer "wchair" - t.integer "income2_value_check" t.integer "armedforcesspouse" t.datetime "hodate", precision: nil t.integer "hoday" @@ -532,15 +542,17 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_08_101826) do t.integer "old_persons_shared_ownership_value_check" t.integer "staircase_bought_value_check" t.integer "monthly_charges_value_check" + t.integer "saledate_check" t.integer "details_known_5" t.integer "details_known_6" - t.integer "saledate_check" - t.integer "prevshared" - t.integer "staircasesale" t.integer "ethnic_group2" t.integer "ethnicbuy2" - t.integer "proplen_asked" + t.integer "prevshared" + t.integer "staircasesale" t.string "old_id" + t.integer "income2_value_check" + t.integer "proplen_asked" + t.integer "mortlen_known" t.integer "pregblank" t.integer "buy2living" t.integer "prevtenbuy2" @@ -641,6 +653,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_08_101826) do add_foreign_key "lettings_logs", "locations" add_foreign_key "lettings_logs", "organisations", column: "owning_organisation_id", on_delete: :cascade add_foreign_key "lettings_logs", "schemes" + add_foreign_key "local_authority_links", "local_authorities" + add_foreign_key "local_authority_links", "local_authorities", column: "linked_local_authority_id" add_foreign_key "locations", "schemes" add_foreign_key "organisation_relationships", "organisations", column: "child_organisation_id" add_foreign_key "organisation_relationships", "organisations", column: "parent_organisation_id" diff --git a/spec/features/bulk_upload_lettings_logs_spec.rb b/spec/features/bulk_upload_lettings_logs_spec.rb index 939518ac9..68945bdf6 100644 --- a/spec/features/bulk_upload_lettings_logs_spec.rb +++ b/spec/features/bulk_upload_lettings_logs_spec.rb @@ -20,7 +20,7 @@ RSpec.describe "Bulk upload lettings log" do end # rubocop:disable RSpec/AnyInstance - context "when during crossover period" do + context "when during crossover period and 22/23 is selected" do it "shows journey with year option" do Timecop.freeze(2022, 6, 1) do visit("/lettings-logs") @@ -79,25 +79,55 @@ RSpec.describe "Bulk upload lettings log" do end end end - # rubocop:enable RSpec/AnyInstance - context "when not it crossover period" do - it "shows journey with year option" do - Timecop.freeze(2023, 10, 1) do + context "when during crossover period and 23/24 is selected" do + it "shows journey with year and template questions" do + Timecop.freeze(2023, 6, 1) do visit("/lettings-logs") expect(page).to have_link("Upload lettings logs in bulk") click_link("Upload lettings logs in bulk") - expect(page).to have_content("Upload lettings logs in bulk (2023/24)") + expect(page).to have_content("Which year") + click_button("Continue") + + expect(page).to have_content("You must select a collection period to upload for") + choose("2023/2024") + click_button("Continue") + + click_link("Back") + + expect(page.find_field("form-year-2023-field")).to be_checked click_button("Continue") + expect(page).to have_content("Prepare your file") + click_button("Continue") + + expect(page).to have_content("Which style of template is being uploaded?") + click_button("Continue") + + expect(page).to have_content("You must answer template style") + choose("Legacy-style template") + click_button("Continue") + + click_link("Back") + + expect(page.find_field("form-ordered-template-true-field")).to be_checked + click_button("Continue") + + expect(page).to have_content("Upload lettings logs in bulk (2023/24)") expect(page).to have_content("Upload your file") + click_button("Upload") + + allow_any_instance_of(Forms::BulkUploadLettings::UploadYourFile).to receive(:`).and_return("not a csv") + + expect(page).to have_content("Select which file to upload") end end end + # rubocop:enable RSpec/AnyInstance - context "when the collection year isn't 22/23" do - it "shows journey without the needstype" do + context "when not it crossover period and the collection year is after 22/23" do + it "shows journey without the needstype and year and with template" do Timecop.freeze(2023, 10, 1) do visit("/lettings-logs") expect(page).to have_link("Upload lettings logs in bulk") @@ -111,6 +141,18 @@ RSpec.describe "Bulk upload lettings log" do expect(page).to have_content("Prepare your file") click_button("Continue") + expect(page).to have_content("Which style of template is being uploaded?") + click_button("Continue") + + expect(page).to have_content("You must answer template style") + choose("Legacy-style template") + click_button("Continue") + + click_link("Back") + + expect(page.find_field("form-ordered-template-true-field")).to be_checked + click_button("Continue") + expect(page).to have_content("Upload lettings logs in bulk (2023/24)") expect(page).to have_content("Upload your file") @@ -118,4 +160,39 @@ RSpec.describe "Bulk upload lettings log" do end end end + + context "when not it crossover period and the collection year is on or before 22/23" do + it "shows journey with the needstype and without template type" do + Timecop.freeze(2022, 10, 1) do + visit("/lettings-logs") + expect(page).to have_link("Upload lettings logs in bulk") + click_link("Upload lettings logs in bulk") + + expect(page).to have_content("Prepare your file") + click_button("Continue") + + click_link("Back") + + expect(page).to have_content("Prepare your file") + click_button("Continue") + + expect(page).to have_content("What is the needs type?") + click_button("Continue") + + expect(page).to have_content("You must answer needs type") + choose("General needs") + click_button("Continue") + + click_link("Back") + + expect(page.find_field("form-needstype-1-field")).to be_checked + click_button("Continue") + + expect(page).to have_content("Upload lettings logs in bulk (2022/23)") + + expect(page).to have_content("Upload your file") + click_button("Upload") + end + end + end end diff --git a/spec/models/forms/bulk_upload_lettings/template_spec.rb b/spec/models/forms/bulk_upload_lettings/template_spec.rb new file mode 100644 index 000000000..c9170d675 --- /dev/null +++ b/spec/models/forms/bulk_upload_lettings/template_spec.rb @@ -0,0 +1,12 @@ +require "rails_helper" + +RSpec.describe Forms::BulkUploadLettings::Template do + subject(:form) { described_class.new } + + describe "#options" do + it "returns correct templates" do + expect(form.options.map(&:id)).to eq([true, false]) + expect(form.options.map(&:name)).to eq(["Legacy-style template", "New-style template"]) + end + end +end