Browse Source

CLDC-4168: Update tests

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

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

@ -1,57 +1,21 @@
require "rails_helper"
RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model do
include CollectionTimeHelper
subject(:discounted_ownership_scheme) { described_class.new(subsection_id, subsection_definition, section) }
let(:subsection_id) { 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:) }
it "has correct section" do
expect(discounted_ownership_scheme.section).to eq(section)
end
it "has correct pages" do
expect(discounted_ownership_scheme.pages.map(&:id)).to eq(
%w[
living_before_purchase_discounted_ownership_joint_purchase
living_before_purchase_discounted_ownership
purchase_price
discount
extra_borrowing_price_value_check
percentage_discount_value_check
grant
grant_value_check
purchase_price_discounted_ownership
discounted_sale_grant_value_check
about_price_discounted_ownership_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount
mortgage_used_discounted_ownership
discounted_ownership_mortgage_used_mortgage_value_check
discounted_sale_mortgage_used_value_check
mortgage_amount_discounted_ownership
discounted_ownership_mortgage_amount_mortgage_value_check
discounted_sale_mortgage_value_check
extra_borrowing_mortgage_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_mortgage
mortgage_lender_discounted_ownership
mortgage_lender_other_discounted_ownership
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
it "has the correct id" do
expect(discounted_ownership_scheme.id).to eq("discounted_ownership_scheme")
end
@ -88,8 +52,9 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
end
end
context "with form on or after 2025" do
let(:form) { instance_double(Form, start_date: Time.zone.local(2025, 4, 1), start_year_2025_or_later?: true) }
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
expect(discounted_ownership_scheme.pages.map(&:id)).to eq(
@ -114,6 +79,8 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
discounted_sale_mortgage_value_check
extra_borrowing_mortgage_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_mortgage
mortgage_lender_discounted_ownership
mortgage_lender_other_discounted_ownership
mortgage_length_discounted_ownership
extra_borrowing_discounted_ownership
extra_borrowing_value_check
@ -129,4 +96,87 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
)
end
end
context "when 2025", metadata: { year: 25 } do
let(:start_year_2026_or_later?) { false }
it "has correct pages" do
expect(discounted_ownership_scheme.pages.map(&:id)).to eq(
%w[
living_before_purchase_discounted_ownership_joint_purchase
living_before_purchase_discounted_ownership
purchase_price
discount
extra_borrowing_price_value_check
percentage_discount_value_check
grant
grant_value_check
purchase_price_discounted_ownership
discounted_sale_grant_value_check
about_price_discounted_ownership_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount
mortgage_used_discounted_ownership
discounted_ownership_mortgage_used_mortgage_value_check
discounted_sale_mortgage_used_value_check
mortgage_amount_discounted_ownership
discounted_ownership_mortgage_amount_mortgage_value_check
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
context "when 2026", metadata: { year: 26 } do
it "has correct pages" do
expect(discounted_ownership_scheme.pages.map(&:id)).to eq(
%w[
living_before_purchase_discounted_ownership_joint_purchase
living_before_purchase_discounted_ownership
purchase_price
discount
extra_borrowing_price_value_check
percentage_discount_value_check
grant
grant_value_check
purchase_price_discounted_ownership
discounted_sale_grant_value_check
about_price_discounted_ownership_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount
mortgage_used_discounted_ownership
discounted_ownership_mortgage_used_mortgage_value_check
discounted_sale_mortgage_used_value_check
mortgage_amount_discounted_ownership
discounted_ownership_mortgage_amount_mortgage_value_check
discounted_sale_mortgage_value_check
extra_borrowing_mortgage_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_mortgage
mortgage_length_discounted_ownership_not_interviewed
mortgage_length_discounted_ownership_interviewed
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

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

@ -1,12 +1,18 @@
require "rails_helper"
RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
include CollectionTimeHelper
subject(:outright_sale) { described_class.new(subsection_id, subsection_definition, section) }
let(:subsection_id) { 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(: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
allow(section).to receive(:form).and_return(form)
@ -19,13 +25,13 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
describe "pages" do
let(:section) { instance_double(described_class, form: instance_double(Form)) }
context "when 2022" do
before do
allow(form).to receive_messages(start_date: Time.zone.local(2022, 2, 8), start_year_2024_or_later?: false)
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(outright_sale.pages.compact.map(&:id)).to eq(
expect(outright_sale.pages.map(&:id)).to eq(
%w[
purchase_price_outright_sale
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
mortgage_amount_outright_sale
outright_sale_mortgage_amount_mortgage_value_check
mortgage_lender_outright_sale
mortgage_lender_other_outright_sale
mortgage_length_outright_sale
extra_borrowing_outright_sale
deposit_outright_sale
outright_sale_deposit_joint_purchase_value_check
outright_sale_deposit_value_check
leasehold_charges_outright_sale
monthly_charges_outright_sale_value_check
],
)
end
end
context "when 2023" do
before do
allow(form).to receive_messages(start_date: Time.zone.local(2023, 2, 8), start_year_2024_or_later?: false)
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
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
mortgage_amount_outright_sale
outright_sale_mortgage_amount_mortgage_value_check
mortgage_lender_outright_sale
mortgage_lender_other_outright_sale
mortgage_length_outright_sale
extra_borrowing_outright_sale
deposit_outright_sale
@ -74,10 +76,8 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
end
end
context "when 2024" do
before do
allow(form).to receive_messages(start_date: Time.zone.local(2024, 2, 8), start_year_2024_or_later?: true)
end
context "when 2026", metadata: { year: 26 } do
let(:start_date) { collection_start_date_for_year(2026) }
it "has correct pages" do
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
mortgage_amount_outright_sale
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
deposit_outright_sale
outright_sale_deposit_joint_purchase_value_check

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

@ -1,56 +1,155 @@
require "rails_helper"
RSpec.describe Form::Sales::Subsections::SharedOwnershipInitialPurchase, type: :model do
include CollectionTimeHelper
subject(:shared_ownership_initial_purchase) { described_class.new(subsection_id, subsection_definition, section) }
let(:subsection_id) { 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) }
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
it "has correct section" do
expect(shared_ownership_initial_purchase.section).to eq(section)
end
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
],
)
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
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 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

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)
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
describe "#log" do
@ -1950,6 +2018,58 @@ RSpec.describe BulkUpload::Sales::Year2026::RowParser do
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
describe "#owning_organisation_id" do

Loading…
Cancel
Save