data_privacy_task_job_spec.rb 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe DataPrivacyTaskJob, type: :job do
  4. describe '#perform' do
  5. before do
  6. Setting.set('system_init_done', true)
  7. end
  8. let!(:organization) { create(:organization, name: 'test') }
  9. let!(:admin) { create(:admin) }
  10. let!(:user) { create(:customer, organization: organization) }
  11. it 'checks if the user is deleted' do
  12. create(:data_privacy_task, deletable: user)
  13. described_class.perform_now
  14. expect { user.reload }.to raise_error(ActiveRecord::RecordNotFound)
  15. end
  16. it 'checks if deletion does not crash if the user is already deleted' do
  17. task = create(:data_privacy_task, deletable: user)
  18. user.destroy
  19. described_class.perform_now
  20. expect(task.reload.state).to eq('completed')
  21. end
  22. it 'checks if the organization is deleted' do
  23. create(:data_privacy_task, deletable: user)
  24. described_class.perform_now
  25. expect(organization.reload).to be_a_kind_of(Organization)
  26. end
  27. it 'checks if the state is completed' do
  28. task = create(:data_privacy_task, deletable: user)
  29. described_class.perform_now
  30. expect(task.reload.state).to eq('completed')
  31. end
  32. it 'checks if the user is deleted (delete_organization=true)' do
  33. create(:data_privacy_task, deletable: user, preferences: { delete_organization: 'true' })
  34. described_class.perform_now
  35. expect { user.reload }.to raise_error(ActiveRecord::RecordNotFound)
  36. end
  37. it 'checks if the organization is deleted (delete_organization=true)' do
  38. create(:data_privacy_task, deletable: user, preferences: { delete_organization: 'true' })
  39. described_class.perform_now
  40. expect { organization.reload }.to raise_error(ActiveRecord::RecordNotFound)
  41. end
  42. it 'checks creation of activity stream log' do
  43. create(:data_privacy_task, deletable: user, created_by: admin)
  44. travel 15.minutes
  45. described_class.perform_now
  46. expect(admin.activity_stream(20).any? { |entry| entry.type.name == 'completed' }).to be true
  47. end
  48. end
  49. end