|
@@ -31,7 +31,77 @@ RSpec.describe Transaction::Notification, type: :model do
|
|
|
end
|
|
|
end
|
|
|
|
|
|
+ describe '#ooo_replacements' do
|
|
|
+ subject(:notification_instance) { build(ticket, user) }
|
|
|
+
|
|
|
+ let(:group) { create(:group) }
|
|
|
+ let(:user) { create(:agent, :ooo, :groupable, ooo_agent: replacement_1, group: group) }
|
|
|
+ let(:ticket) { create(:ticket, owner: user, group: group, state_name: 'open', pending_time: Time.current) }
|
|
|
+
|
|
|
+ context 'when replacement has access' do
|
|
|
+ let(:replacement_1) { create(:agent, :groupable, group: group) }
|
|
|
+
|
|
|
+ it 'is added to list' do
|
|
|
+ replacements = Set.new
|
|
|
+
|
|
|
+ ooo(notification_instance, user, replacements: replacements)
|
|
|
+
|
|
|
+ expect(replacements).to include replacement_1
|
|
|
+ end
|
|
|
+
|
|
|
+ context 'when replacement has replacement' do
|
|
|
+ let(:replacement_1) { create(:agent, :ooo, :groupable, ooo_agent: replacement_2, group: group) }
|
|
|
+ let(:replacement_2) { create(:agent, :groupable, group: group) }
|
|
|
+
|
|
|
+ it 'replacement\'s replacement added to list' do
|
|
|
+ replacements = Set.new
|
|
|
+
|
|
|
+ ooo(notification_instance, user, replacements: replacements)
|
|
|
+
|
|
|
+ expect(replacements).to include replacement_2
|
|
|
+ end
|
|
|
+
|
|
|
+ it 'intermediary replacement is not in list' do
|
|
|
+ replacements = Set.new
|
|
|
+
|
|
|
+ ooo(notification_instance, user, replacements: replacements)
|
|
|
+
|
|
|
+ expect(replacements).not_to include replacement_1
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ context 'when replacement does not have access' do
|
|
|
+ let(:replacement_1) { create(:agent) }
|
|
|
+
|
|
|
+ it 'is not added to list' do
|
|
|
+ replacements = Set.new
|
|
|
+
|
|
|
+ ooo(notification_instance, user, replacements: replacements)
|
|
|
+
|
|
|
+ expect(replacements).not_to include replacement_1
|
|
|
+ end
|
|
|
+
|
|
|
+ context 'when replacement has replacement with access' do
|
|
|
+ let(:replacement_1) { create(:agent, :ooo, ooo_agent: replacement_2) }
|
|
|
+ let(:replacement_2) { create(:agent, :groupable, group: group) }
|
|
|
+
|
|
|
+ it 'his replacement may be added' do
|
|
|
+ replacements = Set.new
|
|
|
+
|
|
|
+ ooo(notification_instance, user, replacements: replacements)
|
|
|
+
|
|
|
+ expect(replacements).to include replacement_2
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
def run(ticket, user, type)
|
|
|
+ build(ticket, user, type).perform
|
|
|
+ end
|
|
|
+
|
|
|
+ def build(ticket, user, type = 'reminder_reached')
|
|
|
described_class.new(
|
|
|
object: ticket.class.name,
|
|
|
type: type,
|
|
@@ -40,6 +110,10 @@ RSpec.describe Transaction::Notification, type: :model do
|
|
|
changes: nil,
|
|
|
created_at: Time.current,
|
|
|
user_id: user.id
|
|
|
- ).perform
|
|
|
+ )
|
|
|
+ end
|
|
|
+
|
|
|
+ def ooo(instance, user, replacements: Set.new, reasons: [])
|
|
|
+ instance.send(:ooo_replacements, user: user, replacements: replacements, ticket: ticket, reasons: reasons)
|
|
|
end
|
|
|
end
|