Browse Source

[1714] Bulk upload part three (#1032)

* add start of bulk upload logs journey

* split upload controller into 2

* add year page to bulk upload journey

* bulk upload years now dynamic

* bulk upload journey: add copy for prepare file

* add link to bulk upload template

* add placeholder for upload your file page

* handle bulk upload when not in crossover

* fix tests around bulk upload redirect

* fix typos in bulk upload jouney
CLDC-20-more-ac-fixes2^2 v0.2.22
Phil Lee 2 years ago committed by GitHub
parent
commit
a305bb7d52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 50
      app/controllers/bulk_upload_lettings_logs_controller.rb
  2. 50
      app/controllers/bulk_upload_sales_logs_controller.rb
  3. 21
      app/helpers/logs_helper.rb
  4. 4
      app/helpers/navigation_items_helper.rb
  5. 8
      app/models/form.rb
  6. 41
      app/models/forms/bulk_upload_lettings/prepare_your_file.rb
  7. 19
      app/models/forms/bulk_upload_lettings/upload_your_file.rb
  8. 37
      app/models/forms/bulk_upload_lettings/year.rb
  9. 41
      app/models/forms/bulk_upload_sales/prepare_your_file.rb
  10. 19
      app/models/forms/bulk_upload_sales/upload_your_file.rb
  11. 37
      app/models/forms/bulk_upload_sales/year.rb
  12. 33
      app/views/bulk_upload_lettings_logs/forms/prepare_your_file.html.erb
  13. 17
      app/views/bulk_upload_lettings_logs/forms/upload_your_file.html.erb
  14. 16
      app/views/bulk_upload_lettings_logs/forms/year.html.erb
  15. 33
      app/views/bulk_upload_sales_logs/forms/prepare_your_file.html.erb
  16. 17
      app/views/bulk_upload_sales_logs/forms/upload_your_file.html.erb
  17. 16
      app/views/bulk_upload_sales_logs/forms/year.html.erb
  18. 12
      app/views/logs/index.html.erb
  19. 4
      config/initializers/feature_toggle.rb
  20. 12
      config/locales/en.yml
  21. 14
      config/routes.rb
  22. BIN
      public/files/bulk-upload-lettings-template-v1.xlsx
  23. BIN
      public/files/bulk-upload-sales-template-v1.xlsx
  24. 51
      spec/features/bulk_upload_lettings_logs_spec.rb
  25. 51
      spec/features/bulk_upload_sales_logs_spec.rb
  26. 34
      spec/models/form_spec.rb
  27. 12
      spec/models/forms/bulk_upload_lettings/year_spec.rb
  28. 12
      spec/models/forms/bulk_upload_sales/year_spec.rb
  29. 1
      spec/rails_helper.rb
  30. 32
      spec/requests/bulk_upload_lettings_logs_controller_spec.rb
  31. 32
      spec/requests/bulk_upload_sales_logs_controller_spec.rb

50
app/controllers/bulk_upload_lettings_logs_controller.rb

@ -0,0 +1,50 @@
class BulkUploadLettingsLogsController < ApplicationController
before_action :authenticate_user!
def start
if in_crossover_period?
redirect_to bulk_upload_lettings_log_path(id: "year")
else
redirect_to bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: current_year })
end
end
def show
render form.view_path
end
def update
if form.valid?
redirect_to form.next_path
else
render form.view_path
end
end
private
def current_year
FormHandler.instance.forms["current_lettings"].start_date.year
end
def in_crossover_period?
FormHandler.instance.forms.values.any?(&:in_crossover_period?)
end
def form
@form ||= case params[:id]
when "year"
Forms::BulkUploadLettings::Year.new(form_params)
when "prepare-your-file"
Forms::BulkUploadLettings::PrepareYourFile.new(form_params)
when "upload-your-file"
Forms::BulkUploadLettings::UploadYourFile.new(form_params)
else
raise "Page not found for path #{params[:id]}"
end
end
def form_params
params.fetch(:form, {}).permit(:year)
end
end

50
app/controllers/bulk_upload_sales_logs_controller.rb

@ -0,0 +1,50 @@
class BulkUploadSalesLogsController < ApplicationController
before_action :authenticate_user!
def start
if in_crossover_period?
redirect_to bulk_upload_sales_log_path(id: "year")
else
redirect_to bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: current_year })
end
end
def show
render form.view_path
end
def update
if form.valid?
redirect_to form.next_path
else
render form.view_path
end
end
private
def current_year
FormHandler.instance.forms["current_sales"].start_date.year
end
def in_crossover_period?
FormHandler.instance.forms.values.any?(&:in_crossover_period?)
end
def form
@form ||= case params[:id]
when "year"
Forms::BulkUploadSales::Year.new(form_params)
when "prepare-your-file"
Forms::BulkUploadSales::PrepareYourFile.new(form_params)
when "upload-your-file"
Forms::BulkUploadSales::UploadYourFile.new(form_params)
else
raise "Page not found for path #{params[:id]}"
end
end
def form_params
params.fetch(:form, {}).permit(:year)
end
end

21
app/helpers/logs_helper.rb

@ -0,0 +1,21 @@
module LogsHelper
def log_type_for_controller(controller)
case controller.class.to_s
when "LettingsLogsController"
"lettings"
when "SalesLogsController"
"sales"
else
raise "Log type not found for #{controller.class}"
end
end
def bulk_upload_path_for_controller(controller, id:)
case log_type_for_controller(controller)
when "lettings"
bulk_upload_lettings_log_path(id:)
when "sales"
bulk_upload_sales_log_path(id:)
end
end
end

4
app/helpers/navigation_items_helper.rb

@ -65,11 +65,11 @@ module NavigationItemsHelper
private private
def lettings_logs_current?(path) def lettings_logs_current?(path)
path == "/lettings-logs" path.starts_with?("/lettings-logs")
end end
def sales_logs_current?(path) def sales_logs_current?(path)
path == "/sales-logs" path.starts_with?("/sales-logs")
end end
def users_current?(path) def users_current?(path)

8
app/models/form.rb

@ -223,4 +223,12 @@ class Form
end end
end end
end end
def in_crossover_period?(now: Time.zone.now)
((end_date - 3.months) < now) && (now < end_date)
end
def inspect
"#<#{self.class} @type=#{type} @name=#{name}>"
end
end end

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

@ -0,0 +1,41 @@
module Forms
module BulkUploadLettings
class PrepareYourFile
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
attribute :year, :integer
def view_path
"bulk_upload_lettings_logs/forms/prepare_your_file"
end
def back_path
if in_crossover_period?
Rails.application.routes.url_helpers.bulk_upload_lettings_log_path(id: "year", form: { year: })
else
Rails.application.routes.url_helpers.lettings_logs_path
end
end
def next_path
bulk_upload_lettings_log_path(id: "upload-your-file", form: { year: })
end
def template_path
"/files/bulk-upload-lettings-template-v1.xlsx"
end
def year_combo
"#{year}/#{year + 1 - 2000}"
end
private
def in_crossover_period?
FormHandler.instance.forms.values.any?(&:in_crossover_period?)
end
end
end
end

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

@ -0,0 +1,19 @@
module Forms
module BulkUploadLettings
class UploadYourFile
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
attribute :year, :integer
def view_path
"bulk_upload_lettings_logs/forms/upload_your_file"
end
def back_path
bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: })
end
end
end
end

37
app/models/forms/bulk_upload_lettings/year.rb

@ -0,0 +1,37 @@
module Forms
module BulkUploadLettings
class Year
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
attribute :year, :integer
validates :year, presence: true
def view_path
"bulk_upload_lettings_logs/forms/year"
end
def options
possible_years.map do |year|
OpenStruct.new(id: year, name: "#{year}/#{year + 1}")
end
end
def back_path
lettings_logs_path
end
def next_path
bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: })
end
private
def possible_years
FormHandler.instance.lettings_forms.values.map { |form| form.start_date.year }.sort.reverse
end
end
end
end

41
app/models/forms/bulk_upload_sales/prepare_your_file.rb

@ -0,0 +1,41 @@
module Forms
module BulkUploadSales
class PrepareYourFile
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
attribute :year, :integer
def view_path
"bulk_upload_sales_logs/forms/prepare_your_file"
end
def back_path
if in_crossover_period?
Rails.application.routes.url_helpers.bulk_upload_sales_log_path(id: "year", form: { year: })
else
Rails.application.routes.url_helpers.sales_logs_path
end
end
def next_path
bulk_upload_sales_log_path(id: "upload-your-file", form: { year: })
end
def template_path
"/files/bulk-upload-sales-template-v1.xlsx"
end
def year_combo
"#{year}/#{year + 1 - 2000}"
end
private
def in_crossover_period?
FormHandler.instance.forms.values.any?(&:in_crossover_period?)
end
end
end
end

19
app/models/forms/bulk_upload_sales/upload_your_file.rb

@ -0,0 +1,19 @@
module Forms
module BulkUploadSales
class UploadYourFile
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
attribute :year, :integer
def view_path
"bulk_upload_sales_logs/forms/upload_your_file"
end
def back_path
bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: })
end
end
end
end

37
app/models/forms/bulk_upload_sales/year.rb

@ -0,0 +1,37 @@
module Forms
module BulkUploadSales
class Year
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
attribute :year, :integer
validates :year, presence: true
def view_path
"bulk_upload_sales_logs/forms/year"
end
def options
possible_years.map do |year|
OpenStruct.new(id: year, name: "#{year}/#{year + 1}")
end
end
def back_path
sales_logs_path
end
def next_path
bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: })
end
private
def possible_years
FormHandler.instance.sales_forms.values.map { |form| form.start_date.year }.sort.reverse
end
end
end
end

33
app/views/bulk_upload_lettings_logs/forms/prepare_your_file.html.erb

@ -0,0 +1,33 @@
<% 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">
<%= form_with model: @form, scope: :form, url: bulk_upload_lettings_log_path(id: "prepare-your-file"), method: :patch do |f| %>
<%= f.hidden_field :year %>
<span class="govuk-caption-l">Upload lettings logs in bulk (<%= @form.year_combo %>)</span>
<h1 class="govuk-heading-l">Prepare your file</h1>
<h2 class="govuk-heading-m">Create your file</h2>
<ul class="govuk-list govuk-list--bullet">
<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>If you cannot export it in this format, you may have to input it manually</li>
</ul>
<h2 class="govuk-heading-m">Check your data</h2>
<ul class="govuk-list govuk-list--bullet">
<li>Check data is complete and formatted correctly, using data specifications (opens in a new tab)</li>
</ul>
<h2 class="govuk-heading-m">Save your file</h2>
<ul class="govuk-list govuk-list--bullet">
<li>Save the file (CSV format <strong>only</strong>)</li>
</ul>
<%= f.govuk_submit %>
<% end %>
</div>
</div>

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

@ -0,0 +1,17 @@
<% 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: "upload-your-file"), method: :patch do |f| %>
<%= f.govuk_error_summary %>
<div>
Upload your file goes here
</div>
<div>
year selected <%= @form.year %>
</div>
<%= f.govuk_submit %>
<% end %>

16
app/views/bulk_upload_lettings_logs/forms/year.html.erb

@ -0,0 +1,16 @@
<% 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: "year"), method: :patch do |f| %>
<%= f.govuk_error_summary %>
<%= f.govuk_collection_radio_buttons :year,
@form.options,
:id,
:name,
legend: { text: "Which year are you uploading data for?", size: "l" },
caption: { text: "Upload lettings logs in bulk", size: "l" } %>
<%= f.govuk_submit %>
<% end %>

33
app/views/bulk_upload_sales_logs/forms/prepare_your_file.html.erb

@ -0,0 +1,33 @@
<% 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">
<%= form_with model: @form, scope: :form, url: bulk_upload_sales_log_path(id: "prepare-your-file"), method: :patch do |f| %>
<%= f.hidden_field :year %>
<span class="govuk-caption-l">Upload sales logs in bulk (<%= @form.year_combo %>)</span>
<h1 class="govuk-heading-l">Prepare your file</h1>
<h2 class="govuk-heading-m">Create your file</h2>
<ul class="govuk-list govuk-list--bullet">
<li>Download the <%= govuk_link_to "bulk sales template", @form.template_path %></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>
</ul>
<h2 class="govuk-heading-m">Check your data</h2>
<ul class="govuk-list govuk-list--bullet">
<li>Check data is complete and formatted correctly, using data specifications (opens in a new tab)</li>
</ul>
<h2 class="govuk-heading-m">Save your file</h2>
<ul class="govuk-list govuk-list--bullet">
<li>Save the file (CSV format <strong>only</strong>)</li>
</ul>
<%= f.govuk_submit %>
<% end %>
</div>
</div>

17
app/views/bulk_upload_sales_logs/forms/upload_your_file.html.erb

@ -0,0 +1,17 @@
<% content_for :before_content do %>
<%= govuk_back_link href: @form.back_path %>
<% end %>
<%= form_with model: @form, scope: :form, url: bulk_upload_sales_log_path(id: "upload-your-file"), method: :patch do |f| %>
<%= f.govuk_error_summary %>
<div>
Upload your file goes here
</div>
<div>
year selected <%= @form.year %>
</div>
<%= f.govuk_submit %>
<% end %>

16
app/views/bulk_upload_sales_logs/forms/year.html.erb

@ -0,0 +1,16 @@
<% content_for :before_content do %>
<%= govuk_back_link href: @form.back_path %>
<% end %>
<%= form_with model: @form, scope: :form, url: bulk_upload_sales_log_path(id: "year"), method: :patch do |f| %>
<%= f.govuk_error_summary %>
<%= f.govuk_collection_radio_buttons :year,
@form.options,
:id,
:name,
legend: { text: "Which year are you uploading data for?", size: "l" },
caption: { text: "Upload sales logs in bulk", size: "l" } %>
<%= f.govuk_submit %>
<% end %>

12
app/views/logs/index.html.erb

@ -10,14 +10,18 @@
<% end %> <% end %>
<div class="app-filter-layout" data-controller="filter-layout"> <div class="app-filter-layout" data-controller="filter-layout">
<div class="govuk-button-group app-filter-toggle"> <div class="govuk-button-group app-filter-toggle govuk-!-margin-bottom-6">
<% if current_page?(controller: 'lettings_logs', action: 'index') %> <% if current_page?(controller: 'lettings_logs', action: 'index') %>
<%= govuk_button_to "Create a new lettings log", lettings_logs_path %> <%= govuk_button_to "Create a new lettings log", lettings_logs_path, class: "govuk-!-margin-right-6" %>
<% end %> <% end %>
<% if FeatureToggle.sales_log_enabled? && current_page?(controller: 'sales_logs', action: 'index') %> <% if FeatureToggle.sales_log_enabled? && current_page?(controller: 'sales_logs', action: 'index') %>
<%= govuk_button_to "Create a new sales log", sales_logs_path %> <%= govuk_button_to "Create a new sales log", sales_logs_path, class: "govuk-!-margin-right-6" %>
<% end %>
<% if FeatureToggle.bulk_upload_logs? %>
<%= govuk_button_link_to "Upload #{log_type_for_controller(controller)} logs in bulk", bulk_upload_path_for_controller(controller, id: "start"), secondary: true %>
<% end %> <% end %>
<%#= govuk_link_to "Upload logs", bulk_upload_lettings_logs_path %>
</div> </div>
<%= render partial: "log_filters" %> <%= render partial: "log_filters" %>

4
config/initializers/feature_toggle.rb

@ -22,4 +22,8 @@ class FeatureToggle
def self.managing_for_other_user_enabled? def self.managing_for_other_user_enabled?
!Rails.env.production? !Rails.env.production?
end end
def self.bulk_upload_logs?
!Rails.env.production?
end
end end

12
config/locales/en.yml

@ -38,6 +38,18 @@ en:
create_password: "Create a password to finish setting up your account" create_password: "Create a password to finish setting up your account"
reset_password: "Reset your password" reset_password: "Reset your password"
activemodel:
errors:
models:
forms/bulk_upload_lettings/year:
attributes:
year:
blank: You must select a collection period to upload for
forms/bulk_upload_sales/year:
attributes:
year:
blank: You must select a collection period to upload for
activerecord: activerecord:
errors: errors:
models: models:

14
config/routes.rb

@ -111,6 +111,12 @@ Rails.application.routes.draw do
get "csv-download", to: "lettings_logs#download_csv" get "csv-download", to: "lettings_logs#download_csv"
post "email-csv", to: "lettings_logs#email_csv" post "email-csv", to: "lettings_logs#email_csv"
get "csv-confirmation", to: "lettings_logs#csv_confirmation" get "csv-confirmation", to: "lettings_logs#csv_confirmation"
resources :bulk_upload_lettings_logs, path: "bulk-upload-logs" do
collection do
get :start
end
end
end end
member do member do
@ -130,6 +136,14 @@ Rails.application.routes.draw do
end end
resources :sales_logs, path: "/sales-logs" do resources :sales_logs, path: "/sales-logs" do
collection do
resources :bulk_upload_sales_logs, path: "bulk-upload-logs" do
collection do
get :start
end
end
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"

BIN
public/files/bulk-upload-lettings-template-v1.xlsx

Binary file not shown.

BIN
public/files/bulk-upload-sales-template-v1.xlsx

Binary file not shown.

51
spec/features/bulk_upload_lettings_logs_spec.rb

@ -0,0 +1,51 @@
require "rails_helper"
RSpec.describe "Bulk upload lettings log" do
let(:user) { create(:user) }
before do
sign_in user
end
context "when during crossover period" do
it "shows journey with year option" 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("Which year")
click_button("Continue")
expect(page).to have_content("You must select a collection period to upload for")
choose("2022/2023")
click_button("Continue")
click_link("Back")
expect(page.find_field("form-year-2022-field")).to be_checked
click_button("Continue")
expect(page).to have_content("Upload lettings logs in bulk (2022/23)")
click_button("Continue")
expect(page).to have_content("Upload your file")
end
end
end
context "when not it crossover period" do
it "shows journey with year option" 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("Upload lettings logs in bulk (2022/23)")
click_button("Continue")
expect(page).to have_content("Upload your file")
end
end
end
end

51
spec/features/bulk_upload_sales_logs_spec.rb

@ -0,0 +1,51 @@
require "rails_helper"
RSpec.describe "Bulk upload sales log" do
let(:user) { create(:user) }
before do
sign_in user
end
context "when during crossover period" do
it "shows journey with year option" do
Timecop.freeze(2023, 6, 1) do
visit("/sales-logs")
expect(page).to have_link("Upload sales logs in bulk")
click_link("Upload sales logs in bulk")
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("2022/2023")
click_button("Continue")
click_link("Back")
expect(page.find_field("form-year-2022-field")).to be_checked
click_button("Continue")
expect(page).to have_content("Upload sales logs in bulk (2022/23)")
click_button("Continue")
expect(page).to have_content("Upload your file")
end
end
end
context "when not it crossover period" do
it "shows journey with year option" do
Timecop.freeze(2023, 10, 1) do
visit("/sales-logs")
expect(page).to have_link("Upload sales logs in bulk")
click_link("Upload sales logs in bulk")
expect(page).to have_content("Upload sales logs in bulk (2022/23)")
click_button("Continue")
expect(page).to have_content("Upload your file")
end
end
end
end

34
spec/models/form_spec.rb

@ -235,4 +235,38 @@ RSpec.describe Form, type: :model do
expect(form.sections[1].class).to eq(Form::Sales::Sections::PropertyInformation) expect(form.sections[1].class).to eq(Form::Sales::Sections::PropertyInformation)
end end
end end
describe "#in_crossover_period?" do
context "when now not specified" do
context "when after end period" do
subject(:form) { described_class.new(nil, 2022, [], "sales") }
it "returns false" do
Timecop.freeze(2023, 8, 1) do
expect(form).not_to be_in_crossover_period
end
end
end
context "when during crossover" do
subject(:form) { described_class.new(nil, 2022, [], "sales") }
it "returns true" do
Timecop.freeze(2023, 6, 1) do
expect(form).to be_in_crossover_period
end
end
end
context "when before crossover" do
subject(:form) { described_class.new(nil, 2022, [], "sales") }
it "returns false" do
Timecop.freeze(2023, 1, 1) do
expect(form).not_to be_in_crossover_period
end
end
end
end
end
end end

12
spec/models/forms/bulk_upload_lettings/year_spec.rb

@ -0,0 +1,12 @@
require "rails_helper"
RSpec.describe Forms::BulkUploadLettings::Year do
subject(:form) { described_class.new }
describe "#options" do
it "returns correct years" do
expect(form.options.map(&:id)).to eql([2022, 2021])
expect(form.options.map(&:name)).to eql(%w[2022/2023 2021/2022])
end
end
end

12
spec/models/forms/bulk_upload_sales/year_spec.rb

@ -0,0 +1,12 @@
require "rails_helper"
RSpec.describe Forms::BulkUploadSales::Year do
subject(:form) { described_class.new }
describe "#options" do
it "returns correct years" do
expect(form.options.map(&:id)).to eql([2022, 2021])
expect(form.options.map(&:name)).to eql(%w[2022/2023 2021/2022])
end
end
end

1
spec/rails_helper.rb

@ -82,6 +82,7 @@ RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, type: :controller config.include Devise::Test::ControllerHelpers, type: :controller
config.include Devise::Test::ControllerHelpers, type: :view config.include Devise::Test::ControllerHelpers, type: :view
config.include Devise::Test::IntegrationHelpers, type: :request config.include Devise::Test::IntegrationHelpers, type: :request
config.include Devise::Test::IntegrationHelpers, type: :feature
config.include ViewComponent::TestHelpers, type: :component config.include ViewComponent::TestHelpers, type: :component
config.include Capybara::RSpecMatchers, type: :component config.include Capybara::RSpecMatchers, type: :component
config.include ActiveJob::TestHelper config.include ActiveJob::TestHelper

32
spec/requests/bulk_upload_lettings_logs_controller_spec.rb

@ -0,0 +1,32 @@
require "rails_helper"
RSpec.describe BulkUploadLettingsLogsController, type: :request do
let(:user) { FactoryBot.create(:user) }
let(:organisation) { user.organisation }
before do
sign_in user
end
describe "GET /lettings-logs/bulk-upload-logs/start" do
context "when not in crossover period" do
it "redirects to /prepare-your-file" do
Timecop.freeze(2022, 1, 1) do
get "/lettings-logs/bulk-upload-logs/start", params: {}
expect(response).to redirect_to("/lettings-logs/bulk-upload-logs/prepare-your-file?form%5Byear%5D=2022")
end
end
end
context "when in crossover period" do
it "redirects to /year" do
Timecop.freeze(2023, 6, 1) do
get "/lettings-logs/bulk-upload-logs/start", params: {}
expect(response).to redirect_to("/lettings-logs/bulk-upload-logs/year")
end
end
end
end
end

32
spec/requests/bulk_upload_sales_logs_controller_spec.rb

@ -0,0 +1,32 @@
require "rails_helper"
RSpec.describe BulkUploadSalesLogsController, type: :request do
let(:user) { FactoryBot.create(:user) }
let(:organisation) { user.organisation }
before do
sign_in user
end
describe "GET /sales-logs/bulk-upload-logs/start" do
context "when not in crossover period" do
it "redirects to /prepare-your-file" do
Timecop.freeze(2022, 1, 1) do
get "/sales-logs/bulk-upload-logs/start", params: {}
expect(response).to redirect_to("/sales-logs/bulk-upload-logs/prepare-your-file?form%5Byear%5D=2022")
end
end
end
context "when in crossover period" do
it "redirects to /year" do
Timecop.freeze(2023, 6, 1) do
get "/sales-logs/bulk-upload-logs/start", params: {}
expect(response).to redirect_to("/sales-logs/bulk-upload-logs/year")
end
end
end
end
end
Loading…
Cancel
Save