Compare commits

...

4 Commits

Author SHA1 Message Date
samyou-softwire 9cee36e26e CLDC-4402: lint 2 days ago
samyou-softwire 328ba47ffa CLDC-4402: form spec changes 2 days ago
samyou-softwire acd763ada1 CLDC-4402: model questions 1 week ago
samyou-softwire edddcf0b15 CLDC-4402: lettings log export service spec 1 week ago
  1. 6
      spec/models/form/lettings/questions/joint_spec.rb
  2. 26
      spec/models/form/lettings/questions/la_spec.rb
  3. 13
      spec/models/form/lettings/questions/tenancy_length_spec.rb
  4. 13
      spec/models/form/lettings/questions/tenancy_other_spec.rb
  5. 49
      spec/models/form/lettings/questions/waityear_spec.rb
  6. 203
      spec/models/form_spec.rb
  7. 46
      spec/services/exports/lettings_log_export_service_spec.rb

6
spec/models/form/lettings/questions/joint_spec.rb

@ -1,13 +1,15 @@
require "rails_helper"
RSpec.describe Form::Lettings::Questions::Joint, type: :model do
include CollectionTimeHelper
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, start_date: Time.zone.local(2023, 4, 1)) }
let(:form) { instance_double(Form, start_date: current_collection_start_date) }
before do
allow(page).to receive(:subsection).and_return(subsection)
@ -40,6 +42,6 @@ RSpec.describe Form::Lettings::Questions::Joint, type: :model do
end
it "has the correct question number" do
expect(question.question_number).to eq(26)
expect(question.question_number).to eq(25)
end
end

26
spec/models/form/lettings/questions/la_spec.rb

@ -1,13 +1,19 @@
require "rails_helper"
RSpec.describe Form::Lettings::Questions::La, type: :model do
include CollectionTimeHelper
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) }
let(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form, start_date: current_collection_start_date) }
let(:page) { instance_double(Form::Page, subsection:) }
let(:start_date) { Time.utc(2023, 4, 1) }
before do
allow(subsection).to receive(:form).and_return(form)
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
@ -69,6 +75,12 @@ RSpec.describe Form::Lettings::Questions::La, type: :model do
"E06000058" => "Bournemouth, Christchurch and Poole",
"E06000059" => "Dorset",
"E06000060" => "Buckinghamshire",
"E06000061" => "North Northamptonshire",
"E06000062" => "West Northamptonshire",
"E06000063" => "Cumberland",
"E06000064" => "Westmorland and Furness",
"E06000065" => "North Yorkshire",
"E06000066" => "Somerset",
"E07000008" => "Cambridge",
"E07000009" => "East Cambridgeshire",
"E07000010" => "Fenland",
@ -175,8 +187,6 @@ RSpec.describe Form::Lettings::Questions::La, type: :model do
"E07000147" => "North Norfolk",
"E07000148" => "Norwich",
"E07000149" => "South Norfolk",
"E06000061" => "North Northamptonshire",
"E06000062" => "West Northamptonshire",
"E07000170" => "Ashfield",
"E07000171" => "Bassetlaw",
"E07000172" => "Broxtowe",
@ -250,10 +260,8 @@ RSpec.describe Form::Lettings::Questions::La, type: :model do
"E08000013" => "St. Helens",
"E08000014" => "Sefton",
"E08000015" => "Wirral",
"E08000016" => "Barnsley",
"E08000017" => "Doncaster",
"E08000018" => "Rotherham",
"E08000019" => "Sheffield",
"E08000021" => "Newcastle upon Tyne",
"E08000022" => "North Tyneside",
"E08000023" => "South Tyneside",
@ -263,7 +271,6 @@ RSpec.describe Form::Lettings::Questions::La, type: :model do
"E08000027" => "Dudley",
"E08000028" => "Sandwell",
"E08000029" => "Solihull",
"E06000066" => "Somerset",
"E08000030" => "Walsall",
"E08000031" => "Wolverhampton",
"E08000032" => "Bradford",
@ -272,6 +279,8 @@ RSpec.describe Form::Lettings::Questions::La, type: :model do
"E08000035" => "Leeds",
"E08000036" => "Wakefield",
"E08000037" => "Gateshead",
"E08000038" => "Barnsley",
"E08000039" => "Sheffield",
"E09000001" => "City of London",
"E09000002" => "Barking and Dagenham",
"E09000003" => "Barnet",
@ -280,7 +289,6 @@ RSpec.describe Form::Lettings::Questions::La, type: :model do
"E09000006" => "Bromley",
"E09000007" => "Camden",
"E09000008" => "Croydon",
"E06000063" => "Cumberland",
"E09000009" => "Ealing",
"E09000010" => "Enfield",
"E09000011" => "Greenwich",
@ -306,8 +314,6 @@ RSpec.describe Form::Lettings::Questions::La, type: :model do
"E09000031" => "Waltham Forest",
"E09000032" => "Wandsworth",
"E09000033" => "Westminster",
"E06000064" => "Westmorland and Furness",
"E06000065" => "North Yorkshire",
})
end

13
spec/models/form/lettings/questions/tenancy_length_spec.rb

@ -1,10 +1,17 @@
require "rails_helper"
RSpec.describe Form::Lettings::Questions::TenancyLength, type: :model do
include CollectionTimeHelper
subject(:question) { described_class.new(nil, nil, page) }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date:)), id: "tenancy_length") }
let(:start_date) { Time.utc(2023, 4, 1) }
let(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form, start_date: current_collection_start_date) }
let(:page) { instance_double(Form::Page, subsection:, id: "tenancy_length") }
before do
allow(subsection).to receive(:form).and_return(form)
end
it "has correct page" do
expect(question.page).to eq(page)
@ -32,6 +39,6 @@ RSpec.describe Form::Lettings::Questions::TenancyLength, type: :model do
end
it "has the correct question number" do
expect(question.question_number).to eq(29)
expect(question.question_number).to eq(28)
end
end

13
spec/models/form/lettings/questions/tenancy_other_spec.rb

@ -1,10 +1,17 @@
require "rails_helper"
RSpec.describe Form::Lettings::Questions::TenancyOther, type: :model do
include CollectionTimeHelper
subject(:question) { described_class.new(nil, nil, page) }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date:)), id: "tenancy_type") }
let(:start_date) { Time.utc(2023, 4, 1) }
let(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form, start_date: current_collection_start_date) }
let(:page) { instance_double(Form::Page, subsection:, id: "tenancy_type") }
before do
allow(subsection).to receive(:form).and_return(form)
end
it "has correct page" do
expect(question.page).to eq(page)
@ -23,6 +30,6 @@ RSpec.describe Form::Lettings::Questions::TenancyOther, type: :model do
end
it "has the correct question number" do
expect(question.question_number).to eq(28)
expect(question.question_number).to eq(27)
end
end

49
spec/models/form/lettings/questions/waityear_spec.rb

@ -14,6 +14,8 @@ RSpec.describe Form::Lettings::Questions::Waityear, type: :model do
allow(form).to receive(:start_year_2025_or_later?).and_return(false)
allow(page).to receive(:subsection).and_return(subsection)
allow(subsection).to receive(:form).and_return(form)
allow(form).to receive(:start_year_2025_or_later?).and_return(true)
allow(form).to receive(:start_year_2025_or_later?).and_return(true)
end
it "has correct page" do
@ -44,39 +46,18 @@ RSpec.describe Form::Lettings::Questions::Waityear, type: :model do
expect(question.check_answers_card_number).to eq(0)
end
describe "before 2025" do
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"2" => { "value" => "Less than 1 year" },
"7" => { "value" => "1 year but under 2 years" },
"8" => { "value" => "2 years but under 3 years" },
"9" => { "value" => "3 years but under 4 years" },
"10" => { "value" => "4 years but under 5 years" },
"5" => { "value" => "5 years or more" },
"divider" => { "value" => true },
"6" => { "value" => "Don’t know" },
})
end
end
context "with 2025/26 form" do
before do
allow(form).to receive(:start_year_2025_or_later?).and_return(true)
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"13" => { "value" => "Household not on the housing register (or waiting list) in this area" },
"2" => { "value" => "Under 1 year" },
"7" => { "value" => "1 year but under 2 years" },
"8" => { "value" => "2 years but under 3 years" },
"9" => { "value" => "3 years but under 4 years" },
"10" => { "value" => "4 years but under 5 years" },
"11" => { "value" => "5 years but under 10 years" },
"12" => { "value" => "10 years or more" },
"divider" => { "value" => true },
"6" => { "value" => "Don’t know" },
})
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"13" => { "value" => "Household not on the housing register (or waiting list) in this area" },
"2" => { "value" => "Under 1 year" },
"7" => { "value" => "1 year but under 2 years" },
"8" => { "value" => "2 years but under 3 years" },
"9" => { "value" => "3 years but under 4 years" },
"10" => { "value" => "4 years but under 5 years" },
"11" => { "value" => "5 years but under 10 years" },
"12" => { "value" => "10 years or more" },
"divider" => { "value" => true },
"6" => { "value" => "Don’t know" },
})
end
end

203
spec/models/form_spec.rb

@ -1,26 +1,17 @@
require "rails_helper"
RSpec.describe Form, type: :model do
around do |example|
Timecop.freeze(Time.zone.local(2022, 1, 1)) do
Singleton.__init__(FormHandler)
example.run
end
Timecop.return
Singleton.__init__(FormHandler)
end
let(:user) { FactoryBot.build(:user) }
let(:lettings_log) { FactoryBot.build(:lettings_log, :in_progress) }
let(:form) { lettings_log.form }
let(:completed_lettings_log) { FactoryBot.build(:lettings_log, :completed) }
describe ".next_page" do
let(:previous_page_id) { form.get_page("person_1_age") }
let(:previous_page_id) { form.get_page("renewal") }
let(:value_check_previous_page) { form.get_page("net_income_value_check") }
it "returns the next page, given the previous" do
expect(form.next_page_id(previous_page_id, lettings_log, user)).to eq("person_1_gender")
expect(form.next_page_id(previous_page_id, lettings_log, user)).to eq("tenancy_start_date")
end
context "when the next page has more than one question" do
@ -68,170 +59,67 @@ RSpec.describe Form, type: :model do
it "returns the previous page if answer is `No` and the page is routed to" do
lettings_log.net_income_value_check = 1
expect(form.next_page_id(value_check_previous_page, lettings_log, user)).to eq("net_income")
expect(form.next_page_id(value_check_previous_page, lettings_log, user)).to eq(:check_answers)
end
it "returns the next page if answer is `Yes` answer and the page is routed to" do
lettings_log.net_income_value_check = 0
expect(form.next_page_id(value_check_previous_page, lettings_log, user)).to eq("net_income_uc_proportion")
expect(form.next_page_id(value_check_previous_page, lettings_log, user)).to eq(:check_answers)
end
end
end
describe ".previous_page" do
context "when the current page is not a value check page" do
let!(:subsection) { form.get_subsection("conditional_question") }
before do
lettings_log.preg_occ = 2
end
it "returns the previous page if the page is routed to" do
page = subsection.pages.find { |p| p.id == "conditional_question_no_second_page" }
expect(form.previous_page_id(page, lettings_log, user)).to eq("conditional_question_no_page")
page = form.get_page("rent_type")
expect(form.previous_page_id(page, lettings_log, user)).to eq("tenancy_start_date")
end
it "returns the page before the previous one if the previous page is not routed to" do
page = subsection.pages.find { |p| p.id == "conditional_question_no_page" }
expect(form.previous_page_id(page, lettings_log, user)).to eq("conditional_question")
lettings_log.needstype = 2
page = form.get_page("renewal")
expect(form.previous_page_id(page, lettings_log, user)).to eq("scheme")
end
end
end
describe "next_page_redirect_path" do
let(:previous_page_id) { form.get_page("net_income") }
let(:last_previous_page) { form.get_page("housing_benefit") }
let(:previous_conditional_page) { form.get_page("conditional_question") }
let(:previous_page_id) { form.get_page("renewal") }
let(:last_previous_page) { form.get_page("property_reference") }
let(:previous_conditional_page) { form.get_page("needs_type") }
it "returns a correct page path if there is no conditional routing" do
expect(form.next_page_redirect_path(previous_page_id, lettings_log, user)).to eq("lettings_log_net_income_uc_proportion_path")
expect(form.next_page_redirect_path(previous_page_id, lettings_log, user)).to eq("lettings_log_tenancy_start_date_path")
end
it "returns a check answers page if previous page is the last page" do
expect(form.next_page_redirect_path(last_previous_page, lettings_log, user)).to eq("lettings_log_income_and_benefits_check_answers_path")
expect(form.next_page_redirect_path(last_previous_page, lettings_log, user)).to eq("lettings_log_declaration_path")
end
it "returns a correct page path if there is conditional routing" do
lettings_log["preg_occ"] = 2
expect(form.next_page_redirect_path(previous_conditional_page, lettings_log, user)).to eq("lettings_log_conditional_question_no_page_path")
lettings_log.needstype = 2
expect(form.next_page_redirect_path(previous_conditional_page, lettings_log, user)).to eq("lettings_log_scheme_path")
end
end
describe "next_incomplete_section_redirect_path" do
let(:lettings_log) { FactoryBot.build_stubbed(:lettings_log, :in_progress) }
let(:subsection) { form.get_subsection("household_characteristics") }
let(:later_subsection) { form.get_subsection("declaration") }
let(:lettings_log) { FactoryBot.create(:lettings_log, :setup_completed) }
let(:subsection) { form.get_subsection("setup") }
let(:later_subsection) { form.get_subsection("income_and_benefits") }
context "when a user is on the check answers page for a subsection" do
def answer_household_needs(lettings_log)
lettings_log.armedforces = 3
lettings_log.illness = 0
lettings_log.housingneeds_a = 1
lettings_log.la = "E06000014"
lettings_log.illness_type_1 = 1
end
def answer_tenancy_information(lettings_log)
lettings_log.tenancycode = "1234"
end
def answer_property_information(lettings_log)
lettings_log.postcode_known = 1
lettings_log.wchair = "No"
end
def answer_conditional_question(lettings_log)
lettings_log.preg_occ = "No"
lettings_log.cbl = "No"
end
def answer_income_and_benefits(lettings_log)
lettings_log.earnings = 30_000
lettings_log.incfreq = 3
lettings_log.benefits = "Some"
lettings_log.hb = "Tenant prefers not to say"
end
def answer_rent_and_charges(lettings_log)
lettings_log.period = "Every 2 weeks"
lettings_log.brent = 650
lettings_log.scharge = 0
lettings_log.pscharge = 0
lettings_log.supcharg = 0
lettings_log.tcharge = 650
end
def answer_local_authority(lettings_log)
lettings_log.layear = "1 year but under 2 years"
lettings_log.waityear = "Less than 1 year"
lettings_log.postcode_full = "NW1 5TY"
lettings_log.reason = "Permanently decanted from another property owned by this landlord"
lettings_log.ppostcode_full = "SE2 6RT"
lettings_log.mrcdate = Time.zone.parse("03/11/2019")
end
before do
lettings_log.tenancycode = "123"
lettings_log.age1 = 35
lettings_log.sex1 = "M"
lettings_log.ecstat1 = 0
lettings_log.hhmemb = 2
lettings_log.relat2 = "P"
lettings_log.sex2 = "F"
lettings_log.ecstat2 = 1
lettings_log.needstype = 1
end
it "returns the first page of the next incomplete subsection if the subsection is not in progress" do
expect(form.next_incomplete_section_redirect_path(subsection, lettings_log)).to eq("armed-forces")
expect(form.next_incomplete_section_redirect_path(subsection, lettings_log)).to eq("first-time-property-let-as-social-housing")
end
it "returns the check answers page of the next incomplete subsection if the subsection is already in progress" do
lettings_log.armedforces = "No"
lettings_log.illness = "No"
expect(form.next_incomplete_section_redirect_path(subsection, lettings_log)).to eq("household-needs/check-answers")
end
it "returns the first page of the next incomplete subsection (skipping completed subsections, and pages that are not routed to)" do
answer_household_needs(lettings_log)
expect(form.next_incomplete_section_redirect_path(subsection, lettings_log)).to eq("property-postcode")
end
it "returns the declaration section for a completed lettings log" do
expect(form.next_incomplete_section_redirect_path(subsection, completed_lettings_log)).to eq("declaration")
lettings_log.first_time_property_let_as_social_housing = 1
expect(form.next_incomplete_section_redirect_path(subsection, lettings_log)).to eq("property-information/check-answers")
end
it "returns the next incomplete section by cycling back around if next subsections are completed" do
expect(form.next_incomplete_section_redirect_path(later_subsection, lettings_log)).to eq("armed-forces")
end
it "returns the declaration section if all sections are complete but the lettings log is in progress" do
answer_household_needs(lettings_log)
answer_tenancy_information(lettings_log)
answer_property_information(lettings_log)
answer_conditional_question(lettings_log)
answer_income_and_benefits(lettings_log)
answer_rent_and_charges(lettings_log)
answer_local_authority(lettings_log)
expect(form.next_incomplete_section_redirect_path(subsection, lettings_log)).to eq("declaration")
end
end
context "when no pages or questions in the next subsection are routed to" do
let(:subsection) { form.get_subsection("setup") }
around do |example|
FormHandler.instance.use_real_forms!
example.run
end
it "finds the path to the section after" do
lettings_log.startdate = Time.zone.local(2022, 9, 1)
lettings_log.renewal = 1
lettings_log.needstype = 2
lettings_log.postcode_known = 0
expect(form.next_incomplete_section_redirect_path(subsection, lettings_log)).to eq("joint")
expect(form.next_incomplete_section_redirect_path(later_subsection, lettings_log)).to eq("first-time-property-let-as-social-housing")
end
end
@ -239,11 +127,6 @@ RSpec.describe Form, type: :model do
let(:lettings_log) { build(:lettings_log, :completed, status: "in_progress") }
let(:subsection) { form.get_subsection("setup") }
before do
Timecop.return
FormHandler.instance.use_real_forms!
end
it "does not raise a Stack Error" do
expect { form.next_incomplete_section_redirect_path(subsection, lettings_log) }.not_to raise_error
end
@ -251,28 +134,21 @@ RSpec.describe Form, type: :model do
end
describe "#reset_not_routed_questions_and_invalid_answers" do
around do |example|
Singleton.__init__(FormHandler)
Timecop.freeze(now) do
FormHandler.instance.use_real_forms!
example.run
end
FormHandler.instance.use_fake_forms!
end
include CollectionTimeHelper
let(:now) { Time.zone.local(2023, 5, 5) }
let(:now) { current_collection_start_date }
context "when there are multiple radio questions for attribute X" do
context "and attribute Y is changed such that a different question for X is routed to" do
let(:log) { FactoryBot.create(:lettings_log, :setup_completed, :sheltered_housing, startdate: now, renewal: 0, prevten:) }
context "and the value of X remains valid" do
let(:prevten) { 36 }
let(:prevten) { 35 }
it "the value of this attribute is not cleared" do
log.renewal = 1
log.form.reset_not_routed_questions_and_invalid_answers(log)
expect(log.prevten).to be 36
expect(log.prevten).to be 35
end
end
@ -291,12 +167,13 @@ RSpec.describe Form, type: :model do
context "when there is one radio question for attribute X" do
context "and the start date or sale date is changed such that the collection year changes and there are different options" do
let(:log) { FactoryBot.create(:lettings_log, :setup_completed, :sheltered_housing, startdate: now, sheltered:) }
let(:previous_year_date) { previous_collection_start_date + 1.month }
context "and the value of X remains valid" do
let(:sheltered) { 2 }
it "the value of this attribute is not cleared" do
log.update!(startdate: Time.zone.local(2023, 1, 1))
log.update!(startdate: previous_year_date)
expect(log.sheltered).to be 2
end
end
@ -305,7 +182,7 @@ RSpec.describe Form, type: :model do
let(:sheltered) { 5 }
it "the value of this attribute is cleared" do
log.update!(startdate: Time.zone.local(2023, 1, 1))
log.update!(startdate: previous_year_date)
expect(log.sheltered).to be_nil
end
end
@ -327,7 +204,7 @@ RSpec.describe Form, type: :model do
context "when there are multiple free user input questions for attribute X" do
context "and attribute Y is changed such that a different question for X is routed to" do
let(:log) { FactoryBot.create(:sales_log, :saledate_today, :shared_ownership, :privacy_notice_seen, jointpur: 1, jointmore: 2, hholdcount: expected_hholdcount) }
let(:log) { FactoryBot.create(:sales_log, :shared_ownership_setup_complete, staircase: 2, jointpur: 1, jointmore: 2, hholdcount: expected_hholdcount) }
let(:expected_hholdcount) { 2 }
it "the value of this attribute is not cleared" do
@ -364,12 +241,12 @@ RSpec.describe Form, type: :model do
end
context "when a value is changed such that a radio and free input questions are no longer routed to" do
let(:log) { FactoryBot.create(:lettings_log, :completed, startdate: now, hhmemb: 2, details_known_2: 0, sex2: "M", relat2: "P", age2_known: 0, age2: 32, ecstat2: 6) }
let(:log) { FactoryBot.create(:lettings_log, :completed, startdate: now, hhmemb: 2, details_known_2: 0, sexrab2: "M", relat2: "P", age2_known: 0, age2: 32, ecstat2: 6) }
it "all attributes relating to that checkbox question are cleared" do
expect(log.hhmemb).to be 2
expect(log.details_known_2).to be 0
expect(log.sex2).to eq("M")
expect(log.sexrab2).to eq("M")
expect(log.relat2).to eq("P")
expect(log.age2_known).to be 0
expect(log.age2).to be 32
@ -377,7 +254,7 @@ RSpec.describe Form, type: :model do
log.update!(hhmemb: 1)
expect(log.details_known_2).to be_nil
expect(log.sex2).to be_nil
expect(log.sexrab2).to be_nil
expect(log.relat2).to be_nil
expect(log.age2_known).to be_nil
expect(log.age2).to be_nil
@ -386,13 +263,15 @@ RSpec.describe Form, type: :model do
end
context "when an attribute is derived, but no questions for that attribute are routed to" do
let(:log) { FactoryBot.create(:sales_log, :outright_sale_setup_complete, value: 200_000) }
let(:log) { FactoryBot.create(:lettings_log, :completed, startdate: now, unittype_gn: 2) }
it "the value of this attribute is not cleared" do
expect(log.deposit).to be_nil
log.update!(mortgageused: 2)
expect(log.form.questions.any? { |q| q.id == "deposit" && q.page.routed_to?(log, nil) }).to be false
expect(log.deposit).not_to be_nil
expect(log.is_bedsit?).to be true
expect(log.form.questions.any? { |q| q.id == "beds" && q.page.routed_to?(log, nil) }).to be false
expect(log.form.questions.any? { |q| q.id == "beds" && q.derived?(log) }).to be true
log.beds = 1
log.form.reset_not_routed_questions_and_invalid_answers(log)
expect(log.beds).to eq 1
end
end

46
spec/services/exports/lettings_log_export_service_spec.rb

@ -152,52 +152,6 @@ RSpec.describe Exports::LettingsLogExportService do
end
end
context "with 23/24 collection period" do
let(:start_time) { Time.zone.local(2023, 4, 3) }
before do
Timecop.freeze(start_time)
Singleton.__init__(FormHandler)
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&uprn=100023336956")
.to_return(status: 200, body: '{"status":200,"results":[{"DPA":{
"PO_BOX_NUMBER": "fake",
"ORGANISATION_NAME": "org",
"DEPARTMENT_NAME": "name",
"SUB_BUILDING_NAME": "building",
"BUILDING_NAME": "name",
"BUILDING_NUMBER": "number",
"DEPENDENT_THOROUGHFARE_NAME": "data",
"THOROUGHFARE_NAME": "thing",
"POST_TOWN": "London",
"POSTCODE": "SE2 6RT"
}}]}', headers: {})
end
after do
Timecop.unfreeze
Singleton.__init__(FormHandler)
end
context "and one lettings log is available for export" do
let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, assigned_to: user, age1: 35, sex1: "F", sexrab1: nil, age2: 32, sex2: "M", sexrab2: nil, uprn_known: 1, uprn: "100023336956", propcode: "123", postcode_full: "SE2 6RT", ppostcode_full: "SE2 6RT", tenancycode: "BZ737", startdate: Time.zone.local(2023, 4, 2, 10, 36, 49), voiddate: Time.zone.local(2021, 11, 3), mrcdate: Time.zone.local(2022, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4) }
let(:expected_zip_filename) { "core_2023_2024_apr_mar_f0001_inc0001.zip" }
let(:expected_data_filename) { "core_2023_2024_apr_mar_f0001_inc0001_pt001.xml" }
let(:xml_export_file) { File.open("spec/fixtures/exports/general_needs_log_23_24.xml", "r:UTF-8") }
it "generates an XML export file with the expected content within the ZIP file" do
expected_content = replace_entity_ids(lettings_log, xml_export_file.read)
expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args) do |_, content|
entry = Zip::File.open_buffer(content).find_entry(expected_data_filename)
expect(entry).not_to be_nil
expect(entry.get_input_stream.read).to have_same_xml_contents_as(expected_content)
end
export_service.export_xml_lettings_logs
end
end
end
context "and multiple lettings logs are available for export on different periods" do
let(:expected_zip_filename2) { "core_2022_2023_apr_mar_f0001_inc0001.zip" }

Loading…
Cancel
Save