ticket_user_ticket_counter_job_spec.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright (C) 2012-2024 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: create_list(:ticket, 2, state_id: ticket_states[:open].id, customer_id: customer.id),
  14. closed: create_list(:ticket, 1, state_id: ticket_states[:closed].id, customer_id: customer.id),
  15. }
  16. end
  17. it 'checks if customer has no ticket count in preferences' do
  18. customer.reload
  19. expect(customer[:preferences][:tickets_open]).to be_falsey
  20. expect(customer[:preferences][:tickets_closed]).to be_falsey
  21. end
  22. it 'checks if customer ticket count has been updated in preferences' do
  23. described_class.perform_now(
  24. customer.id,
  25. customer.id,
  26. )
  27. customer.reload
  28. expect(customer[:preferences][:tickets_open]).to be tickets[:open].count
  29. expect(customer[:preferences][:tickets_closed]).to be tickets[:closed].count
  30. end
  31. end