Browse Source

Do not send deactivation emails when user not present (#1705)

pull/1708/head
Jack 2 years ago committed by GitHub
parent
commit
f3ab2c496d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      app/controllers/locations_controller.rb
  2. 15
      app/controllers/schemes_controller.rb
  3. 27
      spec/requests/locations_controller_spec.rb
  4. 12
      spec/requests/schemes_controller_spec.rb

17
app/controllers/locations_controller.rb

@ -180,12 +180,17 @@ class LocationsController < ApplicationController
logs = reset_location_and_scheme_for_logs!
flash[:notice] = deactivate_success_notice
logs.group_by(&:created_by).transform_values(&:count).compact.each do |user, count|
LocationOrSchemeDeactivationMailer.send_deactivation_mail(user,
count,
url_for(controller: "lettings_logs", action: "update_logs"),
@location.scheme.service_name,
@location.postcode).deliver_later
logs.group_by(&:created_by).transform_values(&:count).each do |user, count|
next unless user
LocationOrSchemeDeactivationMailer.send_deactivation_mail(
user,
count,
url_for(controller: "lettings_logs", action: "update_logs"),
@location.scheme.service_name,
@location.postcode,
).deliver_later
end
end
redirect_to scheme_location_path(@scheme, @location)

15
app/controllers/schemes_controller.rb

@ -58,11 +58,16 @@ class SchemesController < ApplicationController
logs = reset_location_and_scheme_for_logs!
flash[:notice] = deactivate_success_notice
logs.group_by(&:created_by).transform_values(&:count).compact.each do |user, count|
LocationOrSchemeDeactivationMailer.send_deactivation_mail(user,
count,
url_for(controller: "lettings_logs", action: "update_logs"),
@scheme.service_name).deliver_later
logs.group_by(&:created_by).transform_values(&:count).each do |user, count|
next unless user
LocationOrSchemeDeactivationMailer.send_deactivation_mail(
user,
count,
url_for(controller: "lettings_logs", action: "update_logs"),
@scheme.service_name,
).deliver_later
end
end
redirect_to scheme_details_path(@scheme)

27
spec/requests/locations_controller_spec.rb

@ -1467,13 +1467,14 @@ RSpec.describe LocationsController, type: :request do
context "when confirming deactivation" do
let(:params) { { deactivation_date:, confirm: true, deactivation_date_type: "other" } }
let(:mailer) { instance_double(LocationOrSchemeDeactivationMailer) }
let(:user_a) { create(:user, email: "user_a@example.com") }
let(:user_b) { create(:user, email: "user_b@example.com") }
let(:user_a) { create(:user) }
let(:user_b) { create(:user) }
before do
create_list(:lettings_log, 1, :sh, location:, scheme:, startdate:, created_by: user_a)
allow(LocationOrSchemeDeactivationMailer).to receive(:send_deactivation_mail).and_call_original
create(:lettings_log, :sh, location:, scheme:, startdate:, created_by: user_a)
create_list(:lettings_log, 3, :sh, location:, scheme:, startdate:, created_by: user_b)
Timecop.freeze(Time.utc(2022, 10, 10))
@ -1511,6 +1512,24 @@ RSpec.describe LocationsController, type: :request do
lettings_log.reload
expect(lettings_log.unresolved).to eq(true)
end
it "sends deactivation emails" do
expect(LocationOrSchemeDeactivationMailer).to have_received(:send_deactivation_mail).with(
user_a,
1,
update_logs_lettings_logs_url,
location.scheme.service_name,
location.postcode,
)
expect(LocationOrSchemeDeactivationMailer).to have_received(:send_deactivation_mail).with(
user_b,
3,
update_logs_lettings_logs_url,
location.scheme.service_name,
location.postcode,
)
end
end
context "and the users need to be notified" do

12
spec/requests/schemes_controller_spec.rb

@ -1930,7 +1930,6 @@ RSpec.describe SchemesController, type: :request do
context "when confirming deactivation" do
let(:params) { { deactivation_date:, confirm: true, deactivation_date_type: "other" } }
let(:mailer) { instance_double(LocationOrSchemeDeactivationMailer) }
before do
Timecop.freeze(Time.utc(2022, 10, 10))
@ -1943,6 +1942,8 @@ RSpec.describe SchemesController, type: :request do
context "and a log startdate is after scheme deactivation date" do
before do
allow(LocationOrSchemeDeactivationMailer).to receive(:send_deactivation_mail).and_call_original
patch "/schemes/#{scheme.id}/deactivate", params:
end
@ -1969,6 +1970,15 @@ RSpec.describe SchemesController, type: :request do
lettings_log.reload
expect(lettings_log.unresolved).to eq(true)
end
it "sends deactivation emails" do
expect(LocationOrSchemeDeactivationMailer).to have_received(:send_deactivation_mail).with(
user,
1,
update_logs_lettings_logs_url,
scheme.service_name,
)
end
end
context "and a log startdate is before scheme deactivation date" do

Loading…
Cancel
Save