upload_cache_cleanup_job_spec.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe UploadCacheCleanupJob, type: :job do
  4. context 'when upload cache exists' do
  5. let(:upload_cache) { UploadCache.new(SecureRandom.uuid) }
  6. before do
  7. UserInfo.current_user_id = 1
  8. upload_cache.add(
  9. data: 'current example',
  10. filename: 'current.txt',
  11. preferences: {
  12. 'Content-Type' => 'text/plain',
  13. },
  14. )
  15. travel_to 1.month.ago
  16. # create one taskbar and related upload cache entry, which should not be deleted
  17. taskbar_form_id = SecureRandom.uuid
  18. create(:taskbar, state: { form_id: taskbar_form_id })
  19. UploadCache.new(taskbar_form_id).add(
  20. data: 'Some Example with related Taskbar',
  21. filename: 'another_example_with_taskbar.txt',
  22. preferences: {
  23. 'Content-Type' => 'text/plain',
  24. }
  25. )
  26. 3.times do
  27. upload_cache.add(
  28. data: 'hello world',
  29. filename: 'some.txt',
  30. preferences: {
  31. 'Content-Type' => 'text/plain',
  32. },
  33. )
  34. end
  35. travel_back
  36. end
  37. it 'cleanup the store items which are expired with job' do
  38. expect { described_class.perform_now }.to change(Store, :count).by(-3)
  39. end
  40. end
  41. context 'when upload cache does not exist' do
  42. it 'does not crash' do
  43. expect { described_class.perform_now }.not_to raise_error
  44. end
  45. end
  46. end