forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack_spec.rb
118 lines (83 loc) · 3.44 KB
/
slack_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
require 'rails_helper'
require 'slack-ruby-client' # Only load this gem when it is really used.
RSpec.describe 'Slack Integration', integration: true, performs_jobs: true, required_envs: %w[SLACK_CI_CHANNEL_NAME SLACK_CI_OAUTH_TOKEN SLACK_CI_WEBHOOK_URL], time_zone: 'Europe/London', use_vcr: true do # rubocop:disable RSpec/DescribeClass
let(:slack_group) { create(:group) }
let(:types) { %w[create update reminder_reached] }
let(:items) do
[
{
group_ids: [slack_group.id],
types: types,
webhook: ENV['SLACK_CI_WEBHOOK_URL'],
channel: ENV['SLACK_CI_CHANNEL_NAME'],
username: 'zammad_agent',
expand: false,
}
]
end
let(:group) { slack_group }
let(:customer) { create(:customer) }
let(:state_name) { 'new' }
let(:ticket) { create(:ticket, customer: customer, group: group, title: message, state_name: state_name) }
let(:article) { create(:ticket_article, :outbound_note, ticket: ticket, body: message, sender_name: 'Customer', from: customer.fullname) }
before :all do # rubocop:disable RSpec/BeforeAfterAll
delete_all_test_chat_messages if live_mode?
end
before do
Setting.set('slack_integration', true)
Setting.set('slack_config', { items: items })
ticket && article
perform_enqueued_jobs commit_transaction: true
end
context 'with default group' do
let(:message) { 'foo' }
let(:group) { Group.first }
it 'publishes no ticket updates', :aggregate_failures do
expect(message).to have_message_count(0)
ticket.update!(state: Ticket::State.find_by(name: 'open'))
perform_enqueued_jobs commit_transaction: true
expect(message).to have_message_count(0)
end
context 'with create event only' do
let(:types) { 'create' }
let(:message) { 'bar' }
it 'publishes no ticket updates', :aggregate_failures do
expect(message).to have_message_count(0)
ticket.update!(state: Ticket::State.find_by(name: 'open'))
perform_enqueued_jobs commit_transaction: true
expect(message).to have_message_count(0)
end
end
end
context 'with slack group' do
let(:message) { 'baz' }
it 'publishes ticket updates', :aggregate_failures do
expect(message).to have_message_count(1)
new_message = 'qux'
ticket.update!(title: new_message)
perform_enqueued_jobs commit_transaction: true
expect(new_message).to have_message_count(1)
ticket.update!(state: Ticket::State.find_by(name: 'pending reminder'), pending_time: Time.zone.local(2023, 2, 7, 12))
perform_enqueued_jobs commit_transaction: true
expect(new_message).to have_message_count(2)
Ticket.process_pending
perform_enqueued_jobs commit_transaction: true
expect(new_message).to have_message_count(3)
Ticket.process_pending
perform_enqueued_jobs commit_transaction: true
expect(new_message).to have_message_count(3)
end
context 'with create event only' do
let(:types) { 'create' }
let(:message) { 'corge' }
it 'publishes no ticket updates', :aggregate_failures do
expect(message).to have_message_count(1)
new_message = 'grault'
ticket.update!(title: new_message)
perform_enqueued_jobs commit_transaction: true
expect(new_message).to have_message_count(0)
end
end
end
end