trabajo-afectivo/spec/jobs/ticket_user_ticket_counter_job_spec.rb

45 lines
1.2 KiB
Ruby
Raw Normal View History

2022-01-01 13:38:12 +00:00
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
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
{
open: Ticket::State.by_category(:open).first,
closed: Ticket::State.by_category(:closed).first,
}
2019-06-28 11:38:49 +00:00
end
2019-06-28 11:38:49 +00:00
let!(:tickets) do
{
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
described_class.perform_now(
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