ticket_user_ticket_counter_job_spec.rb 1.2 KB

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