2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2018-12-21 16:35:15 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe TicketUserTicketCounterJob, type: :job do
|
|
|
|
|
|
|
|
let!(:customer) { create(:user) }
|
|
|
|
|
2019-06-28 11:38:49 +00:00
|
|
|
let!(:ticket_states) do
|
|
|
|
{
|
2018-12-21 16:35:15 +00:00
|
|
|
open: Ticket::State.by_category(:open).first,
|
|
|
|
closed: Ticket::State.by_category(:closed).first,
|
|
|
|
}
|
2019-06-28 11:38:49 +00:00
|
|
|
end
|
2018-12-21 16:35:15 +00:00
|
|
|
|
2019-06-28 11:38:49 +00:00
|
|
|
let!(:tickets) do
|
|
|
|
{
|
2018-12-21 16:35:15 +00:00
|
|
|
open: [
|
|
|
|
create(:ticket, state_id: ticket_states[:open].id, customer_id: customer.id),
|
|
|
|
create(:ticket, state_id: ticket_states[:open].id, customer_id: customer.id),
|
|
|
|
],
|
|
|
|
closed: [
|
|
|
|
create(:ticket, state_id: ticket_states[:closed].id, customer_id: customer.id),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'checks if customer has no ticket count in preferences' do
|
|
|
|
customer.reload
|
|
|
|
expect(customer[:preferences][:tickets_open]).to be_falsey
|
|
|
|
expect(customer[:preferences][:tickets_closed]).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'checks if customer ticket count has been updated in preferences' do
|
2019-09-16 15:04:17 +00:00
|
|
|
described_class.perform_now(
|
2018-12-21 16:35:15 +00:00
|
|
|
customer.id,
|
|
|
|
customer.id,
|
|
|
|
)
|
|
|
|
customer.reload
|
|
|
|
|
|
|
|
expect(customer[:preferences][:tickets_open]).to be tickets[:open].count
|
|
|
|
expect(customer[:preferences][:tickets_closed]).to be tickets[:closed].count
|
|
|
|
end
|
|
|
|
end
|