Browse Source

Update more tests

pull/2361/head
Kat 2 years ago
parent
commit
f435732547
  1. 4
      spec/features/schemes_helpers.rb
  2. 16
      spec/features/schemes_spec.rb
  3. 3
      spec/models/validations/household_validations_spec.rb
  4. 30
      spec/requests/duplicate_logs_controller_spec.rb
  5. 9
      spec/requests/locations_controller_spec.rb
  6. 2
      spec/services/bulk_upload/lettings/validator_spec.rb
  7. 7
      spec/services/merge/merge_organisations_service_spec.rb

4
spec/features/schemes_helpers.rb

@ -76,7 +76,7 @@ module SchemesHelpers
click_button "Save and continue"
fill_in "Day", with: 2
fill_in "Month", with: 5
fill_in "Year", with: 2022
fill_in "Year", with: 2023
click_button "Save and continue"
end
@ -97,7 +97,7 @@ module SchemesHelpers
click_button "Save and continue"
fill_in "Day", with: 2
fill_in "Month", with: 5
fill_in "Year", with: 2022
fill_in "Year", with: 2023
click_button "Save and continue"
end

16
spec/features/schemes_spec.rb

@ -10,12 +10,17 @@ RSpec.describe "Schemes scheme Features" do
let!(:scheme_to_search) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
before do
Timecop.freeze(Time.zone.local(2024, 3, 1))
visit("/lettings-logs")
fill_in("user[email]", with: user.email)
fill_in("user[password]", with: user.password)
click_button("Sign in")
end
after do
Timecop.return
end
it "displays the link to the schemes" do
expect(page).to have_link("Schemes", href: "/schemes")
end
@ -532,7 +537,6 @@ RSpec.describe "Schemes scheme Features" do
context "when adding a location" do
before do
Timecop.freeze(Time.zone.local(2023, 3, 3))
create_and_save_a_scheme
click_button "Create scheme"
end
@ -600,17 +604,12 @@ RSpec.describe "Schemes scheme Features" do
context "when changing location details" do
before do
Timecop.freeze(Time.zone.local(2024, 3, 1))
create_and_save_a_scheme
click_button "Create scheme"
fill_in_and_save_second_location
click_button "Save and return to locations"
end
after do
Timecop.return
end
it "displays changed location" do
click_link "XX12XX"
click_link("Change", href: "/schemes/#{scheme.id}/locations/#{location.id}/name?referrer=details", match: :first)
@ -623,14 +622,9 @@ RSpec.describe "Schemes scheme Features" do
context "when changing scheme answers" do
before do
Timecop.freeze(Time.zone.local(2024, 3, 1))
create_and_save_a_scheme_no_secondary_client_group
end
after do
Timecop.return
end
it "displays change links" do
assert_selector "a", text: "Change", count: 10
end

3
spec/models/validations/household_validations_spec.rb

@ -295,10 +295,11 @@ RSpec.describe Validations::HouseholdValidations do
end
describe "#validate_partner_count" do
let(:log_date) { Time.zone.local(2023, 4, 1) }
it "validates that only 1 partner exists" do
record.relat2 = "P"
record.relat3 = "P"
record.startdate = Time.zone.local(2023, 4, 1)
household_validator.validate_partner_count(record)
expect(record.errors["relat2"])
.to include(match I18n.t("validations.household.relat.one_partner"))

30
spec/requests/duplicate_logs_controller_spec.rb

@ -7,6 +7,16 @@ RSpec.describe DuplicateLogsController, type: :request do
let(:sales_log) { create(:sales_log, :duplicate, created_by: user) }
describe "GET show" do
before do
Timecop.freeze(Time.zone.local(2024, 3, 1))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "when user is not signed in" do
it "redirects to sign in page" do
get "/lettings-logs/#{lettings_log.id}/duplicate-logs"
@ -591,6 +601,16 @@ RSpec.describe DuplicateLogsController, type: :request do
context "when accessed from the duplicate logs banner flow" do
let(:request) { get "/sales-logs/#{id}/delete-duplicates?original_log_id=#{id}&referrer=duplicate_logs_banner" }
before do
Timecop.freeze(Time.zone.local(2024, 3, 1))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "when there is 1 duplicate log being deleted" do
let!(:duplicate_log) { create(:sales_log, :duplicate, created_by: user) }
@ -628,6 +648,16 @@ RSpec.describe DuplicateLogsController, type: :request do
end
context "when accessed from the single log submission flow" do
before do
Timecop.freeze(Time.zone.local(2024, 3, 1))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "when there is 1 duplicate log being deleted" do
let!(:duplicate_log) { create(:sales_log, :duplicate, created_by: user) }

9
spec/requests/locations_controller_spec.rb

@ -7,9 +7,16 @@ RSpec.describe LocationsController, type: :request do
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
before do
Timecop.freeze(Time.zone.local(2024, 3, 1))
Singleton.__init__(FormHandler)
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
describe "#create" do
context "when not signed in" do
it "redirects to the sign in page" do
@ -130,7 +137,7 @@ RSpec.describe LocationsController, type: :request do
before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 4, 1), location: deactivated_location)
Timecop.return
Timecop.freeze(2023, 3, 3)
end
it "shows locations for multiple selected statuses" do

2
spec/services/bulk_upload/lettings/validator_spec.rb

@ -5,7 +5,7 @@ RSpec.describe BulkUpload::Lettings::Validator do
let(:organisation) { create(:organisation, old_visible_id: "3") }
let(:user) { create(:user, organisation:) }
let(:log) { build(:lettings_log, :completed) }
let(:log) { build(:lettings_log, :completed, startdate: Time.zone.local(2024, 3, 3)) }
let(:bulk_upload) { create(:bulk_upload, user:) }
let(:path) { file.path }
let(:file) { Tempfile.new }

7
spec/services/merge/merge_organisations_service_spec.rb

@ -3,11 +3,18 @@ require "rails_helper"
RSpec.describe Merge::MergeOrganisationsService do
describe "#call" do
before do
Timecop.freeze(Time.zone.local(2024, 3, 1))
Singleton.__init__(FormHandler)
mail_double = instance_double("ActionMailer::MessageDelivery", deliver_later: nil)
allow(MergeCompletionMailer).to receive(:send_merged_organisation_success_mail).and_return(mail_double)
allow(MergeCompletionMailer).to receive(:send_absorbing_organisation_success_mail).and_return(mail_double)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "when merging a single organisation into an existing organisation" do
subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: nil) }

Loading…
Cancel
Save