Skip to content

Commit

Permalink
fix: Clean Inactive Users job when user is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentinchampenois committed Nov 23, 2023
1 parent efa5eec commit 2a9f49d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
10 changes: 5 additions & 5 deletions spec/commands/decidim/destroy_account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand All @@ -80,15 +80,15 @@ 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
end.to change(Follow, :count).by(-2)
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
Expand All @@ -105,4 +105,4 @@ module Decidim
end
end
end
end
end
25 changes: 23 additions & 2 deletions spec/jobs/decidim/cleaner/clean_inactive_users_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -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) }

Expand Down Expand Up @@ -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

0 comments on commit 2a9f49d

Please sign in to comment.