Browse Source

Add template question to lettings bulk upload

CLDC-1787-bulk-upload-column-ordering
Kat 2 years ago
parent
commit
b6274412e8
  1. 4
      app/controllers/bulk_upload_lettings_logs_controller.rb
  2. 3
      app/models/forms/bulk_upload_lettings/needstype.rb
  3. 9
      app/models/forms/bulk_upload_lettings/prepare_your_file.rb
  4. 43
      app/models/forms/bulk_upload_lettings/template.rb
  5. 11
      app/models/forms/bulk_upload_lettings/upload_your_file.rb
  6. 1
      app/views/bulk_upload_lettings_logs/forms/needstype.erb
  7. 20
      app/views/bulk_upload_lettings_logs/forms/template.erb
  8. 1
      app/views/bulk_upload_lettings_logs/forms/upload_your_file.html.erb
  9. 4
      config/locales/en.yml
  10. 7
      db/migrate/20230315113252_add_ordered_template.rb
  11. 26
      db/schema.rb
  12. 93
      spec/features/bulk_upload_lettings_logs_spec.rb
  13. 12
      spec/models/forms/bulk_upload_lettings/template_spec.rb

4
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

3
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

9
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

43
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

11
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

1
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,

20
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 %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<%= 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 %>
</div>
</div>

1
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 %>

4
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:

7
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

26
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"

93
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

12
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
Loading…
Cancel
Save