data_privacy_task_job_spec.rb 2.0 KB

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