|
|
|
@ -1791,7 +1791,7 @@ RSpec.describe SchemesController, type: :request do |
|
|
|
let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation, created_at: Time.zone.today) } |
|
|
|
let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation, created_at: Time.zone.today) } |
|
|
|
let!(:location) { FactoryBot.create(:location, scheme:) } |
|
|
|
let!(:location) { FactoryBot.create(:location, scheme:) } |
|
|
|
let(:deactivation_date) { Time.utc(2022, 10, 10) } |
|
|
|
let(:deactivation_date) { Time.utc(2022, 10, 10) } |
|
|
|
let!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, location:, scheme:, startdate:, owning_organisation: user.organisation) } |
|
|
|
let!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, location:, scheme:, startdate:, owning_organisation: user.organisation, created_by: user) } |
|
|
|
let(:startdate) { Time.utc(2022, 10, 11) } |
|
|
|
let(:startdate) { Time.utc(2022, 10, 11) } |
|
|
|
let(:setup_schemes) { nil } |
|
|
|
let(:setup_schemes) { nil } |
|
|
|
|
|
|
|
|
|
|
|
@ -1865,18 +1865,21 @@ RSpec.describe SchemesController, type: :request do |
|
|
|
let(:mailer) { instance_double(LocationOrSchemeDeactivationMailer) } |
|
|
|
let(:mailer) { instance_double(LocationOrSchemeDeactivationMailer) } |
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
before do |
|
|
|
allow(LocationOrSchemeDeactivationMailer).to receive(:new).and_return(mailer) |
|
|
|
allow(LocationOrSchemeDeactivationMailer).to receive_message_chain(:send_deactivation_mail, :deliver_later).and_return(true) |
|
|
|
allow(mailer).to receive(:send_deactivation_mails) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Timecop.freeze(Time.utc(2022, 10, 10)) |
|
|
|
Timecop.freeze(Time.utc(2022, 10, 10)) |
|
|
|
sign_in user |
|
|
|
sign_in user |
|
|
|
patch "/schemes/#{scheme.id}/deactivate", params: |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
after do |
|
|
|
Timecop.unfreeze |
|
|
|
Timecop.unfreeze |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "and a log startdate is after scheme deactivation date" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
patch "/schemes/#{scheme.id}/deactivate", params: |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "updates existing scheme with valid deactivation date and renders scheme page" do |
|
|
|
it "updates existing scheme with valid deactivation date and renders scheme page" do |
|
|
|
follow_redirect! |
|
|
|
follow_redirect! |
|
|
|
follow_redirect! |
|
|
|
follow_redirect! |
|
|
|
@ -1887,7 +1890,6 @@ RSpec.describe SchemesController, type: :request do |
|
|
|
expect(scheme.scheme_deactivation_periods.first.deactivation_date).to eq(deactivation_date) |
|
|
|
expect(scheme.scheme_deactivation_periods.first.deactivation_date).to eq(deactivation_date) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "and a log startdate is after scheme deactivation date" do |
|
|
|
|
|
|
|
it "clears the scheme and scheme answers" do |
|
|
|
it "clears the scheme and scheme answers" do |
|
|
|
expect(lettings_log.scheme).to eq(scheme) |
|
|
|
expect(lettings_log.scheme).to eq(scheme) |
|
|
|
expect(lettings_log.scheme).to eq(scheme) |
|
|
|
expect(lettings_log.scheme).to eq(scheme) |
|
|
|
@ -1901,10 +1903,6 @@ RSpec.describe SchemesController, type: :request do |
|
|
|
lettings_log.reload |
|
|
|
lettings_log.reload |
|
|
|
expect(lettings_log.unresolved).to eq(true) |
|
|
|
expect(lettings_log.unresolved).to eq(true) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "sends update E-mails for affected logs" do |
|
|
|
|
|
|
|
expect(mailer).to have_received(:send_deactivation_mails).with([lettings_log], "http://www.example.com/lettings-logs/update-logs", scheme.service_name) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "and a log startdate is before scheme deactivation date" do |
|
|
|
context "and a log startdate is before scheme deactivation date" do |
|
|
|
@ -1924,6 +1922,17 @@ RSpec.describe SchemesController, type: :request do |
|
|
|
expect(lettings_log.unresolved).to eq(nil) |
|
|
|
expect(lettings_log.unresolved).to eq(nil) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "and the users need to be notified" do |
|
|
|
|
|
|
|
it "sends E-mails to the creators of affected logs with counts" do |
|
|
|
|
|
|
|
expect(LocationOrSchemeDeactivationMailer).to receive(:send_deactivation_mail).with(user, |
|
|
|
|
|
|
|
1, |
|
|
|
|
|
|
|
url_for(controller: "lettings_logs", action: "update_logs"), |
|
|
|
|
|
|
|
scheme.service_name) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
patch "/schemes/#{scheme.id}/deactivate", params: |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when the date is not selected" do |
|
|
|
context "when the date is not selected" do |
|
|
|
|