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.

178 lines
5.5 KiB

require "rails_helper"
RSpec.describe FormHandler do
let(:form_handler) { described_class.instance }
before do
Timecop.freeze(Time.utc(2022, 9, 20))
Singleton.__init__(described_class)
end
after do
Timecop.unfreeze
Singleton.__init__(described_class)
end
context "when accessing a form in a different year" do
before do
Timecop.freeze(Time.utc(2021, 8, 3))
Singleton.__init__(described_class)
end
after do
Timecop.unfreeze
Singleton.__init__(described_class) # reload FormHandler Instance to update form definitions between runs
end
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 eq(46)
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 eq(13)
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
end
describe "Get specific form" do
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 eq(13)
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 eq(46)
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 eq(44)
expect(form.name).to eq("2022_2023_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 eq(44)
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
before do
Timecop.freeze(Time.utc(2022, 8, 3))
end
after do
Timecop.unfreeze
end
it "returns the same 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 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 current start date" do
Cldc 1671 deactivate scheme (#980) * feat: wip update scheme summary page * feat: wip deactivate scheme schemes page * feat: wip toggle active page * feat: wip set deactivation_date to a datetime (to be more specific times later_ * Change conditional question controller to accommodate all models * feat: add specific datetimes for deactivation * feat: correct date and add notice * feat: wip error behaviour * feat: wip errors * feat: wip errors refactoring * feat: wip errors more refactoring * refactor: linting * feat: add second error in correct position and wip date range error * feat: remove unneccessary db field * feat: change type values to strings * refactor: tidy up controller logic * refactor: use same structure as locations deactivation * feat: add general partially missing date input error * feat: add tests ("updates existing scheme with valid deactivation date and renders scheme page" still wip) and add new partially nil date behaviour to locations controller * feat: fix tests, add status tag behaviour and remove unnecessary nils * refactor: linting * refactor: erblinting * refactor: remove redundant line * refactor: respond to PR comments 1 * refactor: respond to PR comments 2 * refactor: respond to PR comments 3 * refactor: respond to PR comments 3 (locations side) * fix: remove @locations in location model * fix: remove @locations in location model * fix: update status names * feat: wip validation update * feat: add validation to model layer * feat: further separate scheme deactivation behaviour * test: update tests to new flow * feat: respond to pr comments and add dynamic success text * feat: duplicate behaviour schemes -> locations (+ tests) * refactor: linting * refactor: typo and remove unnecessary line for this PR * refactor: feature toggle simplification * Refactor locations and schemes controller actions - Rename confirmation partials to `deactivate_confirm.html.erb` so that they match the actions in which they belong to - Make all deactivation date comparision UTC time * feat: update deactivation_date validation and add tests * refactor: linting Co-authored-by: Kat <katrina@kosiak.co.uk> Co-authored-by: James Rose <james@jbpr.net>
2 years ago
expect(form_handler.current_collection_start_date).to eq(Time.zone.local(2022, 4, 1))
end
end
context "with the date before 1st of April" do
before do
Timecop.freeze(Time.utc(2022, 2, 3))
end
after do
Timecop.unfreeze
end
it "returns the previous year as the current start year" do
expect(form_handler.current_collection_start_year).to eq(2021)
end
it "returns the correct current lettings form name" do
expect(form_handler.form_name_from_start_year(2021, "lettings")).to eq("current_lettings")
end
it "returns the correct previous lettings form name" do
expect(form_handler.form_name_from_start_year(2020, "lettings")).to eq("previous_lettings")
end
it "returns the correct next lettings form name" do
expect(form_handler.form_name_from_start_year(2022, "lettings")).to eq("next_lettings")
end
it "returns the correct current sales form name" do
expect(form_handler.form_name_from_start_year(2021, "sales")).to eq("current_sales")
end
it "returns the correct previous sales form name" do
expect(form_handler.form_name_from_start_year(2020, "sales")).to eq("previous_sales")
end
it "returns the correct next sales form name" do
expect(form_handler.form_name_from_start_year(2022, "sales")).to eq("next_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
end