Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

336 lines
14 KiB

require "rails_helper"
RSpec.describe FormHandler do
let(:form_handler) { described_class.instance }
let(:now) { Time.utc(2022, 9, 20) }
around do |example|
Timecop.freeze(now) do
Singleton.__init__(described_class)
example.run
end
end
context "when accessing a form in a different year" do
let(:now) { Time.utc(2021, 8, 3) }
it "is able to load a current lettings form" do
form = form_handler.get_form("current_lettings")
expect(form).to be_a(Form)
expect(form.pages.count).to be_positive
end
it "is able to load a next lettings form" do
form = form_handler.get_form("next_lettings")
expect(form).to be_a(Form)
expect(form.pages.count).to be_positive
end
end
describe "Get all forms" do
it "is able to load all the forms" do
all_forms = form_handler.forms
expect(all_forms.count).to be >= 1
expect(all_forms["current_sales"]).to be_a(Form)
end
context "when in 23/24 period or later" do
let(:now) { Time.utc(2023, 6, 7) }
it "does not load outdated forms" do
all_forms = form_handler.forms
expect(all_forms.keys).not_to include nil
end
it "loads archived forms" do
all_forms = form_handler.forms
expect(all_forms.keys).to include("archived_sales")
expect(all_forms.keys).to include("archived_lettings")
end
end
end
describe "Get specific form" do
let(:now) { Time.utc(2023, 9, 20) }
it "is able to load a current lettings form" do
form = form_handler.get_form("current_lettings")
expect(form).to be_a(Form)
expect(form.pages.count).to be_positive
expect(form.name).to eq("2023_2024_lettings")
end
it "is able to load a previous lettings form" do
form = form_handler.get_form("previous_lettings")
expect(form).to be_a(Form)
expect(form.pages.count).to be_positive
expect(form.name).to eq("2022_2023_lettings")
end
it "is able to load a archived lettings form" do
form = form_handler.get_form("archived_lettings")
expect(form).to be_a(Form)
expect(form.pages.count).to be_positive
expect(form.name).to eq("2021_2022_lettings")
end
it "is able to load a current sales form" do
form = form_handler.get_form("current_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to be_positive
expect(form.name).to eq("2023_2024_sales")
end
it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to be_positive
expect(form.name).to eq("2022_2023_sales")
end
it "is able to load a archived sales form" do
form = form_handler.get_form("archived_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to be_positive
expect(form.name).to eq("2021_2022_sales")
end
end
describe "Current form" do
it "returns the latest form by date" do
form = form_handler.current_lettings_form
expect(form).to be_a(Form)
expect(form.start_date.year).to eq(2022)
end
end
describe "Current collection start year" do
context "when the date is after 1st of April" do
let(:now) { Time.utc(2023, 8, 3) }
it "returns the same year as the current start year" do
expect(form_handler.current_collection_start_year).to eq(2023)
end
it "returns the correct current lettings form name" do
expect(form_handler.form_name_from_start_year(2023, "lettings")).to eq("current_lettings")
end
it "returns the correct previous lettings form name" do
expect(form_handler.form_name_from_start_year(2022, "lettings")).to eq("previous_lettings")
end
it "returns the correct next lettings form name" do
expect(form_handler.form_name_from_start_year(2024, "lettings")).to eq("next_lettings")
end
it "returns the correct archived lettings form name" do
expect(form_handler.form_name_from_start_year(2021, "lettings")).to eq("archived_lettings")
end
it "returns the correct current sales form name" do
expect(form_handler.form_name_from_start_year(2023, "sales")).to eq("current_sales")
end
it "returns the correct previous sales form name" do
expect(form_handler.form_name_from_start_year(2022, "sales")).to eq("previous_sales")
end
it "returns the correct next sales form name" do
expect(form_handler.form_name_from_start_year(2024, "sales")).to eq("next_sales")
end
it "returns the correct archived sales form name" do
expect(form_handler.form_name_from_start_year(2021, "sales")).to eq("archived_sales")
end
it "returns the correct current start date" do
expect(form_handler.current_collection_start_date).to eq(Time.zone.local(2023, 4, 1))
end
end
context "with the date before 1st of April" do
let(:now) { Time.utc(2023, 2, 3) }
it "returns the previous year as the current start year" do
expect(form_handler.current_collection_start_year).to eq(2022)
end
it "returns the correct current lettings form name" do
expect(form_handler.form_name_from_start_year(2022, "lettings")).to eq("current_lettings")
end
it "returns the correct previous lettings form name" do
expect(form_handler.form_name_from_start_year(2021, "lettings")).to eq("previous_lettings")
end
it "returns the correct next lettings form name" do
expect(form_handler.form_name_from_start_year(2023, "lettings")).to eq("next_lettings")
end
it "returns the correct archived lettings form name" do
expect(form_handler.form_name_from_start_year(2020, "lettings")).to eq("archived_lettings")
end
it "returns the correct current sales form name" do
expect(form_handler.form_name_from_start_year(2022, "sales")).to eq("current_sales")
end
it "returns the correct previous sales form name" do
expect(form_handler.form_name_from_start_year(2021, "sales")).to eq("previous_sales")
end
it "returns the correct next sales form name" do
expect(form_handler.form_name_from_start_year(2023, "sales")).to eq("next_sales")
end
it "returns the correct archived sales form name" do
expect(form_handler.form_name_from_start_year(2020, "sales")).to eq("archived_sales")
end
end
end
it "loads the form once at boot time" do
form_handler = described_class.instance
expect(Form).not_to receive(:new).with(:any, "current_sales")
expect(form_handler.get_form("current_sales")).to be_a(Form)
end
it "correctly sets form type and start year" do
form = form_handler.forms["current_lettings"]
expect(form.type).to eq("lettings")
expect(form.start_date.year).to eq(2022)
end
# rubocop:disable RSpec/PredicateMatcher
describe "#in_crossover_period?" do
context "when not in overlapping period" do
it "returns false" do
expect(form_handler.in_crossover_period?(now: Date.new(2023, 1, 1))).to be_falsey
end
end
context "when in overlapping period" do
it "returns true" do
expect(form_handler.in_crossover_period?(now: Date.new(2022, 6, 1))).to be_truthy
end
end
end
describe "lettings_forms" do
context "when current and previous forms are defined in JSON (current collection start year before 2023)" do
let(:now) { Time.utc(2022, 9, 20) }
it "creates a next_lettings form from ruby form objects" do
expect(form_handler.lettings_forms["previous_lettings"]).to be_present
expect(form_handler.lettings_forms["previous_lettings"].start_date.year).to eq(2021)
expect(form_handler.lettings_forms["current_lettings"]).to be_present
expect(form_handler.lettings_forms["current_lettings"].start_date.year).to eq(2022)
expect(form_handler.lettings_forms["next_lettings"]).to be_present
expect(form_handler.lettings_forms["next_lettings"].start_date.year).to eq(2023)
end
end
context "when only previous form is defined in JSON (current collection start year 2023)" do
let(:now) { Time.utc(2023, 9, 20) }
it "creates current_lettings and next_lettings forms from ruby form objects" do
expect(form_handler.lettings_forms["archived_lettings"]).to be_present
expect(form_handler.lettings_forms["archived_lettings"].start_date.year).to eq(2021)
expect(form_handler.lettings_forms["previous_lettings"]).to be_present
expect(form_handler.lettings_forms["previous_lettings"].start_date.year).to eq(2022)
expect(form_handler.lettings_forms["current_lettings"]).to be_present
expect(form_handler.lettings_forms["current_lettings"].start_date.year).to eq(2023)
expect(form_handler.lettings_forms["next_lettings"]).to be_present
expect(form_handler.lettings_forms["next_lettings"].start_date.year).to eq(2024)
end
end
context "when only archived form form is defined in JSON (current collection start year 2024 onwards)" do
let(:now) { Time.utc(2024, 9, 20) }
it "creates previous_lettings, current_lettings and next_lettings forms from ruby form objects and archived form from json" do
expect(form_handler.lettings_forms["archived_lettings"]).to be_present
expect(form_handler.lettings_forms["archived_lettings"].start_date.year).to eq(2022)
expect(form_handler.lettings_forms["previous_lettings"]).to be_present
expect(form_handler.lettings_forms["previous_lettings"].start_date.year).to eq(2023)
expect(form_handler.lettings_forms["current_lettings"]).to be_present
expect(form_handler.lettings_forms["current_lettings"].start_date.year).to eq(2024)
expect(form_handler.lettings_forms["next_lettings"]).to be_present
expect(form_handler.lettings_forms["next_lettings"].start_date.year).to eq(2025)
end
end
end
CLDC-1633 build feature csv download of sales logs (#1568) * create a method on the FormHandler that returns the sales form questions for all years in the order that they appear in the form * update csv email job to accomodate sales log export as well as lettings add to tests to reflec the changes made * write tests to cover the desired functionality of the SalesLogCsvService * create the SalesLogCsvService create a necessary method on the log to enable submission method to be included on the csv derive values for the two halves of previous postcode for export * add relevant links in the UI and pipe everything together in controllers amend organisations controller to have flexibility to download logs of either type add necessary methods to sales log controller, raising shared method to logs controller update routing for amendments and additions extract helper method to build urls for downloading logs within an organisation * correct various linter complaints and tech review suggestions * minor amendment to add old_id and reorder early columns * undo my 'clever' refactor that broke things * refactoring of csv service after some tech review and some UI testing in review app * update tests to include a test of a full export and all values in teh csv * correct minor routing error to ensure correct url is shown and tab selected after requesting csv email * update organisations controller requests spec file to cover new functionality and make a minor amendment to authentication scope in the controller after error found in testing * write request tests for the new functionality in the sales log controller, define authorisation in the controller * minor correction after rubocop's kind suggestion' * various corrections from first pass at PO, tech review, linter, etc * refactor :ordered_sales_questions_for_all_years * first pass at implementing flexible code-based form fixtures for testing * second pass * refactor all tests of :ordered_sales_questions_for_all_years to use new factories * some refactoring in the testing of the csv service * use that fact that params is always available in controllers and don't pass it around, inline some methods calls * correct minor bug to ensure that "Return to logs" link returns to the correct index page * remove reminder comments * write further tests on the manipulation of questions into the csv headers, update factories of form constituents to allow the creation of forms with richer questions * fix linter complaints * minor alterations after rebase to account for changes made on other branches * refactor after code review * tweak fixtures after rebase containing alterations to the factory defaults
2 years ago
CLDC-3438 Update log csv download flow (#2403) * Filter out empty options from selected filters * Redirect to year filter if it is not selected * Add remaining filter questions * Display lettings filters CYA * Add cancel, conditionally display send email * Refactor * Add removed tests * Update method name * Add sales logs filters * Update tests * Set label size on filter questions * Refactor * Deduplicate filter views * Rename methods * Authenticate pages * Update filtering per organisation * Update routing from CYA * lint * Refactor check_your_answers_filters_list * Redirect if year is not given for sales csv * Update formatted organisations methods * Update missing and wrong copy * Update cancel and back buttons * CLDC-3442 Download logs csv per year (#2404) * Specify year in lettings csv download service * Specify year in sales csv download service * Define non_question_fields per year * Tidy up missing fields and tests * Fix request tests * Refactor * Add missing param * CLDC-3348 Update sales CSV for support (#2407) * Update sales csv for support * CLDC-3352 Update sales CSV address order (#2410) * Update sales support csv address ordering * Refactor * CLDC-3367 Rename sales support CSV fields (#2413) * Rename sales support CSV fields * Update sales CSV user fields order (#2416) * CLDC-2586 Rename scheme sensitive (#2405) * Rename scheme sensitive in lettings csv * Rename scheme sensitive in schemes csv * CLDC-3347 Show soft validations in support CSVs only (#2406) * Show soft validations in support csvs only * CLDC-3352 Update lettings CSV address order (#2409) * Update lettings support csv address ordering * Refactor * CLDC-3415/3421/3422 Add lettings CSV updates (#2415) * Add first_time_property_let_as_social_housing to coordinators csv * Update lettings CSV user fields order * Remove new_old from lettings CSV * Remove duplicate rent value check from CSV (#2423) * Refactor CSV service (#2425) * Extract and move lettings methods * Extract and more sales methods
7 months ago
describe "#ordered_questions_for_year" do
context "with lettings" do
let(:result) { described_class.instance.ordered_questions_for_year(2936, "lettings") }
let(:now) { Time.zone.local(2936, 5, 1) }
it "returns an array of questions" do
section = build(:section, :with_questions, question_ids: %w[1 2 3])
lettings_form = FormFactory.new(year: 2936, type: "lettings")
.with_sections([section])
.build
described_class.instance.use_fake_forms!({ "current_lettings" => lettings_form })
expect(result).to(satisfy { |result| result.all? { |element| element.is_a?(Form::Question) } })
end
CLDC-3438 Update log csv download flow (#2403) * Filter out empty options from selected filters * Redirect to year filter if it is not selected * Add remaining filter questions * Display lettings filters CYA * Add cancel, conditionally display send email * Refactor * Add removed tests * Update method name * Add sales logs filters * Update tests * Set label size on filter questions * Refactor * Deduplicate filter views * Rename methods * Authenticate pages * Update filtering per organisation * Update routing from CYA * lint * Refactor check_your_answers_filters_list * Redirect if year is not given for sales csv * Update formatted organisations methods * Update missing and wrong copy * Update cancel and back buttons * CLDC-3442 Download logs csv per year (#2404) * Specify year in lettings csv download service * Specify year in sales csv download service * Define non_question_fields per year * Tidy up missing fields and tests * Fix request tests * Refactor * Add missing param * CLDC-3348 Update sales CSV for support (#2407) * Update sales csv for support * CLDC-3352 Update sales CSV address order (#2410) * Update sales support csv address ordering * Refactor * CLDC-3367 Rename sales support CSV fields (#2413) * Rename sales support CSV fields * Update sales CSV user fields order (#2416) * CLDC-2586 Rename scheme sensitive (#2405) * Rename scheme sensitive in lettings csv * Rename scheme sensitive in schemes csv * CLDC-3347 Show soft validations in support CSVs only (#2406) * Show soft validations in support csvs only * CLDC-3352 Update lettings CSV address order (#2409) * Update lettings support csv address ordering * Refactor * CLDC-3415/3421/3422 Add lettings CSV updates (#2415) * Add first_time_property_let_as_social_housing to coordinators csv * Update lettings CSV user fields order * Remove new_old from lettings CSV * Remove duplicate rent value check from CSV (#2423) * Refactor CSV service (#2425) * Extract and move lettings methods * Extract and more sales methods
7 months ago
it "does not return multiple questions with the same id" do
first_section = build(:section, :with_questions, question_ids: %w[1 2 3])
second_section = build(:section, :with_questions, question_ids: %w[2 3 4 5])
lettings_form = FormFactory.new(year: 2936, type: "lettings")
.with_sections([first_section, second_section])
.build
described_class.instance.use_fake_forms!({ "current_lettings" => lettings_form })
expect(result.map(&:id)).to eq %w[1 2 3 4 5]
end
CLDC-3438 Update log csv download flow (#2403) * Filter out empty options from selected filters * Redirect to year filter if it is not selected * Add remaining filter questions * Display lettings filters CYA * Add cancel, conditionally display send email * Refactor * Add removed tests * Update method name * Add sales logs filters * Update tests * Set label size on filter questions * Refactor * Deduplicate filter views * Rename methods * Authenticate pages * Update filtering per organisation * Update routing from CYA * lint * Refactor check_your_answers_filters_list * Redirect if year is not given for sales csv * Update formatted organisations methods * Update missing and wrong copy * Update cancel and back buttons * CLDC-3442 Download logs csv per year (#2404) * Specify year in lettings csv download service * Specify year in sales csv download service * Define non_question_fields per year * Tidy up missing fields and tests * Fix request tests * Refactor * Add missing param * CLDC-3348 Update sales CSV for support (#2407) * Update sales csv for support * CLDC-3352 Update sales CSV address order (#2410) * Update sales support csv address ordering * Refactor * CLDC-3367 Rename sales support CSV fields (#2413) * Rename sales support CSV fields * Update sales CSV user fields order (#2416) * CLDC-2586 Rename scheme sensitive (#2405) * Rename scheme sensitive in lettings csv * Rename scheme sensitive in schemes csv * CLDC-3347 Show soft validations in support CSVs only (#2406) * Show soft validations in support csvs only * CLDC-3352 Update lettings CSV address order (#2409) * Update lettings support csv address ordering * Refactor * CLDC-3415/3421/3422 Add lettings CSV updates (#2415) * Add first_time_property_let_as_social_housing to coordinators csv * Update lettings CSV user fields order * Remove new_old from lettings CSV * Remove duplicate rent value check from CSV (#2423) * Refactor CSV service (#2425) * Extract and move lettings methods * Extract and more sales methods
7 months ago
it "returns the questions in the same order as the form" do
first_section = build(:section, :with_questions, question_ids: %w[1 2 3])
second_section = build(:section, :with_questions, question_ids: %w[4 5 6])
lettings_form = FormFactory.new(year: 2936, type: "lettings")
.with_sections([first_section, second_section])
.build
described_class.instance.use_fake_forms!({ "current_lettings" => lettings_form })
expect(result.map(&:id)).to eq %w[1 2 3 4 5 6]
end
end
CLDC-3438 Update log csv download flow (#2403) * Filter out empty options from selected filters * Redirect to year filter if it is not selected * Add remaining filter questions * Display lettings filters CYA * Add cancel, conditionally display send email * Refactor * Add removed tests * Update method name * Add sales logs filters * Update tests * Set label size on filter questions * Refactor * Deduplicate filter views * Rename methods * Authenticate pages * Update filtering per organisation * Update routing from CYA * lint * Refactor check_your_answers_filters_list * Redirect if year is not given for sales csv * Update formatted organisations methods * Update missing and wrong copy * Update cancel and back buttons * CLDC-3442 Download logs csv per year (#2404) * Specify year in lettings csv download service * Specify year in sales csv download service * Define non_question_fields per year * Tidy up missing fields and tests * Fix request tests * Refactor * Add missing param * CLDC-3348 Update sales CSV for support (#2407) * Update sales csv for support * CLDC-3352 Update sales CSV address order (#2410) * Update sales support csv address ordering * Refactor * CLDC-3367 Rename sales support CSV fields (#2413) * Rename sales support CSV fields * Update sales CSV user fields order (#2416) * CLDC-2586 Rename scheme sensitive (#2405) * Rename scheme sensitive in lettings csv * Rename scheme sensitive in schemes csv * CLDC-3347 Show soft validations in support CSVs only (#2406) * Show soft validations in support csvs only * CLDC-3352 Update lettings CSV address order (#2409) * Update lettings support csv address ordering * Refactor * CLDC-3415/3421/3422 Add lettings CSV updates (#2415) * Add first_time_property_let_as_social_housing to coordinators csv * Update lettings CSV user fields order * Remove new_old from lettings CSV * Remove duplicate rent value check from CSV (#2423) * Refactor CSV service (#2425) * Extract and move lettings methods * Extract and more sales methods
7 months ago
context "with sales" do
let(:result) { described_class.instance.ordered_questions_for_year(2936, "sales") }
let(:now) { Time.zone.local(2936, 5, 1) }
it "returns an array of questions" do
section = build(:section, :with_questions, question_ids: %w[1 2 3])
sales_form = FormFactory.new(year: 2936, type: "sales")
.with_sections([section])
.build
described_class.instance.use_fake_forms!({ "current_sales" => sales_form })
expect(result).to(satisfy { |result| result.all? { |element| element.is_a?(Form::Question) } })
end
CLDC-3438 Update log csv download flow (#2403) * Filter out empty options from selected filters * Redirect to year filter if it is not selected * Add remaining filter questions * Display lettings filters CYA * Add cancel, conditionally display send email * Refactor * Add removed tests * Update method name * Add sales logs filters * Update tests * Set label size on filter questions * Refactor * Deduplicate filter views * Rename methods * Authenticate pages * Update filtering per organisation * Update routing from CYA * lint * Refactor check_your_answers_filters_list * Redirect if year is not given for sales csv * Update formatted organisations methods * Update missing and wrong copy * Update cancel and back buttons * CLDC-3442 Download logs csv per year (#2404) * Specify year in lettings csv download service * Specify year in sales csv download service * Define non_question_fields per year * Tidy up missing fields and tests * Fix request tests * Refactor * Add missing param * CLDC-3348 Update sales CSV for support (#2407) * Update sales csv for support * CLDC-3352 Update sales CSV address order (#2410) * Update sales support csv address ordering * Refactor * CLDC-3367 Rename sales support CSV fields (#2413) * Rename sales support CSV fields * Update sales CSV user fields order (#2416) * CLDC-2586 Rename scheme sensitive (#2405) * Rename scheme sensitive in lettings csv * Rename scheme sensitive in schemes csv * CLDC-3347 Show soft validations in support CSVs only (#2406) * Show soft validations in support csvs only * CLDC-3352 Update lettings CSV address order (#2409) * Update lettings support csv address ordering * Refactor * CLDC-3415/3421/3422 Add lettings CSV updates (#2415) * Add first_time_property_let_as_social_housing to coordinators csv * Update lettings CSV user fields order * Remove new_old from lettings CSV * Remove duplicate rent value check from CSV (#2423) * Refactor CSV service (#2425) * Extract and move lettings methods * Extract and more sales methods
7 months ago
it "does not return multiple questions with the same id" do
first_section = build(:section, :with_questions, question_ids: %w[1 2 3])
second_section = build(:section, :with_questions, question_ids: %w[2 3 4 5])
sales_form = FormFactory.new(year: 2936, type: "sales")
.with_sections([first_section, second_section])
.build
described_class.instance.use_fake_forms!({ "current_sales" => sales_form })
expect(result.map(&:id)).to eq %w[1 2 3 4 5]
end
CLDC-3438 Update log csv download flow (#2403) * Filter out empty options from selected filters * Redirect to year filter if it is not selected * Add remaining filter questions * Display lettings filters CYA * Add cancel, conditionally display send email * Refactor * Add removed tests * Update method name * Add sales logs filters * Update tests * Set label size on filter questions * Refactor * Deduplicate filter views * Rename methods * Authenticate pages * Update filtering per organisation * Update routing from CYA * lint * Refactor check_your_answers_filters_list * Redirect if year is not given for sales csv * Update formatted organisations methods * Update missing and wrong copy * Update cancel and back buttons * CLDC-3442 Download logs csv per year (#2404) * Specify year in lettings csv download service * Specify year in sales csv download service * Define non_question_fields per year * Tidy up missing fields and tests * Fix request tests * Refactor * Add missing param * CLDC-3348 Update sales CSV for support (#2407) * Update sales csv for support * CLDC-3352 Update sales CSV address order (#2410) * Update sales support csv address ordering * Refactor * CLDC-3367 Rename sales support CSV fields (#2413) * Rename sales support CSV fields * Update sales CSV user fields order (#2416) * CLDC-2586 Rename scheme sensitive (#2405) * Rename scheme sensitive in lettings csv * Rename scheme sensitive in schemes csv * CLDC-3347 Show soft validations in support CSVs only (#2406) * Show soft validations in support csvs only * CLDC-3352 Update lettings CSV address order (#2409) * Update lettings support csv address ordering * Refactor * CLDC-3415/3421/3422 Add lettings CSV updates (#2415) * Add first_time_property_let_as_social_housing to coordinators csv * Update lettings CSV user fields order * Remove new_old from lettings CSV * Remove duplicate rent value check from CSV (#2423) * Refactor CSV service (#2425) * Extract and move lettings methods * Extract and more sales methods
7 months ago
it "returns the questions in the same order as the form" do
first_section = build(:section, :with_questions, question_ids: %w[1 2 3])
second_section = build(:section, :with_questions, question_ids: %w[4 5 6])
sales_form = FormFactory.new(year: 2936, type: "sales")
.with_sections([first_section, second_section])
.build
described_class.instance.use_fake_forms!({ "current_sales" => sales_form })
expect(result.map(&:id)).to eq %w[1 2 3 4 5 6]
end
end
end
# rubocop:enable RSpec/PredicateMatcher
end