data_privacy_task_job_spec.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 the organization is deleted' do
  16. create(:data_privacy_task, deletable: user)
  17. described_class.perform_now
  18. expect(organization.reload).to be_a_kind_of(Organization)
  19. end
  20. it 'checks if the state is completed' do
  21. task = create(:data_privacy_task, deletable: user)
  22. described_class.perform_now
  23. expect(task.reload.state).to eq('completed')
  24. end
  25. it 'checks if the user is deleted (delete_organization=true)' do
  26. create(:data_privacy_task, deletable: user, preferences: { delete_organization: 'true' })
  27. described_class.perform_now
  28. expect { user.reload }.to raise_error(ActiveRecord::RecordNotFound)
  29. end
  30. it 'checks if the organization is deleted (delete_organization=true)' do
  31. create(:data_privacy_task, deletable: user, preferences: { delete_organization: 'true' })
  32. described_class.perform_now
  33. expect { organization.reload }.to raise_error(ActiveRecord::RecordNotFound)
  34. end
  35. it 'checks creation of activity stream log' do
  36. create(:data_privacy_task, deletable: user, created_by: admin)
  37. travel 15.minutes
  38. described_class.perform_now
  39. expect(admin.activity_stream(20).any? { |entry| entry.type.name == 'completed' }).to be true
  40. end
  41. end
  42. end