calls_stats_ticket_reopen_log_spec.rb 1.2 KB

1234567891011121314151617181920212223
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ticket::CallsStatsTicketReopenLog' do
  4. let(:agent) { create(:agent, groups: Group.all) }
  5. let(:ticket) { create(:ticket, group: Group.first, owner: agent) }
  6. it 'does track reopened tickets' do
  7. ticket.update(state: Ticket::State.find_by(name: 'closed'))
  8. ticket.update(state: Ticket::State.find_by(name: 'open'))
  9. expect(StatsStore.find_by(key: 'ticket:reopen', stats_storable_type: 'User', stats_storable_id: agent.id).data).to eq({ 'ticket_id'=> ticket.id })
  10. end
  11. it 'does calculate dashboard correctly' do
  12. create_list(:ticket, 8, group: Group.first, owner: agent, state: Ticket::State.find_by(name: 'closed'))
  13. tickets_reopened = create_list(:ticket, 2, group: Group.first, owner: agent, state: Ticket::State.find_by(name: 'closed'))
  14. tickets_reopened.each { |ticket| ticket.update(state: Ticket::State.find_by(name: 'open')) }
  15. Stats.generate
  16. expect(StatsStore.find_by(key: 'dashboard', stats_storable_type: 'User', stats_storable_id: agent.id).data['StatsTicketReopen']).to eq({ 'used_for_average' => 20.0, 'percent' => 20.0, 'average_per_agent' => 20.0, 'state' => 'good', 'count' => 2, 'total' => 10 })
  17. end
  18. end