Browse Source

feat: enforce crossover tests pass

pull/3324/head
Nat Dean-Lewis 4 days ago
parent
commit
5d536096ac
  1. 18
      spec/features/form/validations_spec.rb
  2. 10
      spec/models/lettings_log_spec.rb
  3. 10
      spec/models/sales_log_spec.rb
  4. 30
      spec/requests/sales_logs_controller_spec.rb

18
spec/features/form/validations_spec.rb

@ -115,7 +115,7 @@ RSpec.describe "validations" do
end end
it "prompts the user to confirm the value is correct with an interruption screen" do it "prompts the user to confirm the value is correct with an interruption screen" do
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/net-income-value-check") expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/income-amount-net-income-value-check")
expect(page).to have_content("You told us that the household’s income is £750.00 weekly") expect(page).to have_content("You told us that the household’s income is £750.00 weekly")
expect(page).to have_content("This is higher than we would expect for the household’s working situation.") expect(page).to have_content("This is higher than we would expect for the household’s working situation.")
expect(page).not_to have_button("Save changes") expect(page).not_to have_button("Save changes")
@ -124,30 +124,30 @@ RSpec.describe "validations" do
end end
it "allows to fix the questions that trigger the soft validation" do it "allows to fix the questions that trigger the soft validation" do
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/net-income-value-check") expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/income-amount-net-income-value-check")
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/income-amount?referrer=interruption_screen").twice expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/income-amount?referrer=interruption_screen").twice
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/lead-tenant-working-situation?referrer=interruption_screen") expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/lead-tenant-working-situation?referrer=interruption_screen")
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/net-income-value-check") expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/income-amount-net-income-value-check")
click_link("Change", href: "/lettings-logs/#{lettings_log.id}/income-amount?referrer=interruption_screen", match: :first) click_link("Change", href: "/lettings-logs/#{lettings_log.id}/income-amount?referrer=interruption_screen", match: :first)
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/income-amount?referrer=interruption_screen") expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/income-amount?referrer=interruption_screen")
fill_in("lettings-log-earnings-field", with: income_under_soft_limit) fill_in("lettings-log-earnings-field", with: income_under_soft_limit)
choose("lettings-log-incfreq-1-field", allow_label_click: true) choose("lettings-log-incfreq-1-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/net-income-value-check") expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/income-amount-net-income-value-check")
expect(page).not_to have_content("You told us that the household’s income is £750.00 weekly") expect(page).not_to have_content("You told us that the household’s income is £750.00 weekly")
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
end end
it "allows to fix the questions from different sections" do it "allows to fix the questions from different sections" do
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/net-income-value-check") expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/income-amount-net-income-value-check")
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/income-amount?referrer=interruption_screen").twice expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/income-amount?referrer=interruption_screen").twice
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/lead-tenant-working-situation?referrer=interruption_screen") expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/lead-tenant-working-situation?referrer=interruption_screen")
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/net-income-value-check") expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/income-amount-net-income-value-check")
click_link("Change", href: "/lettings-logs/#{lettings_log.id}/lead-tenant-working-situation?referrer=interruption_screen") click_link("Change", href: "/lettings-logs/#{lettings_log.id}/lead-tenant-working-situation?referrer=interruption_screen")
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/lead-tenant-working-situation?referrer=interruption_screen") expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/lead-tenant-working-situation?referrer=interruption_screen")
choose("lettings-log-ecstat1-10-field", allow_label_click: true) choose("lettings-log-ecstat1-10-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/net-income-value-check") expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/income-amount-net-income-value-check")
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
end end
@ -158,12 +158,12 @@ RSpec.describe "validations" do
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/income-amount?referrer=check_answers") expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/income-amount?referrer=check_answers")
fill_in("lettings-log-earnings-field", with: income_over_soft_limit) fill_in("lettings-log-earnings-field", with: income_over_soft_limit)
click_button("Save changes") click_button("Save changes")
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/net-income-value-check?referrer=check_answers") expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/income-amount-net-income-value-check?referrer=check_answers")
click_link("Change", href: "/lettings-logs/#{lettings_log.id}/income-amount?referrer=interruption_screen", match: :first) click_link("Change", href: "/lettings-logs/#{lettings_log.id}/income-amount?referrer=interruption_screen", match: :first)
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/income-amount?referrer=interruption_screen") expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/income-amount?referrer=interruption_screen")
fill_in("lettings-log-earnings-field", with: income_under_soft_limit) fill_in("lettings-log-earnings-field", with: income_under_soft_limit)
click_button("Save and continue") click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/net-income-value-check?referrer=check_answers") expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/income-amount-net-income-value-check?referrer=check_answers")
click_button("Confirm and continue") click_button("Confirm and continue")
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/income-and-benefits/check-answers") expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/income-and-benefits/check-answers")
end end

10
spec/models/lettings_log_spec.rb

@ -1382,6 +1382,16 @@ RSpec.describe LettingsLog do
end end
describe "scopes" do describe "scopes" do
# These examples need logs in both the previous and the current collection year,
# so we have to enforce we are in the crossover period
around do |example|
Timecop.freeze(current_collection_start_date) do
Singleton.__init__(FormHandler)
example.run
end
Singleton.__init__(FormHandler)
end
let!(:lettings_log_1) { create(:lettings_log, :in_progress, startdate: previous_collection_start_date + 1.month, mrcdate: previous_collection_start_date, voiddate: previous_collection_start_date, assigned_to: assigned_to_user) } let!(:lettings_log_1) { create(:lettings_log, :in_progress, startdate: previous_collection_start_date + 1.month, mrcdate: previous_collection_start_date, voiddate: previous_collection_start_date, assigned_to: assigned_to_user) }
let!(:lettings_log_2) { create(:lettings_log, :completed, startdate: previous_collection_start_date + 1.month, mrcdate: previous_collection_start_date, voiddate: previous_collection_start_date, assigned_to: assigned_to_user) } let!(:lettings_log_2) { create(:lettings_log, :completed, startdate: previous_collection_start_date + 1.month, mrcdate: previous_collection_start_date, voiddate: previous_collection_start_date, assigned_to: assigned_to_user) }
let(:postcode_to_search) { "SW1A 0AA" } let(:postcode_to_search) { "SW1A 0AA" }

10
spec/models/sales_log_spec.rb

@ -190,6 +190,16 @@ RSpec.describe SalesLog, type: :model do
end end
context "when filtering by year or nil" do context "when filtering by year or nil" do
# These examples need logs in both the previous and the current collection year,
# so we have to enforce we are in the crossover period
around do |example|
Timecop.freeze(current_collection_start_date) do
Singleton.__init__(FormHandler)
example.run
end
Singleton.__init__(FormHandler)
end
let(:previous_year) { previous_collection_start_year.to_s } let(:previous_year) { previous_collection_start_year.to_s }
let(:current_year) { current_collection_start_year.to_s } let(:current_year) { current_collection_start_year.to_s }

30
spec/requests/sales_logs_controller_spec.rb

@ -65,6 +65,16 @@ RSpec.describe SalesLogsController, type: :request do
end end
context "with a request containing invalid json parameters" do context "with a request containing invalid json parameters" do
# These examples need logs in both the previous and the current collection year,
# so we have to enforce we are in the crossover period
around do |example|
Timecop.freeze(current_collection_start_date) do
Singleton.__init__(FormHandler)
example.run
end
Singleton.__init__(FormHandler)
end
let(:params) do let(:params) do
invalid_sales_log = FactoryBot.build( invalid_sales_log = FactoryBot.build(
:sales_log, :sales_log,
@ -356,6 +366,16 @@ RSpec.describe SalesLogsController, type: :request do
end end
context "with year filter" do context "with year filter" do
# Needs logs in both the previous and the current collection year, so must run inside
# the crossover period, when new logs can still be created for both.
around do |example|
Timecop.freeze(current_collection_start_date) do
Singleton.__init__(FormHandler)
example.run
end
Singleton.__init__(FormHandler)
end
let!(:sales_log_current) do let!(:sales_log_current) do
FactoryBot.create(:sales_log, :completed, FactoryBot.create(:sales_log, :completed,
owning_organisation: organisation, owning_organisation: organisation,
@ -383,6 +403,16 @@ RSpec.describe SalesLogsController, type: :request do
end end
context "with year and status filter" do context "with year and status filter" do
# Needs logs in both the previous and the current collection year, so must run inside
# the crossover period, when new logs can still be created for both.
around do |example|
Timecop.freeze(current_collection_start_date) do
Singleton.__init__(FormHandler)
example.run
end
Singleton.__init__(FormHandler)
end
let!(:sales_log_current) do let!(:sales_log_current) do
FactoryBot.create(:sales_log, :completed, FactoryBot.create(:sales_log, :completed,
owning_organisation: organisation, owning_organisation: organisation,

Loading…
Cancel
Save