2017-05-02 11:37:20 +00:00
|
|
|
|
require 'rails_helper'
|
2019-01-22 16:35:01 +00:00
|
|
|
|
require 'models/application_model_examples'
|
2019-01-28 06:04:05 +00:00
|
|
|
|
require 'models/concerns/can_be_imported_examples'
|
2019-10-21 10:44:52 +00:00
|
|
|
|
require 'models/concerns/can_csv_import_examples'
|
2019-06-28 13:07:14 +00:00
|
|
|
|
require 'models/concerns/has_history_examples'
|
2019-07-03 16:02:29 +00:00
|
|
|
|
require 'models/concerns/has_tags_examples'
|
2020-09-08 15:06:23 +00:00
|
|
|
|
require 'models/concerns/has_taskbars_examples'
|
2019-02-12 07:38:59 +00:00
|
|
|
|
require 'models/concerns/has_xss_sanitized_note_examples'
|
2019-03-13 23:51:22 +00:00
|
|
|
|
require 'models/concerns/has_object_manager_attributes_validation_examples'
|
2017-05-02 11:37:20 +00:00
|
|
|
|
|
2019-01-22 16:35:01 +00:00
|
|
|
|
RSpec.describe Ticket, type: :model do
|
2020-09-30 09:07:01 +00:00
|
|
|
|
subject(:ticket) { create(:ticket) }
|
|
|
|
|
|
2019-01-24 10:13:04 +00:00
|
|
|
|
it_behaves_like 'ApplicationModel'
|
2019-01-28 06:04:05 +00:00
|
|
|
|
it_behaves_like 'CanBeImported'
|
2019-10-21 10:44:52 +00:00
|
|
|
|
it_behaves_like 'CanCsvImport'
|
2019-06-28 13:07:14 +00:00
|
|
|
|
it_behaves_like 'HasHistory', history_relation_object: 'Ticket::Article'
|
2019-07-03 16:02:29 +00:00
|
|
|
|
it_behaves_like 'HasTags'
|
2020-09-08 15:06:23 +00:00
|
|
|
|
it_behaves_like 'HasTaskbars'
|
2019-02-12 07:38:59 +00:00
|
|
|
|
it_behaves_like 'HasXssSanitizedNote', model_factory: :ticket
|
2019-03-13 23:51:22 +00:00
|
|
|
|
it_behaves_like 'HasObjectManagerAttributesValidation'
|
2017-05-02 11:37:20 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
describe 'Class methods:' do
|
|
|
|
|
describe '.selectors' do
|
|
|
|
|
# https://github.com/zammad/zammad/issues/1769
|
|
|
|
|
context 'when matching multiple tickets, each with multiple articles' do
|
|
|
|
|
let(:tickets) { create_list(:ticket, 2) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
create(:ticket_article, ticket: tickets.first, from: 'asdf1@blubselector.de')
|
|
|
|
|
create(:ticket_article, ticket: tickets.first, from: 'asdf2@blubselector.de')
|
|
|
|
|
create(:ticket_article, ticket: tickets.first, from: 'asdf3@blubselector.de')
|
|
|
|
|
create(:ticket_article, ticket: tickets.last, from: 'asdf4@blubselector.de')
|
|
|
|
|
create(:ticket_article, ticket: tickets.last, from: 'asdf5@blubselector.de')
|
|
|
|
|
create(:ticket_article, ticket: tickets.last, from: 'asdf6@blubselector.de')
|
|
|
|
|
end
|
2019-01-04 15:29:56 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
let(:condition) do
|
|
|
|
|
{
|
|
|
|
|
'article.from' => {
|
|
|
|
|
operator: 'contains',
|
|
|
|
|
value: 'blubselector.de',
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
end
|
2017-05-05 09:16:47 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
it 'returns a list of unique tickets (i.e., no duplicates)' do
|
2019-09-16 15:04:17 +00:00
|
|
|
|
expect(described_class.selectors(condition, limit: 100, access: 'full'))
|
2019-03-27 09:01:36 +00:00
|
|
|
|
.to match_array([2, tickets.to_a])
|
2019-02-10 12:24:22 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2017-05-05 09:16:47 +00:00
|
|
|
|
end
|
2017-05-02 11:37:20 +00:00
|
|
|
|
end
|
2017-05-05 09:16:47 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
describe 'Instance methods:' do
|
|
|
|
|
describe '#merge_to' do
|
|
|
|
|
let(:target_ticket) { create(:ticket) }
|
2017-05-05 09:16:47 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
context 'when source ticket has Links' do
|
|
|
|
|
let(:linked_tickets) { create_list(:ticket, 3) }
|
|
|
|
|
let(:links) { linked_tickets.map { |l| create(:link, from: ticket, to: l) } }
|
2017-05-05 09:16:47 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
it 'reassigns all links to the target ticket after merge' do
|
|
|
|
|
expect { ticket.merge_to(ticket_id: target_ticket.id, user_id: 1) }
|
|
|
|
|
.to change { links.each(&:reload).map(&:link_object_source_value) }
|
|
|
|
|
.to(Array.new(3) { target_ticket.id })
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-05-05 09:16:47 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
context 'when attempting to cross-merge (i.e., to merge B → A after merging A → B)' do
|
|
|
|
|
before { target_ticket.merge_to(ticket_id: ticket.id, user_id: 1) }
|
2017-05-05 09:16:47 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
it 'raises an error' do
|
|
|
|
|
expect { ticket.merge_to(ticket_id: target_ticket.id, user_id: 1) }
|
|
|
|
|
.to raise_error('ticket already merged, no merge into merged ticket possible')
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-05-05 09:16:47 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
context 'when attempting to self-merge (i.e., to merge A → A)' do
|
|
|
|
|
it 'raises an error' do
|
|
|
|
|
expect { ticket.merge_to(ticket_id: ticket.id, user_id: 1) }
|
|
|
|
|
.to raise_error("Can't merge ticket with it self!")
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-02-13 09:09:20 +00:00
|
|
|
|
|
|
|
|
|
context 'when merging' do
|
|
|
|
|
let(:merge_user) { create(:user) }
|
|
|
|
|
|
2019-05-20 09:41:28 +00:00
|
|
|
|
before do
|
|
|
|
|
# create target ticket early
|
|
|
|
|
# to avoid a race condition
|
|
|
|
|
# when creating the history entries
|
|
|
|
|
target_ticket
|
|
|
|
|
travel 5.minutes
|
|
|
|
|
|
2019-02-13 09:09:20 +00:00
|
|
|
|
ticket.merge_to(ticket_id: target_ticket.id, user_id: merge_user.id)
|
2020-08-03 11:36:53 +00:00
|
|
|
|
end
|
2019-02-13 09:09:20 +00:00
|
|
|
|
|
2020-08-03 11:36:53 +00:00
|
|
|
|
# Issue #2469 - Add information "Ticket merged" to History
|
|
|
|
|
it 'creates history entries in both the origin ticket and the target ticket' do
|
2019-02-13 09:09:20 +00:00
|
|
|
|
expect(target_ticket.history_get.size).to eq 2
|
|
|
|
|
|
|
|
|
|
target_history = target_ticket.history_get.last
|
|
|
|
|
expect(target_history['object']).to eq 'Ticket'
|
|
|
|
|
expect(target_history['type']).to eq 'received_merge'
|
|
|
|
|
expect(target_history['created_by_id']).to eq merge_user.id
|
|
|
|
|
expect(target_history['o_id']).to eq target_ticket.id
|
|
|
|
|
expect(target_history['id_to']).to eq target_ticket.id
|
|
|
|
|
expect(target_history['id_from']).to eq ticket.id
|
|
|
|
|
|
|
|
|
|
expect(ticket.history_get.size).to eq 4
|
|
|
|
|
|
|
|
|
|
origin_history = ticket.reload.history_get[1]
|
|
|
|
|
expect(origin_history['object']).to eq 'Ticket'
|
|
|
|
|
expect(origin_history['type']).to eq 'merged_into'
|
|
|
|
|
expect(origin_history['created_by_id']).to eq merge_user.id
|
|
|
|
|
expect(origin_history['o_id']).to eq ticket.id
|
|
|
|
|
expect(origin_history['id_to']).to eq target_ticket.id
|
|
|
|
|
expect(origin_history['id_from']).to eq ticket.id
|
|
|
|
|
end
|
2020-07-20 06:19:51 +00:00
|
|
|
|
|
|
|
|
|
it 'sends ExternalSync.migrate' do
|
|
|
|
|
allow(ExternalSync).to receive(:migrate)
|
|
|
|
|
|
|
|
|
|
ticket.merge_to(ticket_id: target_ticket.id, user_id: merge_user.id)
|
|
|
|
|
|
|
|
|
|
expect(ExternalSync).to have_received(:migrate).with('Ticket', ticket.id, target_ticket.id)
|
|
|
|
|
end
|
2020-08-03 11:36:53 +00:00
|
|
|
|
|
|
|
|
|
# Issue #2960 - Ticket removal of merged / linked tickets doesn't remove references
|
|
|
|
|
context 'and deleting the origin ticket' do
|
|
|
|
|
it 'adds reference number and title to the target ticket' do
|
|
|
|
|
expect { ticket.destroy }
|
2020-09-30 09:07:01 +00:00
|
|
|
|
.to change { target_ticket.history_get.find { |elem| elem.fetch('type') == 'received_merge' }['value_from'] }
|
2020-08-03 11:36:53 +00:00
|
|
|
|
.to("##{ticket.number} #{ticket.title}")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Issue #2960 - Ticket removal of merged / linked tickets doesn't remove references
|
|
|
|
|
context 'and deleting the target ticket' do
|
|
|
|
|
it 'adds reference number and title to the origin ticket' do
|
|
|
|
|
expect { target_ticket.destroy }
|
2020-09-30 09:07:01 +00:00
|
|
|
|
.to change { ticket.history_get.find { |elem| elem.fetch('type') == 'merged_into' }['value_to'] }
|
2020-08-03 11:36:53 +00:00
|
|
|
|
.to("##{target_ticket.number} #{target_ticket.title}")
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-02-13 09:09:20 +00:00
|
|
|
|
end
|
2017-05-05 09:16:47 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
describe '#perform_changes' do
|
2020-09-30 12:28:07 +00:00
|
|
|
|
|
|
|
|
|
# a `performable` can be a Trigger or a Job
|
|
|
|
|
# we use DuckTyping and expect that a performable
|
|
|
|
|
# implements the following interface
|
|
|
|
|
let(:performable) { OpenStruct.new(id: 1, perform: perform) }
|
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
# Regression test for https://github.com/zammad/zammad/issues/2001
|
|
|
|
|
describe 'argument handling' do
|
|
|
|
|
let(:perform) do
|
|
|
|
|
{
|
|
|
|
|
'notification.email' => {
|
|
|
|
|
body: "Hello \#{ticket.customer.firstname} \#{ticket.customer.lastname},",
|
|
|
|
|
recipient: %w[article_last_sender ticket_owner ticket_customer ticket_agents],
|
|
|
|
|
subject: "Autoclose (\#{ticket.title})"
|
|
|
|
|
}
|
2018-05-15 10:18:14 +00:00
|
|
|
|
}
|
2019-02-10 12:24:22 +00:00
|
|
|
|
end
|
2018-05-15 10:18:14 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
it 'does not mutate contents of "perform" hash' do
|
2020-09-30 12:28:07 +00:00
|
|
|
|
expect { ticket.perform_changes(performable, 'trigger', {}, 1) }
|
2019-02-10 12:24:22 +00:00
|
|
|
|
.not_to change { perform }
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-05-15 10:18:14 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
context 'with "ticket.state_id" key in "perform" hash' do
|
|
|
|
|
let(:perform) do
|
|
|
|
|
{
|
|
|
|
|
'ticket.state_id' => {
|
|
|
|
|
'value' => Ticket::State.lookup(name: 'closed').id
|
|
|
|
|
}
|
2018-05-23 10:25:11 +00:00
|
|
|
|
}
|
2019-02-10 12:24:22 +00:00
|
|
|
|
end
|
2018-05-23 10:25:11 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
it 'changes #state to specified value' do
|
2020-09-30 12:28:07 +00:00
|
|
|
|
expect { ticket.perform_changes(performable, 'trigger', ticket, User.first) }
|
2019-02-10 12:24:22 +00:00
|
|
|
|
.to change { ticket.reload.state.name }.to('closed')
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-05-23 10:25:11 +00:00
|
|
|
|
|
2020-07-06 15:03:28 +00:00
|
|
|
|
# Test for backwards compatibility after PR https://github.com/zammad/zammad/pull/2862
|
|
|
|
|
context 'with "pending_time" => { "value": DATE } in "perform" hash' do
|
|
|
|
|
let(:perform) do
|
|
|
|
|
{
|
|
|
|
|
'ticket.state_id' => {
|
|
|
|
|
'value' => Ticket::State.lookup(name: 'pending reminder').id.to_s
|
|
|
|
|
},
|
|
|
|
|
'ticket.pending_time' => {
|
|
|
|
|
'value' => timestamp,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:timestamp) { Time.zone.now }
|
|
|
|
|
|
|
|
|
|
it 'changes pending date to given date' do
|
|
|
|
|
freeze_time do
|
2020-09-30 12:28:07 +00:00
|
|
|
|
expect { ticket.perform_changes(performable, 'trigger', ticket, User.first) }
|
2020-07-06 15:03:28 +00:00
|
|
|
|
.to change(ticket, :pending_time).to(be_within(1.minute).of(timestamp))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Test for PR https://github.com/zammad/zammad/pull/2862
|
|
|
|
|
context 'with "pending_time" => { "operator": "relative" } in "perform" hash' do
|
|
|
|
|
shared_examples 'verify' do
|
|
|
|
|
it 'verify relative pending time rule' do
|
|
|
|
|
freeze_time do
|
|
|
|
|
interval = relative_value.send(relative_range).from_now
|
|
|
|
|
|
2020-09-30 12:28:07 +00:00
|
|
|
|
expect { ticket.perform_changes(performable, 'trigger', ticket, User.first) }
|
2020-07-06 15:03:28 +00:00
|
|
|
|
.to change(ticket, :pending_time).to(be_within(1.minute).of(interval))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:perform) do
|
|
|
|
|
{
|
|
|
|
|
'ticket.state_id' => {
|
|
|
|
|
'value' => Ticket::State.lookup(name: 'pending reminder').id.to_s
|
|
|
|
|
},
|
|
|
|
|
'ticket.pending_time' => {
|
|
|
|
|
'operator' => 'relative',
|
|
|
|
|
'value' => relative_value,
|
|
|
|
|
'range' => relative_range_config
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:relative_range_config) { relative_range.to_s.singularize }
|
|
|
|
|
|
|
|
|
|
context 'and value in days' do
|
|
|
|
|
let(:relative_value) { 2 }
|
|
|
|
|
let(:relative_range) { :days }
|
|
|
|
|
|
|
|
|
|
include_examples 'verify'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'and value in minutes' do
|
|
|
|
|
let(:relative_value) { 60 }
|
|
|
|
|
let(:relative_range) { :minutes }
|
|
|
|
|
|
|
|
|
|
include_examples 'verify'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
context 'with "ticket.action" => { "value" => "delete" } in "perform" hash' do
|
|
|
|
|
let(:perform) do
|
|
|
|
|
{
|
|
|
|
|
'ticket.state_id' => { 'value' => Ticket::State.lookup(name: 'closed').id.to_s },
|
|
|
|
|
'ticket.action' => { 'value' => 'delete' },
|
|
|
|
|
}
|
|
|
|
|
end
|
2018-05-23 10:25:11 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
it 'performs a ticket deletion on a ticket' do
|
2020-09-30 12:28:07 +00:00
|
|
|
|
expect { ticket.perform_changes(performable, 'trigger', ticket, User.first) }
|
2019-04-15 01:41:17 +00:00
|
|
|
|
.to change(ticket, :destroyed?).to(true)
|
2019-02-10 12:24:22 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2018-05-23 10:25:11 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
context 'with a "notification.email" trigger' do
|
|
|
|
|
# Regression test for https://github.com/zammad/zammad/issues/1543
|
|
|
|
|
#
|
|
|
|
|
# If a new article fires an email notification trigger,
|
|
|
|
|
# and then another article is added to the same ticket
|
|
|
|
|
# before that trigger is performed,
|
|
|
|
|
# the email template's 'article' var should refer to the originating article,
|
|
|
|
|
# not the newest one.
|
|
|
|
|
#
|
|
|
|
|
# (This occurs whenever one action fires multiple email notification triggers.)
|
|
|
|
|
context 'when two articles are created before the trigger fires once (race condition)' do
|
|
|
|
|
let!(:article) { create(:ticket_article, ticket: ticket) }
|
|
|
|
|
let!(:new_article) { create(:ticket_article, ticket: ticket) }
|
|
|
|
|
|
|
|
|
|
let(:trigger) do
|
|
|
|
|
build(:trigger,
|
|
|
|
|
perform: {
|
|
|
|
|
'notification.email' => {
|
|
|
|
|
body: '',
|
|
|
|
|
recipient: 'ticket_customer',
|
|
|
|
|
subject: ''
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# required by Ticket#perform_changes for email notifications
|
|
|
|
|
before { article.ticket.group.update(email_address: create(:email_address)) }
|
|
|
|
|
|
|
|
|
|
it 'passes the first article to NotificationFactory::Mailer' do
|
|
|
|
|
expect(NotificationFactory::Mailer)
|
|
|
|
|
.to receive(:template)
|
|
|
|
|
.with(hash_including(objects: { ticket: ticket, article: article }))
|
|
|
|
|
.at_least(:once)
|
|
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
|
|
expect(NotificationFactory::Mailer)
|
|
|
|
|
.not_to receive(:template)
|
|
|
|
|
.with(hash_including(objects: { ticket: ticket, article: new_article }))
|
|
|
|
|
|
2020-09-30 12:28:07 +00:00
|
|
|
|
ticket.perform_changes(trigger, 'trigger', { article_id: article.id }, 1)
|
2019-02-10 12:24:22 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-02-18 10:28:44 +00:00
|
|
|
|
|
|
|
|
|
context 'with a notification trigger' do
|
|
|
|
|
# https://github.com/zammad/zammad/issues/2782
|
|
|
|
|
#
|
|
|
|
|
# Notification triggers should log notification as private or public
|
|
|
|
|
# according to given configuration
|
2020-06-19 09:17:18 +00:00
|
|
|
|
let(:user) { create(:admin, mobile: '+37061010000') }
|
2020-02-18 10:28:44 +00:00
|
|
|
|
|
|
|
|
|
before { ticket.group.users << user }
|
|
|
|
|
|
|
|
|
|
let(:perform) do
|
|
|
|
|
{
|
|
|
|
|
notification_key => {
|
|
|
|
|
body: 'Old programmers never die. They just branch to a new address.',
|
|
|
|
|
recipient: 'ticket_agents',
|
|
|
|
|
subject: 'Old programmers never die. They just branch to a new address.'
|
|
|
|
|
}
|
|
|
|
|
}.deep_merge(additional_options).deep_stringify_keys
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:notification_key) { "notification.#{notification_type}" }
|
|
|
|
|
|
|
|
|
|
shared_examples 'verify log visibility status' do
|
|
|
|
|
shared_examples 'notification trigger' do
|
|
|
|
|
it 'adds Ticket::Article' do
|
2020-09-30 12:28:07 +00:00
|
|
|
|
expect { ticket.perform_changes(performable, 'trigger', ticket, user) }
|
2020-02-18 10:28:44 +00:00
|
|
|
|
.to change { ticket.articles.count }.by(1)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'new Ticket::Article visibility reflects setting' do
|
2020-09-30 12:28:07 +00:00
|
|
|
|
ticket.perform_changes(performable, 'trigger', ticket, User.first)
|
2020-02-18 10:28:44 +00:00
|
|
|
|
new_article = ticket.articles.reload.last
|
|
|
|
|
expect(new_article.internal).to be target_internal_value
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when set to private' do
|
|
|
|
|
let(:additional_options) do
|
|
|
|
|
{
|
|
|
|
|
notification_key => {
|
|
|
|
|
internal: true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:target_internal_value) { true }
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'notification trigger'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when set to internal' do
|
|
|
|
|
let(:additional_options) do
|
|
|
|
|
{
|
|
|
|
|
notification_key => {
|
|
|
|
|
internal: false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:target_internal_value) { false }
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'notification trigger'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when no selection was made' do # ensure previously created triggers default to public
|
|
|
|
|
let(:additional_options) do
|
|
|
|
|
{}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:target_internal_value) { false }
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'notification trigger'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'dispatching email' do
|
|
|
|
|
let(:notification_type) { :email }
|
|
|
|
|
|
|
|
|
|
include_examples 'verify log visibility status'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'dispatching SMS' do
|
|
|
|
|
let(:notification_type) { :sms }
|
|
|
|
|
|
|
|
|
|
before { create(:channel, area: 'Sms::Notification') }
|
|
|
|
|
|
|
|
|
|
include_examples 'verify log visibility status'
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-05-23 10:25:11 +00:00
|
|
|
|
end
|
2017-05-05 09:16:47 +00:00
|
|
|
|
|
2019-05-13 09:29:49 +00:00
|
|
|
|
describe '#subject_build' do
|
|
|
|
|
context 'with default "ticket_hook_position" setting ("right")' do
|
|
|
|
|
it 'returns the given string followed by a ticket reference (of the form "[Ticket#123]")' do
|
|
|
|
|
expect(ticket.subject_build('foo'))
|
|
|
|
|
.to eq("foo [Ticket##{ticket.number}]")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'and a non-default value for the "ticket_hook" setting' do
|
|
|
|
|
before { Setting.set('ticket_hook', 'bar baz') }
|
|
|
|
|
|
|
|
|
|
it 'replaces "Ticket#" with the new ticket hook' do
|
|
|
|
|
expect(ticket.subject_build('foo'))
|
|
|
|
|
.to eq("foo [bar baz#{ticket.number}]")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'and a non-default value for the "ticket_hook_divider" setting' do
|
|
|
|
|
before { Setting.set('ticket_hook_divider', ': ') }
|
|
|
|
|
|
|
|
|
|
it 'inserts the new ticket hook divider between "Ticket#" and the ticket number' do
|
|
|
|
|
expect(ticket.subject_build('foo'))
|
|
|
|
|
.to eq("foo [Ticket#: #{ticket.number}]")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the given string already contains a ticket reference, but in the wrong place' do
|
|
|
|
|
it 'moves the ticket reference to the end' do
|
|
|
|
|
expect(ticket.subject_build("[Ticket##{ticket.number}] foo"))
|
|
|
|
|
.to eq("foo [Ticket##{ticket.number}]")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the given string already contains an alternately formatted ticket reference' do
|
|
|
|
|
it 'reformats the ticket reference' do
|
|
|
|
|
expect(ticket.subject_build("foo [Ticket#: #{ticket.number}]"))
|
|
|
|
|
.to eq("foo [Ticket##{ticket.number}]")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with alternate "ticket_hook_position" setting ("left")' do
|
|
|
|
|
before { Setting.set('ticket_hook_position', 'left') }
|
|
|
|
|
|
|
|
|
|
it 'returns a ticket reference (of the form "[Ticket#123]") followed by the given string' do
|
|
|
|
|
expect(ticket.subject_build('foo'))
|
|
|
|
|
.to eq("[Ticket##{ticket.number}] foo")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'and a non-default value for the "ticket_hook" setting' do
|
|
|
|
|
before { Setting.set('ticket_hook', 'bar baz') }
|
|
|
|
|
|
|
|
|
|
it 'replaces "Ticket#" with the new ticket hook' do
|
|
|
|
|
expect(ticket.subject_build('foo'))
|
|
|
|
|
.to eq("[bar baz#{ticket.number}] foo")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'and a non-default value for the "ticket_hook_divider" setting' do
|
|
|
|
|
before { Setting.set('ticket_hook_divider', ': ') }
|
|
|
|
|
|
|
|
|
|
it 'inserts the new ticket hook divider between "Ticket#" and the ticket number' do
|
|
|
|
|
expect(ticket.subject_build('foo'))
|
|
|
|
|
.to eq("[Ticket#: #{ticket.number}] foo")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the given string already contains a ticket reference, but in the wrong place' do
|
|
|
|
|
it 'moves the ticket reference to the start' do
|
|
|
|
|
expect(ticket.subject_build("foo [Ticket##{ticket.number}]"))
|
|
|
|
|
.to eq("[Ticket##{ticket.number}] foo")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the given string already contains an alternately formatted ticket reference' do
|
|
|
|
|
it 'reformats the ticket reference' do
|
|
|
|
|
expect(ticket.subject_build("[Ticket#: #{ticket.number}] foo"))
|
|
|
|
|
.to eq("[Ticket##{ticket.number}] foo")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-02-09 15:46:55 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
describe 'Attributes:' do
|
2019-04-04 12:54:41 +00:00
|
|
|
|
describe '#owner' do
|
2020-06-19 09:17:18 +00:00
|
|
|
|
let(:original_owner) { create(:agent, groups: [ticket.group]) }
|
2019-05-13 09:29:49 +00:00
|
|
|
|
|
2019-04-04 12:54:41 +00:00
|
|
|
|
before { ticket.update(owner: original_owner) }
|
|
|
|
|
|
|
|
|
|
context 'when assigned directly' do
|
|
|
|
|
context 'to an active agent belonging to ticket.group' do
|
2020-06-19 09:17:18 +00:00
|
|
|
|
let(:agent) { create(:agent, groups: [ticket.group]) }
|
2019-04-04 12:54:41 +00:00
|
|
|
|
|
|
|
|
|
it 'can be set' do
|
|
|
|
|
expect { ticket.update(owner: agent) }
|
|
|
|
|
.to change { ticket.reload.owner }.to(agent)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'to an agent not belonging to ticket.group' do
|
2020-06-19 09:17:18 +00:00
|
|
|
|
let(:agent) { create(:agent, groups: [other_group]) }
|
2019-04-04 12:54:41 +00:00
|
|
|
|
let(:other_group) { create(:group) }
|
|
|
|
|
|
|
|
|
|
it 'resets to default user (id: 1) instead' do
|
|
|
|
|
expect { ticket.update(owner: agent) }
|
|
|
|
|
.to change { ticket.reload.owner }.to(User.first)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'to an inactive agent' do
|
2020-06-19 09:17:18 +00:00
|
|
|
|
let(:agent) { create(:agent, groups: [ticket.group], active: false) }
|
2019-04-04 12:54:41 +00:00
|
|
|
|
|
|
|
|
|
it 'resets to default user (id: 1) instead' do
|
|
|
|
|
expect { ticket.update(owner: agent) }
|
|
|
|
|
.to change { ticket.reload.owner }.to(User.first)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'to a non-agent' do
|
2020-06-19 09:17:18 +00:00
|
|
|
|
let(:agent) { create(:customer, groups: [ticket.group]) }
|
2019-04-04 12:54:41 +00:00
|
|
|
|
|
|
|
|
|
it 'resets to default user (id: 1) instead' do
|
|
|
|
|
expect { ticket.update(owner: agent) }
|
|
|
|
|
.to change { ticket.reload.owner }.to(User.first)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the ticket is updated for any other reason' do
|
|
|
|
|
context 'if original owner is still an active agent belonging to ticket.group' do
|
|
|
|
|
it 'does not change' do
|
|
|
|
|
expect { create(:ticket_article, ticket: ticket) }
|
|
|
|
|
.not_to change { ticket.reload.owner }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'if original owner has left ticket.group' do
|
|
|
|
|
before { original_owner.groups = [] }
|
|
|
|
|
|
|
|
|
|
it 'resets to default user (id: 1)' do
|
|
|
|
|
expect { create(:ticket_article, ticket: ticket) }
|
|
|
|
|
.to change { ticket.reload.owner }.to(User.first)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'if original owner has become inactive' do
|
|
|
|
|
before { original_owner.update(active: false) }
|
|
|
|
|
|
|
|
|
|
it 'resets to default user (id: 1)' do
|
|
|
|
|
expect { create(:ticket_article, ticket: ticket) }
|
|
|
|
|
.to change { ticket.reload.owner }.to(User.first)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'if original owner has lost agent status' do
|
|
|
|
|
before { original_owner.roles = [create(:role)] }
|
|
|
|
|
|
|
|
|
|
it 'resets to default user (id: 1)' do
|
|
|
|
|
expect { create(:ticket_article, ticket: ticket) }
|
|
|
|
|
.to change { ticket.reload.owner }.to(User.first)
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-07-31 12:25:02 +00:00
|
|
|
|
|
|
|
|
|
context 'when the Ticket is closed' do
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
ticket.update!(state: Ticket::State.lookup(name: 'closed'))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'if original owner is still an active agent belonging to ticket.group' do
|
|
|
|
|
it 'does not change' do
|
|
|
|
|
expect { create(:ticket_article, ticket: ticket) }
|
|
|
|
|
.not_to change { ticket.reload.owner }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'if original owner has left ticket.group' do
|
|
|
|
|
before { original_owner.groups = [] }
|
|
|
|
|
|
|
|
|
|
it 'does not change' do
|
|
|
|
|
expect { create(:ticket_article, ticket: ticket) }
|
|
|
|
|
.not_to change { ticket.reload.owner }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'if original owner has become inactive' do
|
|
|
|
|
before { original_owner.update(active: false) }
|
|
|
|
|
|
|
|
|
|
it 'does not change' do
|
|
|
|
|
expect { create(:ticket_article, ticket: ticket) }
|
|
|
|
|
.not_to change { ticket.reload.owner }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'if original owner has lost agent status' do
|
|
|
|
|
before { original_owner.roles = [create(:role)] }
|
|
|
|
|
|
|
|
|
|
it 'does not change' do
|
|
|
|
|
expect { create(:ticket_article, ticket: ticket) }
|
|
|
|
|
.not_to change { ticket.reload.owner }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-04-04 12:54:41 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-03-11 07:28:18 +00:00
|
|
|
|
describe '#state' do
|
2019-05-06 06:06:30 +00:00
|
|
|
|
context 'when originally "new" (default)' do
|
|
|
|
|
context 'and a customer article is added' do
|
|
|
|
|
let(:article) { create(:ticket_article, ticket: ticket, sender_name: 'Customer') }
|
|
|
|
|
|
|
|
|
|
it 'stays "new"' do
|
|
|
|
|
expect { article }
|
|
|
|
|
.not_to change { ticket.state.name }.from('new')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-03-18 10:35:35 +00:00
|
|
|
|
context 'and a non-customer article is added' do
|
2019-03-11 07:28:18 +00:00
|
|
|
|
let(:article) { create(:ticket_article, ticket: ticket, sender_name: 'Agent') }
|
|
|
|
|
|
|
|
|
|
it 'switches to "open"' do
|
2019-05-06 06:06:30 +00:00
|
|
|
|
expect { article }
|
2019-09-18 12:20:25 +00:00
|
|
|
|
.to change { ticket.reload.state.name }.from('new').to('open')
|
2019-03-11 07:28:18 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-03-18 10:35:35 +00:00
|
|
|
|
|
|
|
|
|
context 'when originally "closed"' do
|
|
|
|
|
before { ticket.update(state: Ticket::State.find_by(name: 'closed')) }
|
|
|
|
|
|
|
|
|
|
context 'when a non-customer article is added' do
|
|
|
|
|
let(:article) { create(:ticket_article, ticket: ticket, sender_name: 'Agent') }
|
|
|
|
|
|
|
|
|
|
it 'stays "closed"' do
|
2019-09-18 12:20:25 +00:00
|
|
|
|
expect { article }.not_to change { ticket.reload.state.name }
|
2019-03-18 10:35:35 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-03-11 07:28:18 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
describe '#pending_time' do
|
|
|
|
|
subject(:ticket) { create(:ticket, pending_time: Time.zone.now + 2.days) }
|
2017-06-28 08:25:25 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
context 'when #state is updated to any non-"pending" value' do
|
|
|
|
|
it 'is reset to nil' do
|
|
|
|
|
expect { ticket.update!(state: Ticket::State.lookup(name: 'open')) }
|
2019-04-15 01:41:17 +00:00
|
|
|
|
.to change(ticket, :pending_time).to(nil)
|
2019-02-10 12:24:22 +00:00
|
|
|
|
end
|
2017-06-28 08:25:25 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
# Regression test for commit 92f227786f298bad1ccaf92d4478a7062ea6a49f
|
|
|
|
|
context 'when #state is updated to nil (violating DB NOT NULL constraint)' do
|
|
|
|
|
it 'does not prematurely raise within the callback (#reset_pending_time)' do
|
|
|
|
|
expect { ticket.update!(state: nil) }
|
|
|
|
|
.to raise_error(ActiveRecord::StatementInvalid)
|
|
|
|
|
end
|
2017-06-28 08:25:25 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2019-04-08 13:50:21 +00:00
|
|
|
|
|
|
|
|
|
describe '#escalation_at' do
|
2020-06-22 09:57:45 +00:00
|
|
|
|
before { travel_to(Time.current) } # freeze time
|
2019-04-15 01:41:17 +00:00
|
|
|
|
|
2019-04-08 13:50:21 +00:00
|
|
|
|
let(:sla) { create(:sla, calendar: calendar, first_response_time: 60, update_time: 180, solution_time: 240) }
|
|
|
|
|
let(:calendar) { create(:calendar, :'24/7') }
|
|
|
|
|
|
|
|
|
|
context 'with no SLAs in the system' do
|
|
|
|
|
it 'defaults to nil' do
|
|
|
|
|
expect(ticket.escalation_at).to be(nil)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with an SLA in the system' do
|
2020-06-22 09:57:45 +00:00
|
|
|
|
before { sla } # create sla
|
2019-04-08 13:50:21 +00:00
|
|
|
|
|
|
|
|
|
it 'is set based on SLA’s #first_response_time' do
|
2019-09-18 12:20:25 +00:00
|
|
|
|
expect(ticket.reload.escalation_at.to_i)
|
2019-04-08 13:50:21 +00:00
|
|
|
|
.to eq(1.hour.from_now.to_i)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'after first agent’s response' do
|
2020-06-22 09:57:45 +00:00
|
|
|
|
before { ticket } # create ticket
|
2019-04-15 01:41:17 +00:00
|
|
|
|
|
2019-04-08 13:50:21 +00:00
|
|
|
|
let(:article) { create(:ticket_article, ticket: ticket, sender_name: 'Agent') }
|
|
|
|
|
|
|
|
|
|
it 'is updated based on the SLA’s #update_time' do
|
2020-06-22 09:57:45 +00:00
|
|
|
|
travel(1.minute) # time is frozen: if we don't travel forward, pre- and post-update values will be the same
|
2019-04-08 13:50:21 +00:00
|
|
|
|
|
|
|
|
|
expect { article }
|
|
|
|
|
.to change { ticket.reload.escalation_at.to_i }
|
|
|
|
|
.to eq(3.hours.from_now.to_i)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when new #update_time is later than original #solution_time' do
|
|
|
|
|
it 'is updated based on the original #solution_time' do
|
2020-06-22 09:57:45 +00:00
|
|
|
|
travel(2.hours) # time is frozen: if we don't travel forward, pre- and post-update values will be the same
|
2019-04-08 13:50:21 +00:00
|
|
|
|
|
|
|
|
|
expect { article }
|
|
|
|
|
.to change { ticket.reload.escalation_at.to_i }
|
|
|
|
|
.to eq(4.hours.after(ticket.created_at).to_i)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when updated after an SLA has been added to the system' do
|
2019-04-15 01:41:17 +00:00
|
|
|
|
before do
|
|
|
|
|
ticket # create ticket
|
|
|
|
|
sla # create sla
|
|
|
|
|
end
|
2019-04-08 13:50:21 +00:00
|
|
|
|
|
|
|
|
|
it 'is updated based on the new SLA’s #first_response_time' do
|
|
|
|
|
expect { ticket.save! }
|
2019-09-18 12:20:25 +00:00
|
|
|
|
.to change { ticket.reload.escalation_at.to_i }.from(0).to(1.hour.from_now.to_i)
|
2019-04-08 13:50:21 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when updated after all SLAs have been removed from the system' do
|
2019-04-15 01:41:17 +00:00
|
|
|
|
before do
|
|
|
|
|
sla # create sla
|
|
|
|
|
ticket # create ticket
|
|
|
|
|
sla.destroy
|
|
|
|
|
end
|
2019-04-08 13:50:21 +00:00
|
|
|
|
|
|
|
|
|
it 'is set to nil' do
|
|
|
|
|
expect { ticket.save! }
|
2019-09-18 12:20:25 +00:00
|
|
|
|
.to change { ticket.reload.escalation_at }.to(nil)
|
2019-04-08 13:50:21 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '#first_response_escalation_at' do
|
2020-06-22 09:57:45 +00:00
|
|
|
|
before { travel_to(Time.current) } # freeze time
|
2019-04-15 01:41:17 +00:00
|
|
|
|
|
2019-04-08 13:50:21 +00:00
|
|
|
|
let(:sla) { create(:sla, calendar: calendar, first_response_time: 60, update_time: 180, solution_time: 240) }
|
|
|
|
|
let(:calendar) { create(:calendar, :'24/7') }
|
|
|
|
|
|
|
|
|
|
context 'with no SLAs in the system' do
|
|
|
|
|
it 'defaults to nil' do
|
|
|
|
|
expect(ticket.first_response_escalation_at).to be(nil)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with an SLA in the system' do
|
2020-06-22 09:57:45 +00:00
|
|
|
|
before { sla } # create sla
|
2019-04-08 13:50:21 +00:00
|
|
|
|
|
|
|
|
|
it 'is set based on SLA’s #first_response_time' do
|
2019-09-18 12:20:25 +00:00
|
|
|
|
expect(ticket.reload.first_response_escalation_at.to_i)
|
2019-04-08 13:50:21 +00:00
|
|
|
|
.to eq(1.hour.from_now.to_i)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'after first agent’s response' do
|
2020-06-22 09:57:45 +00:00
|
|
|
|
before { ticket } # create ticket
|
2019-04-15 01:41:17 +00:00
|
|
|
|
|
2019-04-08 13:50:21 +00:00
|
|
|
|
let(:article) { create(:ticket_article, ticket: ticket, sender_name: 'Agent') }
|
|
|
|
|
|
|
|
|
|
it 'does not change' do
|
2019-04-15 01:41:17 +00:00
|
|
|
|
expect { article }.not_to change(ticket, :first_response_escalation_at)
|
2019-04-08 13:50:21 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '#update_escalation_at' do
|
2020-06-22 09:57:45 +00:00
|
|
|
|
before { travel_to(Time.current) } # freeze time
|
2019-04-15 01:41:17 +00:00
|
|
|
|
|
2019-04-08 13:50:21 +00:00
|
|
|
|
let(:sla) { create(:sla, calendar: calendar, first_response_time: 60, update_time: 180, solution_time: 240) }
|
|
|
|
|
let(:calendar) { create(:calendar, :'24/7') }
|
|
|
|
|
|
|
|
|
|
context 'with no SLAs in the system' do
|
|
|
|
|
it 'defaults to nil' do
|
|
|
|
|
expect(ticket.update_escalation_at).to be(nil)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with an SLA in the system' do
|
2020-06-22 09:57:45 +00:00
|
|
|
|
before { sla } # create sla
|
2019-04-08 13:50:21 +00:00
|
|
|
|
|
|
|
|
|
it 'is set based on SLA’s #update_time' do
|
2019-09-18 12:20:25 +00:00
|
|
|
|
expect(ticket.reload.update_escalation_at.to_i)
|
2019-04-08 13:50:21 +00:00
|
|
|
|
.to eq(3.hours.from_now.to_i)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'after first agent’s response' do
|
2020-06-22 09:57:45 +00:00
|
|
|
|
before { ticket } # create ticket
|
2019-04-15 01:41:17 +00:00
|
|
|
|
|
2019-04-08 13:50:21 +00:00
|
|
|
|
let(:article) { create(:ticket_article, ticket: ticket, sender_name: 'Agent') }
|
|
|
|
|
|
|
|
|
|
it 'is updated based on the SLA’s #update_time' do
|
2020-06-22 09:57:45 +00:00
|
|
|
|
travel(1.minute) # time is frozen: if we don't travel forward, pre- and post-update values will be the same
|
2019-04-08 13:50:21 +00:00
|
|
|
|
|
|
|
|
|
expect { article }
|
|
|
|
|
.to change { ticket.reload.update_escalation_at.to_i }
|
|
|
|
|
.to(3.hours.from_now.to_i)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '#close_escalation_at' do
|
2020-06-22 09:57:45 +00:00
|
|
|
|
before { travel_to(Time.current) } # freeze time
|
2019-04-15 01:41:17 +00:00
|
|
|
|
|
2019-04-08 13:50:21 +00:00
|
|
|
|
let(:sla) { create(:sla, calendar: calendar, first_response_time: 60, update_time: 180, solution_time: 240) }
|
|
|
|
|
let(:calendar) { create(:calendar, :'24/7') }
|
|
|
|
|
|
|
|
|
|
context 'with no SLAs in the system' do
|
|
|
|
|
it 'defaults to nil' do
|
|
|
|
|
expect(ticket.close_escalation_at).to be(nil)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with an SLA in the system' do
|
2020-06-22 09:57:45 +00:00
|
|
|
|
before { sla } # create sla
|
2019-04-08 13:50:21 +00:00
|
|
|
|
|
|
|
|
|
it 'is set based on SLA’s #solution_time' do
|
2019-09-18 12:20:25 +00:00
|
|
|
|
expect(ticket.reload.close_escalation_at.to_i)
|
2019-04-08 13:50:21 +00:00
|
|
|
|
.to eq(4.hours.from_now.to_i)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'after first agent’s response' do
|
2020-06-22 09:57:45 +00:00
|
|
|
|
before { ticket } # create ticket
|
2019-04-15 01:41:17 +00:00
|
|
|
|
|
2019-04-08 13:50:21 +00:00
|
|
|
|
let(:article) { create(:ticket_article, ticket: ticket, sender_name: 'Agent') }
|
|
|
|
|
|
|
|
|
|
it 'does not change' do
|
2019-04-15 01:41:17 +00:00
|
|
|
|
expect { article }.not_to change(ticket, :close_escalation_at)
|
2019-04-08 13:50:21 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-06-28 08:25:25 +00:00
|
|
|
|
end
|
2018-03-08 12:30:30 +00:00
|
|
|
|
|
2019-02-13 04:19:33 +00:00
|
|
|
|
describe 'Associations:' do
|
|
|
|
|
describe '#organization' do
|
|
|
|
|
subject(:ticket) { build(:ticket, customer: customer, organization: nil) }
|
2019-04-15 01:41:17 +00:00
|
|
|
|
|
2019-02-13 04:19:33 +00:00
|
|
|
|
let(:customer) { create(:customer, :with_org) }
|
|
|
|
|
|
|
|
|
|
context 'on creation' do
|
|
|
|
|
it 'automatically adopts the organization of its #customer' do
|
|
|
|
|
expect { ticket.save }
|
2019-04-15 01:41:17 +00:00
|
|
|
|
.to change(ticket, :organization).to(customer.organization)
|
2019-02-13 04:19:33 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'on update of #customer.organization' do
|
|
|
|
|
context 'to nil' do
|
|
|
|
|
it 'automatically updates to #customer’s new value' do
|
|
|
|
|
ticket.save
|
|
|
|
|
|
|
|
|
|
expect { customer.update(organization: nil) }
|
|
|
|
|
.to change { ticket.reload.organization }.to(nil)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'to a different organization' do
|
|
|
|
|
let(:new_org) { create(:organization) }
|
|
|
|
|
|
|
|
|
|
it 'automatically updates to #customer’s new value' do
|
|
|
|
|
ticket.save
|
|
|
|
|
|
|
|
|
|
expect { customer.update(organization: new_org) }
|
|
|
|
|
.to change { ticket.reload.organization }.to(new_org)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-08-20 07:10:08 +00:00
|
|
|
|
describe '.search' do
|
|
|
|
|
|
|
|
|
|
shared_examples 'search permissions' do
|
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
ticket
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
shared_examples 'permitted' do
|
|
|
|
|
it 'finds Ticket' do
|
|
|
|
|
expect( described_class.search(query: ticket.number, current_user: current_user).count ).to eq(1)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
shared_examples 'no permission' do
|
|
|
|
|
it "doesn't find Ticket" do
|
|
|
|
|
expect( described_class.search(query: ticket.number, current_user: current_user) ).to be_blank
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'Agent with Group access' do
|
|
|
|
|
|
|
|
|
|
let(:ticket) do
|
|
|
|
|
ticket = create(:ticket, group: group)
|
|
|
|
|
create(:ticket_article, ticket: ticket)
|
|
|
|
|
ticket
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:current_user) { create(:agent, groups: [group]) }
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'permitted'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when Agent is Customer of Ticket' do
|
|
|
|
|
|
|
|
|
|
let(:ticket) do
|
|
|
|
|
ticket = create(:ticket, customer: current_user)
|
|
|
|
|
create(:ticket_article, ticket: ticket)
|
|
|
|
|
ticket
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:current_user) { create(:agent_and_customer) }
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'permitted'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'for Organization access' do
|
|
|
|
|
|
|
|
|
|
let(:ticket) do
|
|
|
|
|
ticket = create(:ticket, customer: customer)
|
|
|
|
|
create(:ticket_article, ticket: ticket)
|
|
|
|
|
ticket
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:customer) { create(:customer, organization: organization) }
|
|
|
|
|
|
|
|
|
|
context 'when Organization is shared' do
|
|
|
|
|
let(:organization) { create(:organization, shared: true) }
|
|
|
|
|
|
|
|
|
|
context 'for unrelated Agent' do
|
|
|
|
|
let(:current_user) { create(:agent) }
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'no permission'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'for Agent in same Organization' do
|
|
|
|
|
let(:current_user) { create(:agent_and_customer, organization: organization) }
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'permitted'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'for Customer of Ticket' do
|
|
|
|
|
let(:current_user) { customer }
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'permitted'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when Organization is not shared' do
|
|
|
|
|
let(:organization) { create(:organization, shared: false) }
|
|
|
|
|
|
|
|
|
|
context 'for unrelated Agent' do
|
|
|
|
|
let(:current_user) { create(:agent) }
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'no permission'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'for Agent in same Organization' do
|
|
|
|
|
let(:current_user) { create(:agent_and_customer, organization: organization) }
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'no permission'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'for Customer of Ticket' do
|
|
|
|
|
let(:current_user) { customer }
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'permitted'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with searchindex', searchindex: true do
|
|
|
|
|
|
|
|
|
|
include_examples 'search permissions' do
|
|
|
|
|
before do
|
|
|
|
|
configure_elasticsearch(required: true, rebuild: true)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'without searchindex' do
|
|
|
|
|
include_examples 'search permissions'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
describe 'Callbacks & Observers -' do
|
|
|
|
|
describe 'NULL byte handling (via ChecksAttributeValuesAndLength concern):' do
|
|
|
|
|
it 'removes them from title on creation, if necessary (postgres doesn’t like them)' do
|
|
|
|
|
expect { create(:ticket, title: "some title \u0000 123") }
|
|
|
|
|
.not_to raise_error
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-03-08 12:30:30 +00:00
|
|
|
|
|
2019-04-17 06:18:02 +00:00
|
|
|
|
describe 'XSS protection:' do
|
|
|
|
|
subject(:ticket) { create(:ticket, title: title) }
|
|
|
|
|
|
|
|
|
|
let(:title) { 'test 123 <script type="text/javascript">alert("XSS!");</script>' }
|
|
|
|
|
|
|
|
|
|
it 'does not sanitize title' do
|
|
|
|
|
expect(ticket.title).to eq(title)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-02-05 07:33:40 +00:00
|
|
|
|
describe 'Cti::CallerId syncing:' do
|
|
|
|
|
subject(:ticket) { build(:ticket) }
|
2019-04-15 01:41:17 +00:00
|
|
|
|
|
2019-02-05 07:33:40 +00:00
|
|
|
|
before { allow(Cti::CallerId).to receive(:build) }
|
|
|
|
|
|
|
|
|
|
it 'adds numbers in article bodies (via Cti::CallerId.build)' do
|
|
|
|
|
expect(Cti::CallerId).to receive(:build).with(ticket)
|
|
|
|
|
|
|
|
|
|
ticket.save
|
|
|
|
|
Observer::Transaction.commit
|
|
|
|
|
Scheduler.worker(true)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-04-08 05:48:19 +00:00
|
|
|
|
describe 'Touching associations on update:' do
|
|
|
|
|
subject(:ticket) { create(:ticket, customer: customer) }
|
2019-04-15 01:41:17 +00:00
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
|
let(:customer) { create(:customer, organization: organization) }
|
2019-04-08 05:48:19 +00:00
|
|
|
|
let(:organization) { create(:organization) }
|
2020-06-19 09:17:18 +00:00
|
|
|
|
let(:other_customer) { create(:customer, organization: other_organization) }
|
2019-04-08 05:48:19 +00:00
|
|
|
|
let(:other_organization) { create(:organization) }
|
|
|
|
|
|
|
|
|
|
context 'on creation' do
|
|
|
|
|
it 'touches its customer and his organization' do
|
|
|
|
|
expect { ticket }
|
|
|
|
|
.to change { customer.reload.updated_at }
|
|
|
|
|
.and change { organization.reload.updated_at }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'on destruction' do
|
|
|
|
|
before { ticket }
|
|
|
|
|
|
|
|
|
|
it 'touches its customer and his organization' do
|
|
|
|
|
expect { ticket.destroy }
|
|
|
|
|
.to change { customer.reload.updated_at }
|
|
|
|
|
.and change { organization.reload.updated_at }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when customer association is changed' do
|
|
|
|
|
it 'touches both old and new customer, and their organizations' do
|
|
|
|
|
expect { ticket.update(customer: other_customer) }
|
|
|
|
|
.to change { customer.reload.updated_at }
|
|
|
|
|
.and change { organization.reload.updated_at }
|
|
|
|
|
.and change { other_customer.reload.updated_at }
|
|
|
|
|
.and change { other_organization.reload.updated_at }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
describe 'Association & attachment management:' do
|
|
|
|
|
it 'deletes all related ActivityStreams on destroy' do
|
|
|
|
|
create_list(:activity_stream, 3, o: ticket)
|
2018-03-08 12:30:30 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
expect { ticket.destroy }
|
|
|
|
|
.to change { ActivityStream.exists?(activity_stream_object_id: ObjectLookup.by_name('Ticket'), o_id: ticket.id) }
|
|
|
|
|
.to(false)
|
|
|
|
|
end
|
2018-03-08 12:30:30 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
it 'deletes all related Links on destroy' do
|
|
|
|
|
create(:link, from: ticket, to: create(:ticket))
|
|
|
|
|
create(:link, from: create(:ticket), to: ticket)
|
|
|
|
|
create(:link, from: ticket, to: create(:ticket))
|
2018-03-08 12:30:30 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
expect { ticket.destroy }
|
|
|
|
|
.to change { Link.where('link_object_source_value = :id OR link_object_target_value = :id', id: ticket.id).any? }
|
|
|
|
|
.to(false)
|
2018-03-08 12:30:30 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
it 'deletes all related Articles on destroy' do
|
|
|
|
|
create_list(:ticket_article, 3, ticket: ticket)
|
2018-03-08 12:30:30 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
expect { ticket.destroy }
|
|
|
|
|
.to change { Ticket::Article.exists?(ticket: ticket) }
|
|
|
|
|
.to(false)
|
|
|
|
|
end
|
2018-03-08 12:30:30 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
it 'deletes all related OnlineNotifications on destroy' do
|
|
|
|
|
create_list(:online_notification, 3, o: ticket)
|
2018-03-08 12:30:30 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
expect { ticket.destroy }
|
|
|
|
|
.to change { OnlineNotification.where(object_lookup_id: ObjectLookup.by_name('Ticket'), o_id: ticket.id).any? }
|
|
|
|
|
.to(false)
|
2018-03-08 12:30:30 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
it 'deletes all related Tags on destroy' do
|
|
|
|
|
create_list(:tag, 3, o: ticket)
|
2018-03-08 12:30:30 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
expect { ticket.destroy }
|
|
|
|
|
.to change { Tag.exists?(tag_object_id: Tag::Object.lookup(name: 'Ticket').id, o_id: ticket.id) }
|
|
|
|
|
.to(false)
|
2018-03-08 12:30:30 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
it 'deletes all related Histories on destroy' do
|
|
|
|
|
create_list(:history, 3, o: ticket)
|
2018-03-08 12:30:30 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
expect { ticket.destroy }
|
|
|
|
|
.to change { History.exists?(history_object_id: History::Object.lookup(name: 'Ticket').id, o_id: ticket.id) }
|
|
|
|
|
.to(false)
|
|
|
|
|
end
|
2018-03-08 12:30:30 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
it 'deletes all related Karma::ActivityLogs on destroy' do
|
|
|
|
|
create_list(:'karma/activity_log', 3, o: ticket)
|
2018-03-08 12:30:30 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
expect { ticket.destroy }
|
|
|
|
|
.to change { Karma::ActivityLog.exists?(object_lookup_id: ObjectLookup.by_name('Ticket'), o_id: ticket.id) }
|
|
|
|
|
.to(false)
|
2018-03-08 12:30:30 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
it 'deletes all related RecentViews on destroy' do
|
|
|
|
|
create_list(:recent_view, 3, o: ticket)
|
2018-03-08 12:30:30 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
expect { ticket.destroy }
|
|
|
|
|
.to change { RecentView.exists?(recent_view_object_id: ObjectLookup.by_name('Ticket'), o_id: ticket.id) }
|
|
|
|
|
.to(false)
|
|
|
|
|
end
|
2018-03-08 12:30:30 +00:00
|
|
|
|
|
2020-09-08 15:06:23 +00:00
|
|
|
|
it 'destroys all related dependencies' do
|
|
|
|
|
refs_known = { 'Ticket::Article' => { 'ticket_id'=>1 },
|
|
|
|
|
'Ticket::TimeAccounting' => { 'ticket_id'=>1 },
|
|
|
|
|
'Ticket::Flag' => { 'ticket_id'=>1 } }
|
|
|
|
|
|
|
|
|
|
ticket = create(:ticket)
|
|
|
|
|
article = create(:ticket_article, ticket: ticket)
|
|
|
|
|
accounting = create(:ticket_time_accounting, ticket: ticket)
|
|
|
|
|
flag = create(:ticket_flag, ticket: ticket)
|
|
|
|
|
|
|
|
|
|
refs_ticket = Models.references('Ticket', ticket.id, true)
|
|
|
|
|
expect(refs_ticket).to eq(refs_known)
|
|
|
|
|
|
|
|
|
|
ticket.destroy
|
|
|
|
|
|
|
|
|
|
expect { ticket.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
|
|
|
|
expect { article.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
|
|
|
|
expect { accounting.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
|
|
|
|
expect { flag.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
|
|
|
|
end
|
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
context 'when ticket is generated from email (with attachments)' do
|
|
|
|
|
subject(:ticket) { Channel::EmailParser.new.process({}, raw_email).first }
|
2019-04-15 01:41:17 +00:00
|
|
|
|
|
2020-02-18 19:51:31 +00:00
|
|
|
|
let(:raw_email) { File.read(Rails.root.join('test/data/mail/mail001.box')) }
|
2018-03-08 12:30:30 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
it 'adds attachments to the Store{::File,::Provider::DB} tables' do
|
|
|
|
|
expect { ticket }
|
2019-04-15 01:41:17 +00:00
|
|
|
|
.to change(Store, :count).by(2)
|
2019-02-10 12:24:22 +00:00
|
|
|
|
.and change { Store::File.count }.by(2)
|
|
|
|
|
.and change { Store::Provider::DB.count }.by(2)
|
2018-03-08 12:30:30 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
context 'and subsequently destroyed' do
|
|
|
|
|
it 'deletes all related attachments' do
|
2020-06-22 09:57:45 +00:00
|
|
|
|
ticket # create ticket
|
2018-03-08 12:30:30 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
expect { ticket.destroy }
|
2019-04-15 01:41:17 +00:00
|
|
|
|
.to change(Store, :count).by(-2)
|
2019-02-10 12:24:22 +00:00
|
|
|
|
.and change { Store::File.count }.by(-2)
|
|
|
|
|
.and change { Store::Provider::DB.count }.by(-2)
|
|
|
|
|
end
|
2018-03-08 12:30:30 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
context 'and a duplicate ticket is generated from the same email' do
|
2020-06-22 09:57:45 +00:00
|
|
|
|
before { ticket } # create ticket
|
2019-04-15 01:41:17 +00:00
|
|
|
|
|
2019-02-10 12:24:22 +00:00
|
|
|
|
let(:duplicate) { Channel::EmailParser.new.process({}, raw_email).first }
|
|
|
|
|
|
|
|
|
|
it 'adds duplicate attachments to the Store table only' do
|
|
|
|
|
expect { duplicate }
|
2019-04-15 01:41:17 +00:00
|
|
|
|
.to change(Store, :count).by(2)
|
2019-02-10 12:24:22 +00:00
|
|
|
|
.and change { Store::File.count }.by(0)
|
|
|
|
|
.and change { Store::Provider::DB.count }.by(0)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when only the duplicate ticket is destroyed' do
|
|
|
|
|
it 'deletes only the duplicate attachments' do
|
2020-06-22 09:57:45 +00:00
|
|
|
|
duplicate # create ticket
|
2019-02-10 12:24:22 +00:00
|
|
|
|
|
|
|
|
|
expect { duplicate.destroy }
|
2019-04-15 01:41:17 +00:00
|
|
|
|
.to change(Store, :count).by(-2)
|
2019-02-10 12:24:22 +00:00
|
|
|
|
.and change { Store::File.count }.by(0)
|
|
|
|
|
.and change { Store::Provider::DB.count }.by(0)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'deletes all related attachments' do
|
|
|
|
|
duplicate.destroy
|
|
|
|
|
|
|
|
|
|
expect { ticket.destroy }
|
2019-04-15 01:41:17 +00:00
|
|
|
|
.to change(Store, :count).by(-2)
|
2019-02-10 12:24:22 +00:00
|
|
|
|
.and change { Store::File.count }.by(-2)
|
|
|
|
|
.and change { Store::Provider::DB.count }.by(-2)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-03-08 12:30:30 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2020-10-06 13:03:30 +00:00
|
|
|
|
|
|
|
|
|
describe 'Ticket lifecycle order-of-operations:' do
|
|
|
|
|
subject!(:ticket) { create(:ticket) }
|
|
|
|
|
|
|
|
|
|
let!(:agent) { create(:agent, groups: [group]) }
|
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
create(
|
|
|
|
|
:trigger,
|
|
|
|
|
condition: { 'ticket.action' => { 'operator' => 'is', 'value' => 'create' } },
|
|
|
|
|
perform: { 'ticket.group_id' => { 'value' => group.id } }
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'fires triggers before new ticket notifications are sent' do
|
|
|
|
|
expect { Observer::Transaction.commit }
|
|
|
|
|
.to change { ticket.reload.group }.to(group)
|
|
|
|
|
|
|
|
|
|
expect { Scheduler.worker(true) }
|
|
|
|
|
.to change { NotificationFactory::Mailer.already_sent?(ticket, agent, 'email') }.to(1)
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-03-08 12:30:30 +00:00
|
|
|
|
end
|
2017-05-02 11:37:20 +00:00
|
|
|
|
end
|