slack_service_spec.rb
1.68 KB
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
describe NotificationServices::SlackService, type: 'model' do
it "it should send a notification to Slack with hook url" do
# setup
notice = Fabricate :notice
notification_service = Fabricate :slack_notification_service, app: notice.app, service_url: "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX"
problem = notice.problem
# faraday stubbing
payload = {
attachments: [
{
fallback: notification_service.message_for_slack(problem),
pretext: "<#{problem.url}|Errbit - #{problem.app.name}: #{problem.error_class}>",
color: "#D00000",
fields: [
{
title: "Environment",
value: problem.environment,
short: false
},
{
title: "Location",
value: problem.where,
short: false
},
{
title: "Message",
value: problem.message.to_s,
short: false
},
{
title: "First Noticed",
value: problem.first_notice_at,
short: false
},
{
title: "Last Noticed",
value: problem.last_notice_at,
short: false
},
{
title: "Times Occurred",
value: problem.notices_count,
short: false
}
]
}
]
}.to_json
expect(HTTParty).to receive(:post).with(notification_service.service_url, body: payload, headers: { "Content-Type" => "application/json" }).and_return(true)
notification_service.create_notification(problem)
end
end