ticket_user_ticket_counter_job_spec.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe TicketUserTicketCounterJob, type: :job do
  4. let!(:customer) { create(:user) }
  5. let!(:ticket_states) do
  6. {
  7. open: Ticket::State.by_category(:open).first,
  8. closed: Ticket::State.by_category(:closed).first,
  9. }
  10. end
  11. let!(:tickets) do
  12. {
  13. open: [
  14. create(:ticket, state_id: ticket_states[:open].id, customer_id: customer.id),
  15. create(:ticket, state_id: ticket_states[:open].id, customer_id: customer.id),
  16. ],
  17. closed: [
  18. create(:ticket, state_id: ticket_states[:closed].id, customer_id: customer.id),
  19. ],
  20. }
  21. end
  22. it 'checks if customer has no ticket count in preferences' do
  23. customer.reload
  24. expect(customer[:preferences][:tickets_open]).to be_falsey
  25. expect(customer[:preferences][:tickets_closed]).to be_falsey
  26. end
  27. it 'checks if customer ticket count has been updated in preferences' do
  28. described_class.perform_now(
  29. customer.id,
  30. customer.id,
  31. )
  32. customer.reload
  33. expect(customer[:preferences][:tickets_open]).to be tickets[:open].count
  34. expect(customer[:preferences][:tickets_closed]).to be tickets[:closed].count
  35. end
  36. end