From 2a9f49dfce403b6d00d2954df4929c3ef60ae39c Mon Sep 17 00:00:00 2001 From: quentinchampenois <26109239+Quentinchampenois@users.noreply.github.com> Date: Thu, 23 Nov 2023 16:55:22 +0100 Subject: [PATCH] fix: Clean Inactive Users job when user is invalid --- spec/commands/decidim/destroy_account_spec.rb | 10 ++++---- .../cleaner/clean_inactive_users_job_spec.rb | 25 +++++++++++++++++-- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/spec/commands/decidim/destroy_account_spec.rb b/spec/commands/decidim/destroy_account_spec.rb index 9340693..1212be9 100644 --- a/spec/commands/decidim/destroy_account_spec.rb +++ b/spec/commands/decidim/destroy_account_spec.rb @@ -6,7 +6,7 @@ module Decidim describe DestroyAccount do let(:command) { described_class.new(user, form) } let(:user) { create(:user, :confirmed) } - let!(:identity) { create(:identity, user:) } + let!(:identity) { create(:identity, user: user) } let(:valid) { true } let(:data) do { @@ -70,7 +70,7 @@ module Decidim it "deletes user group memberships" do user_group = create(:user_group) - create(:user_group_membership, user_group:, user:) + create(:user_group_membership, user_group: user_group, user: user) expect do command.call @@ -80,7 +80,7 @@ module Decidim it "deletes the follows" do other_user = create(:user) create(:follow, followable: user, user: other_user) - create(:follow, followable: other_user, user:) + create(:follow, followable: other_user, user: user) expect do command.call @@ -88,7 +88,7 @@ module Decidim end it "deletes participatory space private user" do - create(:participatory_space_private_user, user:) + create(:participatory_space_private_user, user: user) expect do command.call @@ -105,4 +105,4 @@ module Decidim end end end -end \ No newline at end of file +end diff --git a/spec/jobs/decidim/cleaner/clean_inactive_users_job_spec.rb b/spec/jobs/decidim/cleaner/clean_inactive_users_job_spec.rb index 6b5d611..a692532 100644 --- a/spec/jobs/decidim/cleaner/clean_inactive_users_job_spec.rb +++ b/spec/jobs/decidim/cleaner/clean_inactive_users_job_spec.rb @@ -5,8 +5,9 @@ describe Decidim::Cleaner::CleanInactiveUsersJob do subject { described_class } + let!(:organization) { create(:organization, delete_inactive_users: true, delete_inactive_users_email_after: 25, delete_inactive_users_after: 5) } + context "when the delay is specified" do - let!(:organization) { create(:organization, delete_inactive_users: true, delete_inactive_users_email_after: 25, delete_inactive_users_after: 5) } let!(:pending_user) { create(:user, organization: organization, current_sign_in_at: 27.days.ago) } let!(:inactive_user) { create(:user, organization: organization, current_sign_in_at: 35.days.ago, warning_date: 10.days.ago) } let!(:user) { create(:user, organization: organization) } @@ -31,7 +32,7 @@ expect(user.reload).not_to be_deleted end - context "when users have destroyed his/her account" do + context "when user has destroyed her account" do let!(:pending_user) { create(:user, :deleted, organization: organization, current_sign_in_at: 27.days.ago) } let!(:inactive_user) { create(:user, :deleted, organization: organization, current_sign_in_at: 35.days.ago, warning_date: 10.days.ago) } @@ -74,4 +75,24 @@ end end end + + context "when user validation fails" do + let(:inactive_user) { build(:user, nickname: "#####", organization: organization, current_sign_in_at: 35.days.ago, warning_date: 10.days.ago) } + + before do + inactive_user.save(validate: false) + end + + it "sends email" do + expect(Decidim::Cleaner::InactiveUsersMailer).to receive(:warning_deletion).with(inactive_user).and_call_original + + subject.perform_now + end + + it "destroys user" do + subject.perform_now + + expect(inactive_user.reload).to be_deleted + end + end end