85 changed files with 1726 additions and 525 deletions
@ -1,15 +1,22 @@ |
|||||||
class Form::Sales::Pages::AboutDepositWithDiscount < ::Form::Page |
class Form::Sales::Pages::AboutDepositWithDiscount < ::Form::Page |
||||||
def initialize(id, hsh, subsection) |
def initialize(id, hsh, subsection, optional:) |
||||||
super |
super(id, hsh, subsection) |
||||||
@id = "about_deposit_with_discount" |
|
||||||
@header = "About the deposit" |
@header = "About the deposit" |
||||||
@depends_on = [{ "is_type_discount?" => true }] |
@optional = optional |
||||||
end |
end |
||||||
|
|
||||||
def questions |
def questions |
||||||
@questions ||= [ |
@questions ||= [ |
||||||
Form::Sales::Questions::DepositAmount.new(nil, nil, self, ownershipsch: 1), |
Form::Sales::Questions::DepositAmount.new(nil, nil, self, ownershipsch: 1, optional: @optional), |
||||||
Form::Sales::Questions::DepositDiscount.new(nil, nil, self), |
Form::Sales::Questions::DepositDiscount.new(nil, nil, self), |
||||||
] |
] |
||||||
end |
end |
||||||
|
|
||||||
|
def depends_on |
||||||
|
if form.start_year_after_2024? |
||||||
|
[{ "is_type_discount?" => true, "stairowned_100?" => @optional }] |
||||||
|
else |
||||||
|
[{ "is_type_discount?" => true }] |
||||||
|
end |
||||||
|
end |
||||||
end |
end |
||||||
|
@ -1,16 +1,26 @@ |
|||||||
class Form::Sales::Pages::AboutDepositWithoutDiscount < ::Form::Page |
class Form::Sales::Pages::AboutDepositWithoutDiscount < ::Form::Page |
||||||
def initialize(id, hsh, subsection, ownershipsch:) |
def initialize(id, hsh, subsection, ownershipsch:, optional:) |
||||||
super(id, hsh, subsection) |
super(id, hsh, subsection) |
||||||
@header = "About the deposit" |
@header = "About the deposit" |
||||||
@depends_on = [{ "is_type_discount?" => false, "ownershipsch" => 1 }, |
|
||||||
{ "ownershipsch" => 2 }, |
|
||||||
{ "ownershipsch" => 3, "mortgageused" => 1 }] |
|
||||||
@ownershipsch = ownershipsch |
@ownershipsch = ownershipsch |
||||||
|
@optional = optional |
||||||
end |
end |
||||||
|
|
||||||
def questions |
def questions |
||||||
@questions ||= [ |
@questions ||= [ |
||||||
Form::Sales::Questions::DepositAmount.new(nil, nil, self, ownershipsch: @ownershipsch), |
Form::Sales::Questions::DepositAmount.new(nil, nil, self, ownershipsch: @ownershipsch, optional: @optional), |
||||||
] |
] |
||||||
end |
end |
||||||
|
|
||||||
|
def depends_on |
||||||
|
if form.start_year_after_2024? |
||||||
|
[{ "is_type_discount?" => false, "ownershipsch" => 1, "stairowned_100?" => @optional }, |
||||||
|
{ "ownershipsch" => 2 }, |
||||||
|
{ "ownershipsch" => 3, "mortgageused" => 1 }] |
||||||
|
else |
||||||
|
[{ "is_type_discount?" => false, "ownershipsch" => 1 }, |
||||||
|
{ "ownershipsch" => 2 }, |
||||||
|
{ "ownershipsch" => 3, "mortgageused" => 1 }] |
||||||
|
end |
||||||
|
end |
||||||
end |
end |
||||||
|
@ -0,0 +1 @@ |
|||||||
|
<p class="govuk-body">Make sure the buyer has seen or been given access to <%= govuk_link_to "the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice", privacy_notice_path, target: :_blank %> before completing this log. This is a legal requirement under data protection legislation.</p> |
@ -0,0 +1 @@ |
|||||||
|
<p class="govuk-body">Make sure the lead tenant has seen or been given access to <%= govuk_link_to "the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice", privacy_notice_path, target: :_blank %> before completing this log. This is a legal requirement under data protection legislation.</p> |
@ -0,0 +1,5 @@ |
|||||||
|
class AddAccessibleRegisterToLettingsLogs < ActiveRecord::Migration[7.0] |
||||||
|
def change |
||||||
|
add_column :lettings_logs, :accessible_register, :integer |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,12 @@ |
|||||||
|
desc "Clear earnings for lettings logs that fail validation" |
||||||
|
task clear_invalidated_earnings: :environment do |
||||||
|
LettingsLog.filter_by_year(2023).find_each do |lettings_log| |
||||||
|
lettings_log.validate_net_income(lettings_log) |
||||||
|
if lettings_log.errors[:earnings].present? |
||||||
|
Rails.logger.info "Clearing earnings for lettings log #{lettings_log.id}, owning_organisation_id: #{lettings_log.owning_organisation_id}, managing_organisation_id: #{lettings_log.managing_organisation_id}, startdate: #{lettings_log.startdate.to_date}, tenancy reference: #{lettings_log.tenancycode}, property reference: #{lettings_log.propcode}, created_by: #{lettings_log.created_by.email}(#{lettings_log.created_by_id})" |
||||||
|
lettings_log.earnings = nil |
||||||
|
lettings_log.incfreq = nil |
||||||
|
lettings_log.save!(validate: false) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Binary file not shown.
|
|
|
|
|
|
|
|
|
|
|
|
@ -0,0 +1,111 @@ |
|||||||
|
require "rails_helper" |
||||||
|
require "rake" |
||||||
|
|
||||||
|
RSpec.describe "clear_invalidated_earnings" do |
||||||
|
describe ":clear_invalidated_earnings", type: :task do |
||||||
|
subject(:task) { Rake::Task["clear_invalidated_earnings"] } |
||||||
|
|
||||||
|
before do |
||||||
|
Rake.application.rake_require("tasks/clear_invalidated_earnings") |
||||||
|
Rake::Task.define_task(:environment) |
||||||
|
task.reenable |
||||||
|
FormHandler.instance.use_real_forms! |
||||||
|
end |
||||||
|
|
||||||
|
context "when the rake task is run" do |
||||||
|
context "and there are 2023 logs with invalid earnings" do |
||||||
|
let(:user) { create(:user) } |
||||||
|
let!(:lettings_log) { create(:lettings_log, :completed, created_by: user, voiddate: nil, mrcdate: nil, tenancycode: "123", propcode: "321") } |
||||||
|
|
||||||
|
before do |
||||||
|
lettings_log.startdate = Time.zone.local(2023, 4, 4) |
||||||
|
lettings_log.incfreq = 1 |
||||||
|
lettings_log.earnings = 20 |
||||||
|
lettings_log.hhmemb = 1 |
||||||
|
lettings_log.ecstat1 = 1 |
||||||
|
lettings_log.save!(validate: false) |
||||||
|
end |
||||||
|
|
||||||
|
it "clears earnings" do |
||||||
|
initial_updated_at = lettings_log.updated_at |
||||||
|
expect(lettings_log.incfreq).to eq(1) |
||||||
|
expect(lettings_log.earnings).to eq(20) |
||||||
|
expect(lettings_log.hhmemb).to eq(1) |
||||||
|
expect(lettings_log.ecstat1).to eq(1) |
||||||
|
expect(Rails.logger).to receive(:info).with("Clearing earnings for lettings log #{lettings_log.id}, owning_organisation_id: #{lettings_log.owning_organisation_id}, managing_organisation_id: #{lettings_log.managing_organisation_id}, startdate: 2023-04-04, tenancy reference: 123, property reference: 321, created_by: #{user.email}(#{user.id})") |
||||||
|
|
||||||
|
task.invoke |
||||||
|
lettings_log.reload |
||||||
|
|
||||||
|
expect(lettings_log.incfreq).to eq(nil) |
||||||
|
expect(lettings_log.earnings).to eq(nil) |
||||||
|
expect(lettings_log.hhmemb).to eq(1) |
||||||
|
expect(lettings_log.ecstat1).to eq(1) |
||||||
|
expect(lettings_log.updated_at).not_to eq(initial_updated_at) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "and there are valid 2023 logs" do |
||||||
|
let(:user) { create(:user) } |
||||||
|
let!(:lettings_log) { create(:lettings_log, :completed, created_by: user, voiddate: nil, mrcdate: nil) } |
||||||
|
|
||||||
|
before do |
||||||
|
lettings_log.startdate = Time.zone.local(2023, 4, 4) |
||||||
|
lettings_log.incfreq = 1 |
||||||
|
lettings_log.earnings = 95 |
||||||
|
lettings_log.hhmemb = 1 |
||||||
|
lettings_log.ecstat1 = 1 |
||||||
|
lettings_log.save! |
||||||
|
end |
||||||
|
|
||||||
|
it "does not update the logs" do |
||||||
|
initial_updated_at = lettings_log.updated_at |
||||||
|
expect(lettings_log.incfreq).to eq(1) |
||||||
|
expect(lettings_log.earnings).to eq(95) |
||||||
|
expect(lettings_log.hhmemb).to eq(1) |
||||||
|
expect(lettings_log.ecstat1).to eq(1) |
||||||
|
|
||||||
|
task.invoke |
||||||
|
lettings_log.reload |
||||||
|
|
||||||
|
expect(lettings_log.incfreq).to eq(1) |
||||||
|
expect(lettings_log.earnings).to eq(95) |
||||||
|
expect(lettings_log.hhmemb).to eq(1) |
||||||
|
expect(lettings_log.ecstat1).to eq(1) |
||||||
|
expect(lettings_log.updated_at).to eq(initial_updated_at) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "and there are 2022 logs" do |
||||||
|
let(:user) { create(:user) } |
||||||
|
let!(:lettings_log) { create(:lettings_log, :completed, created_by: user, voiddate: nil, mrcdate: nil) } |
||||||
|
|
||||||
|
before do |
||||||
|
lettings_log.startdate = Time.zone.local(2022, 4, 4) |
||||||
|
lettings_log.incfreq = 1 |
||||||
|
lettings_log.earnings = 20 |
||||||
|
lettings_log.hhmemb = 1 |
||||||
|
lettings_log.ecstat1 = 1 |
||||||
|
lettings_log.save!(validate: false) |
||||||
|
end |
||||||
|
|
||||||
|
it "does not update the logs" do |
||||||
|
initial_updated_at = lettings_log.updated_at |
||||||
|
expect(lettings_log.incfreq).to eq(1) |
||||||
|
expect(lettings_log.earnings).to eq(20) |
||||||
|
expect(lettings_log.hhmemb).to eq(1) |
||||||
|
expect(lettings_log.ecstat1).to eq(1) |
||||||
|
|
||||||
|
task.invoke |
||||||
|
lettings_log.reload |
||||||
|
|
||||||
|
expect(lettings_log.incfreq).to eq(1) |
||||||
|
expect(lettings_log.earnings).to eq(20) |
||||||
|
expect(lettings_log.hhmemb).to eq(1) |
||||||
|
expect(lettings_log.ecstat1).to eq(1) |
||||||
|
expect(lettings_log.updated_at).to eq(initial_updated_at) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,81 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe Form::Lettings::Questions::Declaration, type: :model do |
||||||
|
subject(:question) { described_class.new(question_id, question_definition, page) } |
||||||
|
|
||||||
|
let(:question_id) { nil } |
||||||
|
let(:question_definition) { nil } |
||||||
|
let(:page) { instance_double(Form::Page) } |
||||||
|
let(:subsection) { instance_double(Form::Subsection) } |
||||||
|
let(:form) { instance_double(Form) } |
||||||
|
|
||||||
|
before do |
||||||
|
allow(form).to receive(:start_year_after_2024?) |
||||||
|
allow(page).to receive(:subsection).and_return(subsection) |
||||||
|
allow(subsection).to receive(:form).and_return(form) |
||||||
|
end |
||||||
|
|
||||||
|
it "has correct page" do |
||||||
|
expect(question.page).to eq(page) |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct id" do |
||||||
|
expect(question.id).to eq("declaration") |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct header" do |
||||||
|
expect(question.header).to eq("Declaration") |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct check_answer_label" do |
||||||
|
expect(question.check_answer_label).to eq("Tenant has seen the privacy notice") |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct type" do |
||||||
|
expect(question.type).to eq("checkbox") |
||||||
|
end |
||||||
|
|
||||||
|
it "is not marked as derived" do |
||||||
|
expect(question.derived?).to be false |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct hint" do |
||||||
|
expect(question.hint_text).to be_nil |
||||||
|
end |
||||||
|
|
||||||
|
context "when the form year is before 2024" do |
||||||
|
before do |
||||||
|
allow(form).to receive(:start_year_after_2024?).and_return(false) |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct answer_options" do |
||||||
|
expect(question.answer_options).to eq({ |
||||||
|
"declaration" => { "value" => "The tenant has seen the DLUHC privacy notice" }, |
||||||
|
}) |
||||||
|
end |
||||||
|
|
||||||
|
it "uses the expected top guidance partial" do |
||||||
|
expect(question.top_guidance_partial).to eq("privacy_notice_tenant") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when the form year is >= 2024" do |
||||||
|
before do |
||||||
|
allow(form).to receive(:start_year_after_2024?).and_return(true) |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct answer_options" do |
||||||
|
expect(question.answer_options).to eq({ |
||||||
|
"declaration" => { "value" => "The tenant has seen or been given access to the DLUHC privacy notice" }, |
||||||
|
}) |
||||||
|
end |
||||||
|
|
||||||
|
it "uses the expected top guidance partial" do |
||||||
|
expect(question.top_guidance_partial).to eq("privacy_notice_tenant_2024") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
it "returns correct unanswered_error_message" do |
||||||
|
expect(question.unanswered_error_message).to eq("You must show the DLUHC privacy notice to the tenant before you can submit this log.") |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,74 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe Form::Lettings::Questions::LettingAllocation, type: :model do |
||||||
|
subject(:question) { described_class.new(question_id, question_definition, page) } |
||||||
|
|
||||||
|
let(:question_id) { nil } |
||||||
|
let(:question_definition) { nil } |
||||||
|
let(:page) { instance_double(Form::Page) } |
||||||
|
let(:subsection) { instance_double(Form::Subsection) } |
||||||
|
let(:form) { instance_double(Form) } |
||||||
|
|
||||||
|
before do |
||||||
|
allow(form).to receive(:start_year_after_2024?).and_return(false) |
||||||
|
allow(page).to receive(:subsection).and_return(subsection) |
||||||
|
allow(subsection).to receive(:form).and_return(form) |
||||||
|
end |
||||||
|
|
||||||
|
it "has correct page" do |
||||||
|
expect(question.page).to eq(page) |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct id" do |
||||||
|
expect(question.id).to eq("letting_allocation") |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct header" do |
||||||
|
expect(question.header).to eq("How was this letting allocated?") |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct check_answer_label" do |
||||||
|
expect(question.check_answer_label).to eq("Allocation system") |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct type" do |
||||||
|
expect(question.type).to eq("checkbox") |
||||||
|
end |
||||||
|
|
||||||
|
it "is not marked as derived" do |
||||||
|
expect(question.derived?).to be false |
||||||
|
end |
||||||
|
|
||||||
|
context "with 2023/24 form" do |
||||||
|
it "has the correct answer_options" do |
||||||
|
expect(question.answer_options).to eq({ |
||||||
|
"cbl" => { "value" => "Choice-based lettings (CBL)" }, |
||||||
|
"cap" => { "value" => "Common Allocation Policy (CAP)" }, |
||||||
|
"chr" => { "value" => "Common housing register (CHR)" }, |
||||||
|
"divider" => { "value" => true }, |
||||||
|
"letting_allocation_unknown" => { "value" => "None of these allocation systems" }, |
||||||
|
}) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with 2024/25 form" do |
||||||
|
before do |
||||||
|
allow(form).to receive(:start_year_after_2024?).and_return(true) |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct answer_options" do |
||||||
|
expect(question.answer_options).to eq({ |
||||||
|
"cbl" => { "value" => "Choice-based lettings (CBL)", "hint" => "Where available vacant properties are advertised and applicants are able to bid for specific properties." }, |
||||||
|
"cap" => { "value" => "Common Allocation Policy (CAP)", "hint" => "Where a common system agreed between a group of housing providers is used to determine applicant’s priority for housing." }, |
||||||
|
"chr" => { "value" => "Common housing register (CHR)", "hint" => "Where a single waiting list is used by a group of housing providers to receive and process housing applications. Providers may use different approaches to determine priority." }, |
||||||
|
"accessible_register" => { "value" => "Accessible housing register", "hint" => "Where the ‘access category’ or another descriptor of whether an available vacant property meets a range of access needs is displayed to applicants during the allocations process." }, |
||||||
|
"divider" => { "value" => true }, |
||||||
|
"letting_allocation_unknown" => { "value" => "None of these allocation systems" }, |
||||||
|
}) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct check_answers_card_number" do |
||||||
|
expect(question.check_answers_card_number).to eq(0) |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue