Browse Source

CLDC-4168: Update tests

pull/3195/head
samyou-softwire 2 months ago
parent
commit
2ff110b6e6
  1. 122
      spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
  2. 39
      spec/models/form/sales/subsections/outright_sale_spec.rb
  3. 101
      spec/models/form/sales/subsections/shared_ownership_initial_purchase_spec.rb
  4. 120
      spec/services/bulk_upload/sales/year2026/row_parser_spec.rb

122
spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb

@ -1,17 +1,61 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model do RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model do
include CollectionTimeHelper
subject(:discounted_ownership_scheme) { described_class.new(subsection_id, subsection_definition, section) } subject(:discounted_ownership_scheme) { described_class.new(subsection_id, subsection_definition, section) }
let(:subsection_id) { nil } let(:subsection_id) { nil }
let(:subsection_definition) { nil } let(:subsection_definition) { nil }
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2025_or_later?: false) } let(:start_year_2025_or_later?) { true }
let(:start_year_2026_or_later?) { true }
let(:form) { instance_double(Form, start_date: current_collection_start_date, start_year_2025_or_later?: start_year_2025_or_later?, start_year_2026_or_later?: start_year_2026_or_later?) }
let(:section) { instance_double(Form::Sales::Sections::SaleInformation, form:) } let(:section) { instance_double(Form::Sales::Sections::SaleInformation, form:) }
it "has correct section" do it "has correct section" do
expect(discounted_ownership_scheme.section).to eq(section) expect(discounted_ownership_scheme.section).to eq(section)
end end
it "has the correct id" do
expect(discounted_ownership_scheme.id).to eq("discounted_ownership_scheme")
end
it "has the correct copy key" do
expect(discounted_ownership_scheme.copy_key).to eq("sale_information")
end
it "has the correct label" do
expect(discounted_ownership_scheme.label).to eq("Discounted ownership scheme")
end
it "has the correct depends_on" do
expect(discounted_ownership_scheme.depends_on).to eq([
{
"ownershipsch" => 2, "setup_completed?" => true
},
])
end
context "when it is a discounted ownership scheme" do
let(:log) { FactoryBot.build(:sales_log, ownershipsch: 2) }
it "is displayed in tasklist" do
expect(discounted_ownership_scheme.displayed_in_tasklist?(log)).to be(true)
end
end
context "when it is not a discounted ownership scheme" do
let(:log) { FactoryBot.build(:sales_log, ownershipsch: 1) }
it "is displayed in tasklist" do
expect(discounted_ownership_scheme.displayed_in_tasklist?(log)).to be(false)
end
end
context "when 2024", metadata: { year: 24 } do
let(:start_year_2025_or_later?) { false }
let(:start_year_2026_or_later?) { false }
it "has correct pages" do it "has correct pages" do
expect(discounted_ownership_scheme.pages.map(&:id)).to eq( expect(discounted_ownership_scheme.pages.map(&:id)).to eq(
%w[ %w[
@ -51,46 +95,51 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
], ],
) )
end end
it "has the correct id" do
expect(discounted_ownership_scheme.id).to eq("discounted_ownership_scheme")
end end
it "has the correct copy key" do context "when 2025", metadata: { year: 25 } do
expect(discounted_ownership_scheme.copy_key).to eq("sale_information") let(:start_year_2026_or_later?) { false }
end
it "has the correct label" do
expect(discounted_ownership_scheme.label).to eq("Discounted ownership scheme")
end
it "has the correct depends_on" do it "has correct pages" do
expect(discounted_ownership_scheme.depends_on).to eq([ expect(discounted_ownership_scheme.pages.map(&:id)).to eq(
{ %w[
"ownershipsch" => 2, "setup_completed?" => true living_before_purchase_discounted_ownership_joint_purchase
}, living_before_purchase_discounted_ownership
]) purchase_price
end discount
extra_borrowing_price_value_check
context "when it is a discounted ownership scheme" do percentage_discount_value_check
let(:log) { FactoryBot.build(:sales_log, ownershipsch: 2) } grant
grant_value_check
it "is displayed in tasklist" do purchase_price_discounted_ownership
expect(discounted_ownership_scheme.displayed_in_tasklist?(log)).to be(true) discounted_sale_grant_value_check
end about_price_discounted_ownership_value_check
end discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount
mortgage_used_discounted_ownership
context "when it is not a discounted ownership scheme" do discounted_ownership_mortgage_used_mortgage_value_check
let(:log) { FactoryBot.build(:sales_log, ownershipsch: 1) } discounted_sale_mortgage_used_value_check
mortgage_amount_discounted_ownership
it "is displayed in tasklist" do discounted_ownership_mortgage_amount_mortgage_value_check
expect(discounted_ownership_scheme.displayed_in_tasklist?(log)).to be(false) discounted_sale_mortgage_value_check
extra_borrowing_mortgage_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_mortgage
mortgage_length_discounted_ownership
extra_borrowing_discounted_ownership
extra_borrowing_value_check
deposit_discounted_ownership
extra_borrowing_deposit_value_check
discounted_ownership_deposit_joint_purchase_value_check
discounted_ownership_deposit_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_deposit
discounted_sale_deposit_value_check
leasehold_charges_discounted_ownership
monthly_charges_discounted_ownership_value_check
],
)
end end
end end
context "with form on or after 2025" do context "when 2026", metadata: { year: 26 } do
let(:form) { instance_double(Form, start_date: Time.zone.local(2025, 4, 1), start_year_2025_or_later?: true) }
it "has correct pages" do it "has correct pages" do
expect(discounted_ownership_scheme.pages.map(&:id)).to eq( expect(discounted_ownership_scheme.pages.map(&:id)).to eq(
%w[ %w[
@ -114,7 +163,8 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
discounted_sale_mortgage_value_check discounted_sale_mortgage_value_check
extra_borrowing_mortgage_value_check extra_borrowing_mortgage_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_mortgage discounted_ownership_deposit_and_mortgage_value_check_after_mortgage
mortgage_length_discounted_ownership mortgage_length_discounted_ownership_not_interviewed
mortgage_length_discounted_ownership_interviewed
extra_borrowing_discounted_ownership extra_borrowing_discounted_ownership
extra_borrowing_value_check extra_borrowing_value_check
deposit_discounted_ownership deposit_discounted_ownership

39
spec/models/form/sales/subsections/outright_sale_spec.rb

@ -1,12 +1,18 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
include CollectionTimeHelper
subject(:outright_sale) { described_class.new(subsection_id, subsection_definition, section) } subject(:outright_sale) { described_class.new(subsection_id, subsection_definition, section) }
let(:subsection_id) { nil } let(:subsection_id) { nil }
let(:subsection_definition) { nil } let(:subsection_definition) { nil }
let(:start_year_2024_or_later?) { true }
let(:start_year_2025_or_later?) { true }
let(:start_year_2026_or_later?) { true }
let(:start_date) { current_collection_start_date }
let(:section) { instance_double(Form::Sales::Sections::SaleInformation) } let(:section) { instance_double(Form::Sales::Sections::SaleInformation) }
let(:form) { instance_double(Form) } let(:form) { instance_double(Form, start_date:, start_year_2024_or_later?: start_year_2024_or_later?, start_year_2025_or_later?: start_year_2025_or_later?, start_year_2026_or_later?: start_year_2026_or_later?) }
before do before do
allow(section).to receive(:form).and_return(form) allow(section).to receive(:form).and_return(form)
@ -19,13 +25,13 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
describe "pages" do describe "pages" do
let(:section) { instance_double(described_class, form: instance_double(Form)) } let(:section) { instance_double(described_class, form: instance_double(Form)) }
context "when 2022" do context "when 2024", metadata: { year: 24 } do
before do let(:start_year_2025_or_later?) { false }
allow(form).to receive_messages(start_date: Time.zone.local(2022, 2, 8), start_year_2024_or_later?: false) let(:start_year_2026_or_later?) { false }
end let(:start_date) { collection_start_date_for_year(2024) }
it "has correct pages" do it "has correct pages" do
expect(outright_sale.pages.compact.map(&:id)).to eq( expect(outright_sale.pages.map(&:id)).to eq(
%w[ %w[
purchase_price_outright_sale purchase_price_outright_sale
about_price_outright_sale_value_check about_price_outright_sale_value_check
@ -33,23 +39,21 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
outright_sale_mortgage_used_mortgage_value_check outright_sale_mortgage_used_mortgage_value_check
mortgage_amount_outright_sale mortgage_amount_outright_sale
outright_sale_mortgage_amount_mortgage_value_check outright_sale_mortgage_amount_mortgage_value_check
mortgage_lender_outright_sale
mortgage_lender_other_outright_sale
mortgage_length_outright_sale mortgage_length_outright_sale
extra_borrowing_outright_sale extra_borrowing_outright_sale
deposit_outright_sale deposit_outright_sale
outright_sale_deposit_joint_purchase_value_check outright_sale_deposit_joint_purchase_value_check
outright_sale_deposit_value_check outright_sale_deposit_value_check
leasehold_charges_outright_sale
monthly_charges_outright_sale_value_check monthly_charges_outright_sale_value_check
], ],
) )
end end
end end
context "when 2023" do context "when 2025", metadata: { year: 25 } do
before do let(:start_year_2026_or_later?) { false }
allow(form).to receive_messages(start_date: Time.zone.local(2023, 2, 8), start_year_2024_or_later?: false) let(:start_date) { collection_start_date_for_year(2025) }
end
it "has correct pages" do it "has correct pages" do
expect(outright_sale.pages.map(&:id)).to eq( expect(outright_sale.pages.map(&:id)).to eq(
@ -60,8 +64,6 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
outright_sale_mortgage_used_mortgage_value_check outright_sale_mortgage_used_mortgage_value_check
mortgage_amount_outright_sale mortgage_amount_outright_sale
outright_sale_mortgage_amount_mortgage_value_check outright_sale_mortgage_amount_mortgage_value_check
mortgage_lender_outright_sale
mortgage_lender_other_outright_sale
mortgage_length_outright_sale mortgage_length_outright_sale
extra_borrowing_outright_sale extra_borrowing_outright_sale
deposit_outright_sale deposit_outright_sale
@ -74,10 +76,8 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
end end
end end
context "when 2024" do context "when 2026", metadata: { year: 26 } do
before do let(:start_date) { collection_start_date_for_year(2026) }
allow(form).to receive_messages(start_date: Time.zone.local(2024, 2, 8), start_year_2024_or_later?: true)
end
it "has correct pages" do it "has correct pages" do
expect(outright_sale.pages.map(&:id)).to eq( expect(outright_sale.pages.map(&:id)).to eq(
@ -88,7 +88,8 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
outright_sale_mortgage_used_mortgage_value_check outright_sale_mortgage_used_mortgage_value_check
mortgage_amount_outright_sale mortgage_amount_outright_sale
outright_sale_mortgage_amount_mortgage_value_check outright_sale_mortgage_amount_mortgage_value_check
mortgage_length_outright_sale mortgage_length_outright_sale_not_interviewed
mortgage_length_outright_sale_interviewed
extra_borrowing_outright_sale extra_borrowing_outright_sale
deposit_outright_sale deposit_outright_sale
outright_sale_deposit_joint_purchase_value_check outright_sale_deposit_joint_purchase_value_check

101
spec/models/form/sales/subsections/shared_ownership_initial_purchase_spec.rb

@ -1,20 +1,75 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Subsections::SharedOwnershipInitialPurchase, type: :model do RSpec.describe Form::Sales::Subsections::SharedOwnershipInitialPurchase, type: :model do
include CollectionTimeHelper
subject(:shared_ownership_initial_purchase) { described_class.new(subsection_id, subsection_definition, section) } subject(:shared_ownership_initial_purchase) { described_class.new(subsection_id, subsection_definition, section) }
let(:subsection_id) { nil } let(:subsection_id) { nil }
let(:subsection_definition) { nil } let(:subsection_definition) { nil }
let(:start_year_2024_or_later?) { true }
let(:start_year_2025_or_later?) { true }
let(:start_year_2026_or_later?) { true }
let(:start_date) { current_collection_start_date }
let(:form) { instance_double(Form, start_date:, start_year_2024_or_later?: start_year_2024_or_later?, start_year_2025_or_later?: start_year_2025_or_later?, start_year_2026_or_later?: start_year_2026_or_later?) }
let(:section) { instance_double(Form::Sales::Sections::SaleInformation) } let(:section) { instance_double(Form::Sales::Sections::SaleInformation) }
before do before do
allow(section).to receive(:form).and_return(instance_double(Form, start_date: Time.zone.local(2025, 4, 1))) allow(section).to receive(:form).and_return(form)
end end
it "has correct section" do it "has correct section" do
expect(shared_ownership_initial_purchase.section).to eq(section) expect(shared_ownership_initial_purchase.section).to eq(section)
end end
context "when 2024", metadata: { year: 24 } do
let(:start_year_2025_or_later?) { false }
let(:start_year_2026_or_later?) { false }
let(:start_date) { collection_start_date_for_year(2024) }
it "has correct pages" do
expect(shared_ownership_initial_purchase.pages.map(&:id)).to eq(
%w[
resale
living_before_purchase_shared_ownership_joint_purchase
living_before_purchase_shared_ownership
handover_date
handover_date_check
buyer_previous_joint_purchase
buyer_previous_not_joint_purchase
previous_bedrooms
previous_property_type
shared_ownership_previous_tenure
value_shared_ownership
about_price_shared_ownership_value_check
initial_equity
shared_ownership_equity_value_check
mortgage_used_shared_ownership
mortgage_used_mortgage_value_check
mortgage_amount_shared_ownership
shared_ownership_mortgage_amount_value_check
mortgage_amount_mortgage_value_check
mortgage_length_shared_ownership
deposit_shared_ownership
deposit_shared_ownership_optional
deposit_joint_purchase_value_check
deposit_value_check
deposit_discount
deposit_discount_optional
shared_ownership_deposit_value_check
monthly_rent
service_charge
monthly_charges_shared_ownership_value_check
estate_management_fee
],
)
end
end
context "when 2025", metadata: { year: 25 } do
let(:start_year_2026_or_later?) { false }
let(:start_date) { collection_start_date_for_year(2025) }
it "has correct pages" do it "has correct pages" do
expect(shared_ownership_initial_purchase.pages.map(&:id)).to eq( expect(shared_ownership_initial_purchase.pages.map(&:id)).to eq(
%w[ %w[
@ -52,6 +107,50 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipInitialPurchase, type: :
], ],
) )
end end
end
context "when 2026", metadata: { year: 26 } do
let(:start_date) { collection_start_date_for_year(2026) }
it "has correct pages" do
expect(shared_ownership_initial_purchase.pages.map(&:id)).to eq(
%w[
resale
living_before_purchase_shared_ownership_joint_purchase
living_before_purchase_shared_ownership
handover_date
handover_date_check
buyer_previous_joint_purchase
buyer_previous_not_joint_purchase
previous_bedrooms
previous_property_type
shared_ownership_previous_tenure
value_shared_ownership
about_price_shared_ownership_value_check
initial_equity
shared_ownership_equity_value_check
mortgage_used_shared_ownership
mortgage_used_mortgage_value_check
mortgage_amount_shared_ownership
shared_ownership_mortgage_amount_value_check
mortgage_amount_mortgage_value_check
mortgage_length_shared_ownership_not_interviewed
mortgage_length_shared_ownership_interviewed
deposit_shared_ownership
deposit_shared_ownership_optional
deposit_joint_purchase_value_check
deposit_value_check
deposit_discount
deposit_discount_optional
shared_ownership_deposit_value_check
monthly_rent
service_charge
monthly_charges_shared_ownership_value_check
estate_management_fee
],
)
end
end
it "has the correct id" do it "has the correct id" do
expect(shared_ownership_initial_purchase.id).to eq("shared_ownership_initial_purchase") expect(shared_ownership_initial_purchase.id).to eq("shared_ownership_initial_purchase")

120
spec/services/bulk_upload/sales/year2026/row_parser_spec.rb

@ -1445,6 +1445,74 @@ RSpec.describe BulkUpload::Sales::Year2026::RowParser do
expect(parser.log_already_exists?).to be(false) expect(parser.log_already_exists?).to be(false)
end end
end end
describe "field_90" do
context "when field_90 is a number" do
let(:field_90_number_attributes) { valid_attributes.merge({ field_90: 20 }) }
context "and buyer was interviewed" do
let(:attributes) { field_90_number_attributes.merge({ field_14: 2 }) }
it "does not add an error" do
parser.valid?
expect(parser.errors.where(:field_90)).not_to be_present
end
end
context "and buyer was not interviewed" do
let(:attributes) { field_90_number_attributes.merge({ field_14: 1 }) }
it "does not add an error" do
parser.valid?
expect(parser.errors.where(:field_90)).not_to be_present
end
end
end
context "when field_90 is R" do
let(:field_90_number_attributes) { valid_attributes.merge({ field_90: "R" }) }
context "and buyer was interviewed" do
let(:attributes) { field_90_number_attributes.merge({ field_14: 2 }) }
it "does not add an error" do
parser.valid?
expect(parser.errors.where(:field_90)).not_to be_present
end
end
context "and buyer was not interviewed" do
let(:attributes) { field_90_number_attributes.merge({ field_14: 1 }) }
it "adds an error" do
parser.valid?
expect(parser.errors.where(:field_90)).to be_present
end
end
end
context "when field_90 is neither a number nor R" do
let(:field_90_number_attributes) { valid_attributes.merge({ field_90: "something" }) }
context "and buyer was interviewed" do
let(:attributes) { field_90_number_attributes.merge({ field_14: 2 }) }
it "adds an error" do
parser.valid?
expect(parser.errors.where(:field_90)).to be_present
end
end
context "and buyer was not interviewed" do
let(:attributes) { field_90_number_attributes.merge({ field_14: 1 }) }
it "adds an error" do
parser.valid?
expect(parser.errors.where(:field_90)).to be_present
end
end
end
end
end end
describe "#log" do describe "#log" do
@ -1950,6 +2018,58 @@ RSpec.describe BulkUpload::Sales::Year2026::RowParser do
end end
end end
end end
describe "mortlen amd mortgage_length_known" do
context "when field_90 is a number" do
let(:field_90_number_attributes) { valid_attributes.merge({ field_90: 20 }) }
context "and buyer was interviewed" do
let(:attributes) { field_90_number_attributes.merge({ field_14: 2 }) }
it "sets mortlen to the length" do
log = parser.log
expect(log.mortlen).to eq(20)
end
it "sets mortgage_length_known to yes" do
log = parser.log
expect(log.mortgage_length_known).to eq(0)
end
end
context "and buyer was not interviewed" do
let(:attributes) { field_90_number_attributes.merge({ field_14: 1 }) }
it "sets mortlen to the length" do
log = parser.log
expect(log.mortlen).to eq(20)
end
it "sets mortgage_length_known to nil" do
log = parser.log
expect(log.mortgage_length_known).to be_nil
end
end
end
context "when field_90 is R" do
let(:field_90_number_attributes) { valid_attributes.merge({ field_90: "R" }) }
context "and buyer was interviewed" do
let(:attributes) { field_90_number_attributes.merge({ field_14: 2 }) }
it "sets mortlen to nil" do
log = parser.log
expect(log.mortlen).to be_nil
end
it "sets mortgage_length_known to no" do
log = parser.log
expect(log.mortgage_length_known).to eq(1)
end
end
end
end
end end
describe "#owning_organisation_id" do describe "#owning_organisation_id" do

Loading…
Cancel
Save