Browse Source
* Deduplicate BU forms * Update and fix specs * Update missed files * Deduplicate resume forms * Update copy * Deduplicate soft validations formsmain
kosiakkatrina
4 days ago
committed by
GitHub
46 changed files with 444 additions and 1068 deletions
@ -1,22 +1,23 @@
|
||||
module Forms |
||||
module BulkUploadLettings |
||||
module BulkUploadForm |
||||
class CheckingFile |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :log_type |
||||
attribute :year, :integer |
||||
attribute :organisation_id, :integer |
||||
|
||||
def view_path |
||||
"bulk_upload_lettings_logs/forms/checking_file" |
||||
"bulk_upload_#{log_type}_logs/forms/checking_file" |
||||
end |
||||
|
||||
def back_path |
||||
if organisation_id.present? |
||||
lettings_logs_organisation_path(organisation_id) |
||||
send("#{log_type}_logs_organisation_path", organisation_id) |
||||
else |
||||
bulk_upload_lettings_log_path(id: "start") |
||||
send("bulk_upload_#{log_type}_log_path", id: "start") |
||||
end |
||||
end |
||||
|
@ -1,60 +0,0 @@
|
||||
module Forms |
||||
module BulkUploadLettings |
||||
class PrepareYourFile |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :year, :integer |
||||
attribute :needstype, :integer |
||||
attribute :organisation_id, :integer |
||||
|
||||
def view_path |
||||
case year |
||||
when 2023 |
||||
"bulk_upload_lettings_logs/forms/prepare_your_file_2023" |
||||
when 2024 |
||||
"bulk_upload_lettings_logs/forms/prepare_your_file_2024" |
||||
end |
||||
end |
||||
|
||||
def back_path |
||||
if have_choice_of_year? |
||||
Rails.application.routes.url_helpers.bulk_upload_lettings_log_path(id: "year", form: { year:, organisation_id: }.compact) |
||||
elsif organisation_id.present? |
||||
lettings_logs_organisation_path(organisation_id) |
||||
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:, needstype:, organisation_id: }.compact) |
||||
end |
||||
|
||||
def template_path |
||||
download_mandatory_collection_resource_path(year:, log_type: "lettings", resource_type: "bulk_upload_template") |
||||
end |
||||
|
||||
def specification_path |
||||
download_mandatory_collection_resource_path(year:, log_type: "lettings", resource_type: "bulk_upload_specification") |
||||
end |
||||
|
||||
def year_combo |
||||
"#{year} to #{year + 1}" |
||||
end |
||||
|
||||
def save! |
||||
true |
||||
end |
||||
|
||||
private |
||||
|
||||
def have_choice_of_year? |
||||
return true if FeatureToggle.allow_future_form_use? |
||||
|
||||
FormHandler.instance.lettings_in_crossover_period? |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,55 +0,0 @@
|
||||
module Forms |
||||
module BulkUploadLettingsResume |
||||
class Confirm |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :bulk_upload |
||||
|
||||
def view_path |
||||
"bulk_upload_lettings_resume/confirm" |
||||
end |
||||
|
||||
def back_path |
||||
page_bulk_upload_lettings_resume_path(bulk_upload, page: "fix-choice") |
||||
end |
||||
|
||||
def next_path |
||||
resume_bulk_upload_lettings_result_path(bulk_upload) |
||||
end |
||||
|
||||
def error_report_path |
||||
if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors? |
||||
summary_bulk_upload_lettings_result_path(bulk_upload) |
||||
else |
||||
bulk_upload_lettings_result_path(bulk_upload) |
||||
end |
||||
end |
||||
|
||||
def save! |
||||
ApplicationRecord.transaction do |
||||
processor = BulkUpload::Processor.new(bulk_upload:) |
||||
processor.approve |
||||
|
||||
bulk_upload.update!(choice: "create-fix-inline") |
||||
end |
||||
|
||||
true |
||||
end |
||||
|
||||
def preflight_valid? |
||||
bulk_upload.choice != "create-fix-inline" && bulk_upload.choice != "bulk-confirm-soft-validations" |
||||
end |
||||
|
||||
def preflight_redirect |
||||
case bulk_upload.choice |
||||
when "create-fix-inline" |
||||
page_bulk_upload_lettings_resume_path(bulk_upload, :chosen) |
||||
when "bulk-confirm-soft-validations" |
||||
page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, :chosen) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,28 +0,0 @@
|
||||
module Forms |
||||
module BulkUploadLettingsResume |
||||
class DeletionReport |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :bulk_upload |
||||
|
||||
def view_path |
||||
"bulk_upload_lettings_resume/deletion_report" |
||||
end |
||||
|
||||
def preflight_valid? |
||||
bulk_upload.choice != "create-fix-inline" && bulk_upload.choice != "bulk-confirm-soft-validations" |
||||
end |
||||
|
||||
def preflight_redirect |
||||
case bulk_upload.choice |
||||
when "create-fix-inline" |
||||
page_bulk_upload_lettings_resume_path(bulk_upload, :chosen) |
||||
when "bulk-confirm-soft-validations" |
||||
page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, :chosen) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,74 +0,0 @@
|
||||
module Forms |
||||
module BulkUploadLettingsResume |
||||
class FixChoice |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :bulk_upload |
||||
attribute :choice, :string |
||||
|
||||
validates :choice, presence: true, |
||||
inclusion: { in: %w[create-fix-inline upload-again] } |
||||
|
||||
def options |
||||
[ |
||||
OpenStruct.new(id: "create-fix-inline", name: "Upload these logs and fix errors on CORE site"), |
||||
OpenStruct.new(id: "upload-again", name: "Fix errors in the CSV and upload the file again"), |
||||
] |
||||
end |
||||
|
||||
def view_path |
||||
"bulk_upload_lettings_resume/fix_choice" |
||||
end |
||||
|
||||
def next_path |
||||
case choice |
||||
when "create-fix-inline" |
||||
page_bulk_upload_lettings_resume_path(bulk_upload, page: "confirm") |
||||
when "upload-again" |
||||
error_report_path |
||||
else |
||||
raise "invalid choice" |
||||
end |
||||
end |
||||
|
||||
def error_report_path |
||||
if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors? |
||||
summary_bulk_upload_lettings_result_path(bulk_upload) |
||||
else |
||||
bulk_upload_lettings_result_path(bulk_upload) |
||||
end |
||||
end |
||||
|
||||
def recommendation |
||||
if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors? |
||||
"We recommend fixing these errors in the CSV, as you may be able to edit multiple fields at once. However, you can also upload these logs and fix the errors on the CORE site." |
||||
else |
||||
"We recommend uploading logs and fixing errors on site as you can easily see the questions and select the appropriate answer. However, you can also fix these errors in the CSV." |
||||
end |
||||
end |
||||
|
||||
def save! |
||||
bulk_upload.update!(choice:) if choice == "upload-again" |
||||
|
||||
true |
||||
end |
||||
|
||||
def preflight_valid? |
||||
bulk_upload.choice.blank? |
||||
end |
||||
|
||||
def preflight_redirect |
||||
case bulk_upload.choice |
||||
when "create-fix-inline" |
||||
page_bulk_upload_lettings_resume_path(bulk_upload, :chosen) |
||||
when "bulk-confirm-soft-validations" |
||||
page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, :chosen) |
||||
else |
||||
bulk_upload_lettings_result_path(bulk_upload) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,31 +0,0 @@
|
||||
module Forms |
||||
module BulkUploadLettingsSoftValidationsCheck |
||||
class Chosen |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :bulk_upload |
||||
|
||||
def view_path |
||||
"bulk_upload_lettings_soft_validations_check/chosen" |
||||
end |
||||
|
||||
def back_path |
||||
lettings_logs_path |
||||
end |
||||
|
||||
def next_path |
||||
lettings_logs_path |
||||
end |
||||
|
||||
def save! |
||||
true |
||||
end |
||||
|
||||
def preflight_valid? |
||||
true |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,22 +1,23 @@
|
||||
module Forms |
||||
module BulkUploadLettingsResume |
||||
module BulkUploadResume |
||||
class Chosen |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :log_type |
||||
attribute :bulk_upload |
||||
|
||||
def view_path |
||||
bulk_upload.completed? ? "bulk_upload_lettings_resume/completed" : "bulk_upload_lettings_resume/chosen" |
||||
bulk_upload.completed? ? "bulk_upload_#{log_type}_resume/completed" : "bulk_upload_#{log_type}_resume/chosen" |
||||
end |
||||
|
||||
def back_path |
||||
lettings_logs_path |
||||
send("#{log_type}_logs_path") |
||||
end |
||||
|
||||
def next_path |
||||
lettings_logs_path |
||||
send("#{log_type}_logs_path") |
||||
end |
||||
|
||||
def save! |
@ -1,32 +0,0 @@
|
||||
module Forms |
||||
module BulkUploadSales |
||||
class CheckingFile |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :year, :integer |
||||
attribute :organisation_id, :integer |
||||
|
||||
def view_path |
||||
"bulk_upload_sales_logs/forms/checking_file" |
||||
end |
||||
|
||||
def back_path |
||||
if organisation_id.present? |
||||
sales_logs_organisation_path(organisation_id) |
||||
else |
||||
bulk_upload_sales_log_path(id: "start") |
||||
end |
||||
end |
||||
|
||||
def year_combo |
||||
"#{year} to #{year + 1}" |
||||
end |
||||
|
||||
def save! |
||||
true |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,51 +0,0 @@
|
||||
module Forms |
||||
module BulkUploadSales |
||||
class Guidance |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
include CollectionTimeHelper |
||||
|
||||
attribute :year, :integer |
||||
attribute :referrer |
||||
attribute :organisation_id, :integer |
||||
|
||||
def initialize(params) |
||||
super(params) |
||||
|
||||
self.year = current_collection_start_year if year.nil? |
||||
end |
||||
|
||||
def view_path |
||||
"bulk_upload_shared/guidance" |
||||
end |
||||
|
||||
def back_path |
||||
case referrer |
||||
when "prepare-your-file" |
||||
bulk_upload_sales_log_path(id: "prepare-your-file", form: { year:, organisation_id: }.compact) |
||||
when "home" |
||||
root_path |
||||
else |
||||
guidance_path |
||||
end |
||||
end |
||||
|
||||
def lettings_template_path |
||||
Forms::BulkUploadLettings::PrepareYourFile.new(year:).template_path |
||||
end |
||||
|
||||
def lettings_specification_path |
||||
Forms::BulkUploadLettings::PrepareYourFile.new(year:).specification_path |
||||
end |
||||
|
||||
def sales_template_path |
||||
Forms::BulkUploadSales::PrepareYourFile.new(year:).template_path |
||||
end |
||||
|
||||
def sales_specification_path |
||||
Forms::BulkUploadSales::PrepareYourFile.new(year:).specification_path |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,83 +0,0 @@
|
||||
require "shellwords" |
||||
|
||||
module Forms |
||||
module BulkUploadSales |
||||
class UploadYourFile |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :year, :integer |
||||
attribute :file |
||||
attribute :current_user |
||||
attribute :organisation_id, :integer |
||||
|
||||
validates :file, presence: true |
||||
validate :validate_file_is_csv |
||||
validate :validate_file_size |
||||
|
||||
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:, organisation_id: }.compact) |
||||
end |
||||
|
||||
def year_combo |
||||
"#{year} to #{year + 1}" |
||||
end |
||||
|
||||
def next_path |
||||
bulk_upload_sales_log_path(id: "checking-file", form: { year:, organisation_id: }.compact) |
||||
end |
||||
|
||||
def save! |
||||
bulk_upload = BulkUpload.create!( |
||||
user: current_user, |
||||
log_type: BulkUpload.log_types[:sales], |
||||
year:, |
||||
filename: file.original_filename, |
||||
organisation_id: (organisation_id if current_user.support?) || current_user.organisation_id, |
||||
) |
||||
|
||||
storage_service.write_file(bulk_upload.identifier, File.read(file.path)) |
||||
|
||||
ProcessBulkUploadJob.perform_later(bulk_upload:) |
||||
|
||||
true |
||||
end |
||||
|
||||
private |
||||
|
||||
def storage_service |
||||
@storage_service ||= if FeatureToggle.upload_enabled? |
||||
Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["BULK_UPLOAD_BUCKET"]) |
||||
else |
||||
Storage::LocalDiskService.new |
||||
end |
||||
end |
||||
|
||||
def validate_file_is_csv |
||||
return unless file |
||||
|
||||
argv = %W[file --brief --mime-type -- #{file.path}] |
||||
output = `#{argv.shelljoin}` |
||||
|
||||
unless output.match?(/text\/csv|text\/plain/) |
||||
errors.add(:file, :not_csv) |
||||
end |
||||
end |
||||
|
||||
MAX_FILE_SIZE = 10.megabytes |
||||
|
||||
def validate_file_size |
||||
return unless file |
||||
|
||||
if file.size > MAX_FILE_SIZE |
||||
errors.add(:file, :file_too_large) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,50 +0,0 @@
|
||||
module Forms |
||||
module BulkUploadSales |
||||
class Year |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :year, :integer |
||||
attribute :organisation_id, :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} to #{year + 1}") |
||||
end |
||||
end |
||||
|
||||
def back_path |
||||
if organisation_id.present? |
||||
sales_logs_organisation_path(organisation_id) |
||||
else |
||||
sales_logs_path |
||||
end |
||||
end |
||||
|
||||
def next_path |
||||
bulk_upload_sales_log_path(id: "prepare-your-file", form: { year:, organisation_id: }.compact) |
||||
end |
||||
|
||||
def save! |
||||
true |
||||
end |
||||
|
||||
private |
||||
|
||||
def possible_years |
||||
[ |
||||
FormHandler.instance.current_sales_form.start_date.year, |
||||
(FormHandler.instance.previous_sales_form.start_date.year if FormHandler.instance.sales_in_crossover_period?), |
||||
(FormHandler.instance.next_sales_form.start_date.year if FeatureToggle.allow_future_form_use?), |
||||
].compact |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,31 +0,0 @@
|
||||
module Forms |
||||
module BulkUploadSalesSoftValidationsCheck |
||||
class Chosen |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :bulk_upload |
||||
|
||||
def view_path |
||||
"bulk_upload_sales_soft_validations_check/chosen" |
||||
end |
||||
|
||||
def back_path |
||||
sales_logs_path |
||||
end |
||||
|
||||
def next_path |
||||
sales_logs_path |
||||
end |
||||
|
||||
def save! |
||||
true |
||||
end |
||||
|
||||
def preflight_valid? |
||||
true |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,47 +0,0 @@
|
||||
module Forms |
||||
module BulkUploadSalesSoftValidationsCheck |
||||
class Confirm |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :bulk_upload |
||||
|
||||
def view_path |
||||
"bulk_upload_sales_soft_validations_check/confirm" |
||||
end |
||||
|
||||
def back_path |
||||
page_bulk_upload_sales_soft_validations_check_path(bulk_upload, page: "confirm-soft-errors") |
||||
end |
||||
|
||||
def next_path |
||||
sales_logs_path |
||||
end |
||||
|
||||
def save! |
||||
ApplicationRecord.transaction do |
||||
processor = BulkUpload::Processor.new(bulk_upload:) |
||||
processor.approve_and_confirm_soft_validations |
||||
|
||||
bulk_upload.update!(choice: "bulk-confirm-soft-validations") |
||||
end |
||||
|
||||
true |
||||
end |
||||
|
||||
def preflight_valid? |
||||
bulk_upload.choice != "bulk-confirm-soft-validations" && bulk_upload.choice != "create-fix-inline" |
||||
end |
||||
|
||||
def preflight_redirect |
||||
case bulk_upload.choice |
||||
when "bulk-confirm-soft-validations" |
||||
page_bulk_upload_sales_soft_validations_check_path(bulk_upload, :chosen) |
||||
when "create-fix-inline" |
||||
page_bulk_upload_sales_resume_path(bulk_upload, :chosen) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,53 +0,0 @@
|
||||
module Forms |
||||
module BulkUploadSalesSoftValidationsCheck |
||||
class ConfirmSoftErrors |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :bulk_upload |
||||
attribute :confirm_soft_errors, :string |
||||
|
||||
validates :confirm_soft_errors, presence: true |
||||
|
||||
def options |
||||
[ |
||||
OpenStruct.new(id: "yes", name: "Yes, these fields are correct"), |
||||
OpenStruct.new(id: "no", name: "No, there are errors"), |
||||
] |
||||
end |
||||
|
||||
def view_path |
||||
"bulk_upload_sales_soft_validations_check/confirm_soft_errors" |
||||
end |
||||
|
||||
def next_path |
||||
case confirm_soft_errors |
||||
when "no" |
||||
page_bulk_upload_sales_resume_path(bulk_upload, page: "fix-choice", soft_errors_only: true) |
||||
when "yes" |
||||
page_bulk_upload_sales_soft_validations_check_path(bulk_upload, page: "confirm") |
||||
else |
||||
raise "invalid choice" |
||||
end |
||||
end |
||||
|
||||
def save! |
||||
true |
||||
end |
||||
|
||||
def preflight_valid? |
||||
bulk_upload.choice != "bulk-confirm-soft-validations" && bulk_upload.choice != "create-fix-inline" |
||||
end |
||||
|
||||
def preflight_redirect |
||||
case bulk_upload.choice |
||||
when "bulk-confirm-soft-validations" |
||||
page_bulk_upload_sales_soft_validations_check_path(bulk_upload, :chosen) |
||||
when "create-fix-inline" |
||||
page_bulk_upload_sales_resume_path(bulk_upload, :chosen) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,22 +1,23 @@
|
||||
module Forms |
||||
module BulkUploadSalesResume |
||||
module BulkUploadSoftValidationsCheck |
||||
class Chosen |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :log_type |
||||
attribute :bulk_upload |
||||
|
||||
def view_path |
||||
bulk_upload.completed? ? "bulk_upload_sales_resume/completed" : "bulk_upload_sales_resume/chosen" |
||||
"bulk_upload_#{log_type}_soft_validations_check/chosen" |
||||
end |
||||
|
||||
def back_path |
||||
sales_logs_path |
||||
send("#{log_type}_logs_path") |
||||
end |
||||
|
||||
def next_path |
||||
sales_logs_path |
||||
send("#{log_type}_logs_path") |
||||
end |
||||
|
||||
def save! |
@ -0,0 +1,117 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Forms::BulkUploadForm::Guidance do |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
subject(:bu_guidance) { described_class.new(year:, referrer:, log_type:) } |
||||
|
||||
let(:year) { 2024 } |
||||
let(:log_type) { "sales" } |
||||
let(:referrer) { nil } |
||||
|
||||
describe "sales" do |
||||
describe "#back_path" do |
||||
context "when referrer is prepare-your-file" do |
||||
let(:referrer) { "prepare-your-file" } |
||||
|
||||
it "returns the prepare your file path" do |
||||
expect(bu_guidance.back_path).to eq bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: }) |
||||
end |
||||
end |
||||
|
||||
context "when referrer is home" do |
||||
let(:referrer) { "home" } |
||||
|
||||
it "returns the root path" do |
||||
expect(bu_guidance.back_path).to eq root_path |
||||
end |
||||
end |
||||
|
||||
context "when referrer is guidance" do |
||||
let(:referrer) { "guidance" } |
||||
|
||||
it "returns the main guidance page path" do |
||||
expect(bu_guidance.back_path).to eq guidance_path |
||||
end |
||||
end |
||||
|
||||
context "when referrer is absent" do |
||||
let(:referrer) { nil } |
||||
|
||||
it "returns the main guidance page path" do |
||||
expect(bu_guidance.back_path).to eq guidance_path |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe "year" do |
||||
context "when year is not provided" do |
||||
let(:year) { nil } |
||||
|
||||
before do |
||||
# rubocop:disable RSpec/AnyInstance |
||||
allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_start_year).and_return(2030) |
||||
# rubocop:enable RSpec/AnyInstance |
||||
end |
||||
|
||||
it "is set to the current collection start year" do |
||||
expect(bu_guidance.year).to eq(2030) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe "lettings" do |
||||
let(:log_type) { "lettings" } |
||||
|
||||
describe "#back_path" do |
||||
context "when referrer is prepare-your-file" do |
||||
let(:referrer) { "prepare-your-file" } |
||||
|
||||
it "returns the prepare your file path" do |
||||
expect(bu_guidance.back_path).to eq bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: }) |
||||
end |
||||
end |
||||
|
||||
context "when referrer is home" do |
||||
let(:referrer) { "home" } |
||||
|
||||
it "returns the root path" do |
||||
expect(bu_guidance.back_path).to eq root_path |
||||
end |
||||
end |
||||
|
||||
context "when referrer is guidance" do |
||||
let(:referrer) { "guidance" } |
||||
|
||||
it "returns the main guidance page path" do |
||||
expect(bu_guidance.back_path).to eq guidance_path |
||||
end |
||||
end |
||||
|
||||
context "when referrer is absent" do |
||||
let(:referrer) { nil } |
||||
|
||||
it "returns the main guidance page path" do |
||||
expect(bu_guidance.back_path).to eq guidance_path |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe "year" do |
||||
context "when year is not provided" do |
||||
let(:year) { nil } |
||||
|
||||
before do |
||||
# rubocop:disable RSpec/AnyInstance |
||||
allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_start_year).and_return(2030) |
||||
# rubocop:enable RSpec/AnyInstance |
||||
end |
||||
|
||||
it "is set to the current collection start year" do |
||||
expect(bu_guidance.year).to eq(2030) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,100 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Forms::BulkUploadForm::UploadYourFile do |
||||
subject(:form) { described_class.new(year:, file:, current_user:, log_type:) } |
||||
|
||||
let(:year) { 2022 } |
||||
let(:actual_file) { File.open(file_fixture("blank_bulk_upload_sales.csv")) } |
||||
let(:file) do |
||||
ActionDispatch::Http::UploadedFile.new( |
||||
tempfile: actual_file, |
||||
filename: "my-file.csv", |
||||
) |
||||
end |
||||
let(:current_user) { create(:user) } |
||||
let(:mock_storage_service) { instance_double("S3Service") } |
||||
|
||||
before do |
||||
vcap_services = { "aws-s3-bucket" => {} } |
||||
|
||||
allow(ENV).to receive(:[]) |
||||
allow(ENV).to receive(:[]).with("VCAP_SERVICES").and_return(vcap_services.to_json) |
||||
|
||||
allow(Storage::S3Service).to receive(:new).and_return(mock_storage_service) |
||||
allow(mock_storage_service).to receive(:write_file) |
||||
end |
||||
|
||||
describe "lettings" do |
||||
let(:log_type) { "lettings" } |
||||
|
||||
describe "#save" do |
||||
it "persists a BulkUpload" do |
||||
expect { form.save! }.to change(BulkUpload, :count).by(1) |
||||
end |
||||
|
||||
it "persists a BulkUpload correctly" do |
||||
form.save! |
||||
|
||||
bulk_upload = BulkUpload.last |
||||
|
||||
expect(bulk_upload.user).to eql(current_user) |
||||
expect(bulk_upload.log_type).to eql("lettings") |
||||
expect(bulk_upload.year).to eql(year) |
||||
expect(bulk_upload.filename).to eql("my-file.csv") |
||||
expect(bulk_upload.identifier).to be_present |
||||
end |
||||
|
||||
it "uploads file via storage service" do |
||||
form.save! |
||||
|
||||
bulk_upload = BulkUpload.last |
||||
|
||||
expect(Storage::S3Service).to have_received(:new) |
||||
expect(mock_storage_service).to have_received(:write_file).with(bulk_upload.identifier, actual_file.read) |
||||
end |
||||
|
||||
it "enqueues job to process bulk upload" do |
||||
expect { |
||||
form.save! |
||||
}.to have_enqueued_job(ProcessBulkUploadJob) |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe "sales" do |
||||
let(:log_type) { "sales" } |
||||
|
||||
describe "#save" do |
||||
it "persists a BulkUpload" do |
||||
expect { form.save! }.to change(BulkUpload, :count).by(1) |
||||
end |
||||
|
||||
it "persists a BulkUpload correctly" do |
||||
form.save! |
||||
|
||||
bulk_upload = BulkUpload.last |
||||
|
||||
expect(bulk_upload.user).to eql(current_user) |
||||
expect(bulk_upload.log_type).to eql("sales") |
||||
expect(bulk_upload.year).to eql(year) |
||||
expect(bulk_upload.filename).to eql("my-file.csv") |
||||
expect(bulk_upload.identifier).to be_present |
||||
end |
||||
|
||||
it "uploads file via storage service" do |
||||
form.save! |
||||
|
||||
bulk_upload = BulkUpload.last |
||||
|
||||
expect(Storage::S3Service).to have_received(:new) |
||||
expect(mock_storage_service).to have_received(:write_file).with(bulk_upload.identifier, actual_file.read) |
||||
end |
||||
|
||||
it "enqueues job to process bulk upload" do |
||||
expect { |
||||
form.save! |
||||
}.to have_enqueued_job(ProcessBulkUploadJob) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,101 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Forms::BulkUploadForm::Year do |
||||
subject(:form) { described_class.new(log_type:) } |
||||
|
||||
describe "lettings" do |
||||
let(:log_type) { "lettings" } |
||||
|
||||
describe "#options" do |
||||
before do |
||||
allow(FormHandler.instance).to receive(:lettings_forms).and_return({ "current_lettings" => instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) }) |
||||
allow(FormHandler.instance).to receive(:previous_lettings_form).and_return(instance_double(Form, start_date: Time.zone.local(2023, 4, 1))) |
||||
allow(FormHandler.instance).to receive(:next_lettings_form).and_return(instance_double(Form, start_date: Time.zone.local(2025, 4, 1))) |
||||
end |
||||
|
||||
context "when in a crossover period" do |
||||
before do |
||||
allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(true) |
||||
end |
||||
|
||||
it "returns current and previous years" do |
||||
expect(form.options.map(&:id)).to eql([2024, 2023]) |
||||
expect(form.options.map(&:name)).to eql(["2024 to 2025", "2023 to 2024"]) |
||||
end |
||||
end |
||||
|
||||
context "when not in a crossover period" do |
||||
before do |
||||
allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(false) |
||||
end |
||||
|
||||
it "returns the current year" do |
||||
expect(form.options.map(&:id)).to eql([2024]) |
||||
expect(form.options.map(&:name)).to eql(["2024 to 2025"]) |
||||
end |
||||
end |
||||
|
||||
context "when allow_future_form_use is toggled on" do |
||||
before do |
||||
allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(false) |
||||
allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true) |
||||
end |
||||
|
||||
it "returns current and next years" do |
||||
expect(form.options.map(&:id)).to eql([2024, 2025]) |
||||
expect(form.options.map(&:name)).to eql(["2024 to 2025", "2025 to 2026"]) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe "sales" do |
||||
let(:log_type) { "sales" } |
||||
|
||||
describe "#options" do |
||||
before do |
||||
allow(FormHandler.instance).to receive(:sales_forms).and_return({ "current_sales" => instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) }) |
||||
allow(FormHandler.instance).to receive(:previous_sales_form).and_return(instance_double(Form, start_date: Time.zone.local(2023, 4, 1))) |
||||
allow(FormHandler.instance).to receive(:next_sales_form).and_return(instance_double(Form, start_date: Time.zone.local(2025, 4, 1))) |
||||
end |
||||
|
||||
context "when in a crossover period" do |
||||
before do |
||||
allow(FormHandler.instance).to receive(:sales_in_crossover_period?).and_return(true) |
||||
end |
||||
|
||||
it "returns current and previous years" do |
||||
expect(form.options.map(&:id)).to eql([2024, 2023]) |
||||
expect(form.options.map(&:name)).to eql(["2024 to 2025", "2023 to 2024"]) |
||||
end |
||||
end |
||||
|
||||
context "when not in a crossover period" do |
||||
before do |
||||
allow(FormHandler.instance).to receive(:sales_in_crossover_period?).and_return(false) |
||||
end |
||||
|
||||
it "returns the current year" do |
||||
expect(form.options.map(&:id)).to eql([2024]) |
||||
expect(form.options.map(&:name)).to eql(["2024 to 2025"]) |
||||
end |
||||
end |
||||
|
||||
context "when allow_future_form_use is toggled on" do |
||||
before do |
||||
allow(FormHandler.instance).to receive(:sales_in_crossover_period?).and_return(false) |
||||
allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true) |
||||
end |
||||
|
||||
after do |
||||
Timecop.return |
||||
end |
||||
|
||||
it "returns current and next years" do |
||||
expect(form.options.map(&:id)).to eql([2024, 2025]) |
||||
expect(form.options.map(&:name)).to eql(["2024 to 2025", "2025 to 2026"]) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,60 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Forms::BulkUploadLettings::Guidance do |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
subject(:bu_guidance) { described_class.new(year:, referrer:) } |
||||
|
||||
let(:year) { 2024 } |
||||
let(:referrer) { nil } |
||||
|
||||
describe "#back_path" do |
||||
context "when referrer is prepare-your-file" do |
||||
let(:referrer) { "prepare-your-file" } |
||||
|
||||
it "returns the prepare your file path" do |
||||
expect(bu_guidance.back_path).to eq bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: }) |
||||
end |
||||
end |
||||
|
||||
context "when referrer is home" do |
||||
let(:referrer) { "home" } |
||||
|
||||
it "returns the root path" do |
||||
expect(bu_guidance.back_path).to eq root_path |
||||
end |
||||
end |
||||
|
||||
context "when referrer is guidance" do |
||||
let(:referrer) { "guidance" } |
||||
|
||||
it "returns the main guidance page path" do |
||||
expect(bu_guidance.back_path).to eq guidance_path |
||||
end |
||||
end |
||||
|
||||
context "when referrer is absent" do |
||||
let(:referrer) { nil } |
||||
|
||||
it "returns the main guidance page path" do |
||||
expect(bu_guidance.back_path).to eq guidance_path |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe "year" do |
||||
context "when year is not provided" do |
||||
let(:year) { nil } |
||||
|
||||
before do |
||||
# rubocop:disable RSpec/AnyInstance |
||||
allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_start_year).and_return(2030) |
||||
# rubocop:enable RSpec/AnyInstance |
||||
end |
||||
|
||||
it "is set to the current collection start year" do |
||||
expect(bu_guidance.year).to eq(2030) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,61 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Forms::BulkUploadLettings::UploadYourFile do |
||||
subject(:form) { described_class.new(year:, needstype:, file:, current_user:) } |
||||
|
||||
let(:year) { 2022 } |
||||
let(:needstype) { 2 } |
||||
let(:actual_file) { File.open(file_fixture("blank_bulk_upload_sales.csv")) } |
||||
let(:file) do |
||||
ActionDispatch::Http::UploadedFile.new( |
||||
tempfile: actual_file, |
||||
filename: "my-file.csv", |
||||
) |
||||
end |
||||
let(:current_user) { create(:user) } |
||||
let(:mock_storage_service) { instance_double("S3Service") } |
||||
|
||||
before do |
||||
vcap_services = { "aws-s3-bucket" => {} } |
||||
|
||||
allow(ENV).to receive(:[]) |
||||
allow(ENV).to receive(:[]).with("VCAP_SERVICES").and_return(vcap_services.to_json) |
||||
|
||||
allow(Storage::S3Service).to receive(:new).and_return(mock_storage_service) |
||||
allow(mock_storage_service).to receive(:write_file) |
||||
end |
||||
|
||||
describe "#save" do |
||||
it "persists a BulkUpload" do |
||||
expect { form.save! }.to change(BulkUpload, :count).by(1) |
||||
end |
||||
|
||||
it "persists a BulkUpload correctly" do |
||||
form.save! |
||||
|
||||
bulk_upload = BulkUpload.last |
||||
|
||||
expect(bulk_upload.user).to eql(current_user) |
||||
expect(bulk_upload.log_type).to eql("lettings") |
||||
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.identifier).to be_present |
||||
end |
||||
|
||||
it "uploads file via storage service" do |
||||
form.save! |
||||
|
||||
bulk_upload = BulkUpload.last |
||||
|
||||
expect(Storage::S3Service).to have_received(:new) |
||||
expect(mock_storage_service).to have_received(:write_file).with(bulk_upload.identifier, actual_file.read) |
||||
end |
||||
|
||||
it "enqueues job to process bulk upload" do |
||||
expect { |
||||
form.save! |
||||
}.to have_enqueued_job(ProcessBulkUploadJob) |
||||
end |
||||
end |
||||
end |
@ -1,47 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Forms::BulkUploadLettings::Year do |
||||
subject(:form) { described_class.new } |
||||
|
||||
describe "#options" do |
||||
before do |
||||
allow(FormHandler.instance).to receive(:lettings_forms).and_return({ "current_lettings" => instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) }) |
||||
allow(FormHandler.instance).to receive(:previous_lettings_form).and_return(instance_double(Form, start_date: Time.zone.local(2023, 4, 1))) |
||||
allow(FormHandler.instance).to receive(:next_lettings_form).and_return(instance_double(Form, start_date: Time.zone.local(2025, 4, 1))) |
||||
end |
||||
|
||||
context "when in a crossover period" do |
||||
before do |
||||
allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(true) |
||||
end |
||||
|
||||
it "returns current and previous years" do |
||||
expect(form.options.map(&:id)).to eql([2024, 2023]) |
||||
expect(form.options.map(&:name)).to eql(["2024 to 2025", "2023 to 2024"]) |
||||
end |
||||
end |
||||
|
||||
context "when not in a crossover period" do |
||||
before do |
||||
allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(false) |
||||
end |
||||
|
||||
it "returns the current year" do |
||||
expect(form.options.map(&:id)).to eql([2024]) |
||||
expect(form.options.map(&:name)).to eql(["2024 to 2025"]) |
||||
end |
||||
end |
||||
|
||||
context "when allow_future_form_use is toggled on" do |
||||
before do |
||||
allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(false) |
||||
allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true) |
||||
end |
||||
|
||||
it "returns current and next years" do |
||||
expect(form.options.map(&:id)).to eql([2024, 2025]) |
||||
expect(form.options.map(&:name)).to eql(["2024 to 2025", "2025 to 2026"]) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,60 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Forms::BulkUploadSales::Guidance do |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
subject(:bu_guidance) { described_class.new(year:, referrer:) } |
||||
|
||||
let(:year) { 2024 } |
||||
let(:referrer) { nil } |
||||
|
||||
describe "#back_path" do |
||||
context "when referrer is prepare-your-file" do |
||||
let(:referrer) { "prepare-your-file" } |
||||
|
||||
it "returns the prepare your file path" do |
||||
expect(bu_guidance.back_path).to eq bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: }) |
||||
end |
||||
end |
||||
|
||||
context "when referrer is home" do |
||||
let(:referrer) { "home" } |
||||
|
||||
it "returns the root path" do |
||||
expect(bu_guidance.back_path).to eq root_path |
||||
end |
||||
end |
||||
|
||||
context "when referrer is guidance" do |
||||
let(:referrer) { "guidance" } |
||||
|
||||
it "returns the main guidance page path" do |
||||
expect(bu_guidance.back_path).to eq guidance_path |
||||
end |
||||
end |
||||
|
||||
context "when referrer is absent" do |
||||
let(:referrer) { nil } |
||||
|
||||
it "returns the main guidance page path" do |
||||
expect(bu_guidance.back_path).to eq guidance_path |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe "year" do |
||||
context "when year is not provided" do |
||||
let(:year) { nil } |
||||
|
||||
before do |
||||
# rubocop:disable RSpec/AnyInstance |
||||
allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_start_year).and_return(2030) |
||||
# rubocop:enable RSpec/AnyInstance |
||||
end |
||||
|
||||
it "is set to the current collection start year" do |
||||
expect(bu_guidance.year).to eq(2030) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,59 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Forms::BulkUploadSales::UploadYourFile do |
||||
subject(:form) { described_class.new(year:, file:, current_user:) } |
||||
|
||||
let(:year) { 2022 } |
||||
let(:actual_file) { File.open(file_fixture("blank_bulk_upload_sales.csv")) } |
||||
let(:file) do |
||||
ActionDispatch::Http::UploadedFile.new( |
||||
tempfile: actual_file, |
||||
filename: "my-file.csv", |
||||
) |
||||
end |
||||
let(:current_user) { create(:user) } |
||||
let(:mock_storage_service) { instance_double("S3Service") } |
||||
|
||||
before do |
||||
vcap_services = { "aws-s3-bucket" => {} } |
||||
|
||||
allow(ENV).to receive(:[]) |
||||
allow(ENV).to receive(:[]).with("VCAP_SERVICES").and_return(vcap_services.to_json) |
||||
|
||||
allow(Storage::S3Service).to receive(:new).and_return(mock_storage_service) |
||||
allow(mock_storage_service).to receive(:write_file) |
||||
end |
||||
|
||||
describe "#save" do |
||||
it "persists a BulkUpload" do |
||||
expect { form.save! }.to change(BulkUpload, :count).by(1) |
||||
end |
||||
|
||||
it "persists a BulkUpload correctly" do |
||||
form.save! |
||||
|
||||
bulk_upload = BulkUpload.last |
||||
|
||||
expect(bulk_upload.user).to eql(current_user) |
||||
expect(bulk_upload.log_type).to eql("sales") |
||||
expect(bulk_upload.year).to eql(year) |
||||
expect(bulk_upload.filename).to eql("my-file.csv") |
||||
expect(bulk_upload.identifier).to be_present |
||||
end |
||||
|
||||
it "uploads file via storage service" do |
||||
form.save! |
||||
|
||||
bulk_upload = BulkUpload.last |
||||
|
||||
expect(Storage::S3Service).to have_received(:new) |
||||
expect(mock_storage_service).to have_received(:write_file).with(bulk_upload.identifier, actual_file.read) |
||||
end |
||||
|
||||
it "enqueues job to process bulk upload" do |
||||
expect { |
||||
form.save! |
||||
}.to have_enqueued_job(ProcessBulkUploadJob) |
||||
end |
||||
end |
||||
end |
@ -1,51 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Forms::BulkUploadSales::Year do |
||||
subject(:form) { described_class.new } |
||||
|
||||
describe "#options" do |
||||
before do |
||||
allow(FormHandler.instance).to receive(:sales_forms).and_return({ "current_sales" => instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) }) |
||||
allow(FormHandler.instance).to receive(:previous_sales_form).and_return(instance_double(Form, start_date: Time.zone.local(2023, 4, 1))) |
||||
allow(FormHandler.instance).to receive(:next_sales_form).and_return(instance_double(Form, start_date: Time.zone.local(2025, 4, 1))) |
||||
end |
||||
|
||||
context "when in a crossover period" do |
||||
before do |
||||
allow(FormHandler.instance).to receive(:sales_in_crossover_period?).and_return(true) |
||||
end |
||||
|
||||
it "returns current and previous years" do |
||||
expect(form.options.map(&:id)).to eql([2024, 2023]) |
||||
expect(form.options.map(&:name)).to eql(["2024 to 2025", "2023 to 2024"]) |
||||
end |
||||
end |
||||
|
||||
context "when not in a crossover period" do |
||||
before do |
||||
allow(FormHandler.instance).to receive(:sales_in_crossover_period?).and_return(false) |
||||
end |
||||
|
||||
it "returns the current year" do |
||||
expect(form.options.map(&:id)).to eql([2024]) |
||||
expect(form.options.map(&:name)).to eql(["2024 to 2025"]) |
||||
end |
||||
end |
||||
|
||||
context "when allow_future_form_use is toggled on" do |
||||
before do |
||||
allow(FormHandler.instance).to receive(:sales_in_crossover_period?).and_return(false) |
||||
allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true) |
||||
end |
||||
|
||||
after do |
||||
Timecop.return |
||||
end |
||||
|
||||
it "returns current and next years" do |
||||
expect(form.options.map(&:id)).to eql([2024, 2025]) |
||||
expect(form.options.map(&:name)).to eql(["2024 to 2025", "2025 to 2026"]) |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue