Browse Source

Cldc 1773 needstype bulk upload (#1105)

* Add needstype to lettings bulk upload model

* Add needstype question for 2022/23 bulk uploads

* New line

* Add more info to prepare your file
pull/1096/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
da33b7e5fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/controllers/bulk_upload_lettings_logs_controller.rb
  2. 38
      app/models/forms/bulk_upload_lettings/needstype.rb
  3. 4
      app/models/forms/bulk_upload_lettings/prepare_your_file.rb
  4. 5
      app/models/forms/bulk_upload_lettings/upload_your_file.rb
  5. 21
      app/views/bulk_upload_lettings_logs/forms/needstype.erb
  6. 1
      app/views/bulk_upload_lettings_logs/forms/prepare_your_file.html.erb
  7. 1
      app/views/bulk_upload_lettings_logs/forms/upload_your_file.html.erb
  8. 6
      config/locales/en.yml
  9. 7
      db/migrate/20221219112421_add_needstype_to_bulk_upload.rb
  10. 1
      db/schema.rb
  11. 38
      spec/features/bulk_upload_lettings_logs_spec.rb
  12. 4
      spec/models/forms/bulk_upload_lettings/upload_your_file_spec.rb
  13. 2
      spec/requests/bulk_upload_lettings_logs_controller_spec.rb

6
app/controllers/bulk_upload_lettings_logs_controller.rb

@ -24,7 +24,7 @@ class BulkUploadLettingsLogsController < ApplicationController
private private
def current_year def current_year
FormHandler.instance.forms["current_lettings"].start_date.year FormHandler.instance.current_collection_start_year
end end
def in_crossover_period? def in_crossover_period?
@ -37,6 +37,8 @@ private
Forms::BulkUploadLettings::Year.new(form_params) Forms::BulkUploadLettings::Year.new(form_params)
when "prepare-your-file" when "prepare-your-file"
Forms::BulkUploadLettings::PrepareYourFile.new(form_params) Forms::BulkUploadLettings::PrepareYourFile.new(form_params)
when "needstype"
Forms::BulkUploadLettings::Needstype.new(form_params)
when "upload-your-file" when "upload-your-file"
Forms::BulkUploadLettings::UploadYourFile.new(form_params.merge(current_user:)) Forms::BulkUploadLettings::UploadYourFile.new(form_params.merge(current_user:))
when "checking-file" when "checking-file"
@ -47,6 +49,6 @@ private
end end
def form_params def form_params
params.fetch(:form, {}).permit(:year, :file) params.fetch(:form, {}).permit(:year, :needstype, :file)
end end
end end

38
app/models/forms/bulk_upload_lettings/needstype.rb

@ -0,0 +1,38 @@
module Forms
module BulkUploadLettings
class Needstype
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
attribute :needstype, :integer
attribute :year, :integer
validates :needstype, presence: true
def view_path
"bulk_upload_lettings_logs/forms/needstype"
end
def options
[OpenStruct.new(id: 1, name: "General needs"), OpenStruct.new(id: 2, name: "Supported housing")]
end
def back_path
bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year:, needstype: })
end
def next_path
bulk_upload_lettings_log_path(id: "upload-your-file", form: { year:, needstype: })
end
def year_combo
"#{year}/#{year + 1 - 2000}"
end
def save!
true
end
end
end
end

4
app/models/forms/bulk_upload_lettings/prepare_your_file.rb

@ -6,6 +6,7 @@ module Forms
include Rails.application.routes.url_helpers include Rails.application.routes.url_helpers
attribute :year, :integer attribute :year, :integer
attribute :needstype, :integer
def view_path def view_path
"bulk_upload_lettings_logs/forms/prepare_your_file" "bulk_upload_lettings_logs/forms/prepare_your_file"
@ -20,7 +21,8 @@ module Forms
end end
def next_path def next_path
bulk_upload_lettings_log_path(id: "upload-your-file", form: { year: }) page_id = year == 2022 ? "needstype" : "upload-your-file"
bulk_upload_lettings_log_path(id: page_id, form: { year:, needstype: })
end end
def template_path def template_path

5
app/models/forms/bulk_upload_lettings/upload_your_file.rb

@ -8,6 +8,7 @@ module Forms
include Rails.application.routes.url_helpers include Rails.application.routes.url_helpers
attribute :year, :integer attribute :year, :integer
attribute :needstype, :integer
attribute :file attribute :file
attribute :current_user attribute :current_user
@ -19,7 +20,8 @@ module Forms
end end
def back_path def back_path
bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: }) page_id = year == 2022 ? "needstype" : "prepare-your-file"
bulk_upload_lettings_log_path(id: page_id, form: { year:, needstype: })
end end
def year_combo def year_combo
@ -35,6 +37,7 @@ module Forms
user: current_user, user: current_user,
log_type: BulkUpload.log_types[:lettings], log_type: BulkUpload.log_types[:lettings],
year:, year:,
needstype:,
filename: file.original_filename, filename: file.original_filename,
) )

21
app/views/bulk_upload_lettings_logs/forms/needstype.erb

@ -0,0 +1,21 @@
<% 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: "needstype"), method: :patch do |f| %>
<%= f.govuk_error_summary %>
<%= f.hidden_field :year %>
<%= f.govuk_collection_radio_buttons :needstype,
@form.options,
:id,
:name,
hint: { text: I18n.t("hints.bulk_upload.needstype") },
legend: { text: "What is the needs type?", 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/prepare_your_file.html.erb

@ -15,6 +15,7 @@
<li>Download the <%= govuk_link_to "bulk lettings template", @form.template_path %></li> <li>Download the <%= govuk_link_to "bulk lettings template", @form.template_path %></li>
<li>Export the data from your housing management system, matching the template</li> <li>Export the data from your housing management system, matching the template</li>
<li>If you cannot export it in this format, you may have to input it manually</li> <li>If you cannot export it in this format, you may have to input it manually</li>
<li>You can not have a file with both general needs logs and supported housing logs. These must be in separate files</li>
</ul> </ul>
<h2 class="govuk-heading-m">Check your data</h2> <h2 class="govuk-heading-m">Check your data</h2>

1
app/views/bulk_upload_lettings_logs/forms/upload_your_file.html.erb

@ -6,6 +6,7 @@
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%= form_with model: @form, scope: :form, url: bulk_upload_lettings_log_path(id: "upload-your-file"), method: :patch do |f| %> <%= 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 :year %>
<%= f.hidden_field :needstype %>
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>

6
config/locales/en.yml

@ -59,6 +59,10 @@ en:
file: file:
blank: Select which file to upload blank: Select which file to upload
not_csv: Your file must be in CSV format not_csv: Your file must be in CSV format
forms/bulk_upload_lettings/needstype:
attributes:
needstype:
blank: You must answer needs type
activerecord: activerecord:
errors: errors:
@ -458,6 +462,8 @@ en:
startdate: "For example, 27 3 2021" startdate: "For example, 27 3 2021"
scheme: scheme:
toggle_active: "If the date is before %{date}, select ‘From the start of the current collection period’ because the previous period has now closed." toggle_active: "If the date is before %{date}, select ‘From the start of the current collection period’ because the previous period has now closed."
bulk_upload:
needstype: "General needs housing includes both self-contained and shared housing without support or specific adaptations. Supported housing can include direct access hostels, group homes, residential care and nursing homes."
warnings: warnings:
location: location:

7
db/migrate/20221219112421_add_needstype_to_bulk_upload.rb

@ -0,0 +1,7 @@
class AddNeedstypeToBulkUpload < ActiveRecord::Migration[7.0]
def change
change_table :bulk_uploads, bulk: true do |t|
t.column :needstype, :integer
end
end
end

1
db/schema.rb

@ -22,6 +22,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_04_164318) do
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.text "filename" t.text "filename"
t.integer "needstype"
t.index ["identifier"], name: "index_bulk_uploads_on_identifier", unique: true t.index ["identifier"], name: "index_bulk_uploads_on_identifier", unique: true
t.index ["user_id"], name: "index_bulk_uploads_on_user_id" t.index ["user_id"], name: "index_bulk_uploads_on_user_id"
end end

38
spec/features/bulk_upload_lettings_logs_spec.rb

@ -42,6 +42,19 @@ RSpec.describe "Bulk upload lettings log" do
expect(page).to have_content("Upload lettings logs in bulk (2022/23)") expect(page).to have_content("Upload lettings logs in bulk (2022/23)")
click_button("Continue") 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") expect(page).to have_content("Upload your file")
click_button("Upload") click_button("Upload")
@ -75,10 +88,33 @@ RSpec.describe "Bulk upload lettings log" do
expect(page).to have_link("Upload lettings logs in bulk") expect(page).to have_link("Upload lettings logs in bulk")
click_link("Upload lettings logs in bulk") click_link("Upload lettings logs in bulk")
expect(page).to have_content("Upload lettings logs in bulk (2022/23)") expect(page).to have_content("Upload lettings logs in bulk (2023/24)")
click_button("Continue")
expect(page).to have_content("Upload your file")
end
end
end
context "when the collection year isn't 22/23" do
it "shows journey without the needstype" do
Timecop.freeze(2023, 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_button("Continue")
click_link("Back")
expect(page).to have_content("Prepare your file")
click_button("Continue")
expect(page).to have_content("Upload lettings logs in bulk (2023/24)")
expect(page).to have_content("Upload your file") expect(page).to have_content("Upload your file")
click_button("Upload")
end end
end end
end end

4
spec/models/forms/bulk_upload_lettings/upload_your_file_spec.rb

@ -1,9 +1,10 @@
require "rails_helper" require "rails_helper"
RSpec.describe Forms::BulkUploadLettings::UploadYourFile do RSpec.describe Forms::BulkUploadLettings::UploadYourFile do
subject(:form) { described_class.new(year:, file:, current_user:) } subject(:form) { described_class.new(year:, needstype:, file:, current_user:) }
let(:year) { 2022 } let(:year) { 2022 }
let(:needstype) { 2 }
let(:actual_file) { File.open(file_fixture("blank_bulk_upload_sales.csv")) } let(:actual_file) { File.open(file_fixture("blank_bulk_upload_sales.csv")) }
let(:file) do let(:file) do
ActionDispatch::Http::UploadedFile.new( ActionDispatch::Http::UploadedFile.new(
@ -37,6 +38,7 @@ RSpec.describe Forms::BulkUploadLettings::UploadYourFile do
expect(bulk_upload.user).to eql(current_user) expect(bulk_upload.user).to eql(current_user)
expect(bulk_upload.log_type).to eql("lettings") expect(bulk_upload.log_type).to eql("lettings")
expect(bulk_upload.year).to eql(year) expect(bulk_upload.year).to eql(year)
expect(bulk_upload.needstype).to eql(needstype)
expect(bulk_upload.filename).to eql("my-file.csv") expect(bulk_upload.filename).to eql("my-file.csv")
expect(bulk_upload.identifier).to be_present expect(bulk_upload.identifier).to be_present
end end

2
spec/requests/bulk_upload_lettings_logs_controller_spec.rb

@ -10,7 +10,7 @@ RSpec.describe BulkUploadLettingsLogsController, type: :request do
describe "GET /lettings-logs/bulk-upload-logs/start" do describe "GET /lettings-logs/bulk-upload-logs/start" do
context "when not in crossover period" do context "when not in crossover period" do
let(:expected_year) { FormHandler.instance.forms["current_lettings"].start_date.year } let(:expected_year) { 2021 }
it "redirects to /prepare-your-file" do it "redirects to /prepare-your-file" do
Timecop.freeze(2022, 1, 1) do Timecop.freeze(2022, 1, 1) do

Loading…
Cancel
Save