Commit f16e413d47af55af253f74b30e03adb5e9e21495
1 parent
e7d0739d
Exists in
master
and in
1 other branch
Copy pasted wrong
Showing
1 changed file
with
12 additions
and
29 deletions
Show diff stats
spec/models/notification_service/slack_service_spec.rb
1 | -class NotificationServices::SlackService < NotificationService | |
2 | - Label = "slack" | |
3 | - Fields += [ | |
4 | - [:service_url, { | |
5 | - :placeholder => 'Slack Hook URL (https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX)', | |
6 | - :label => 'Hook URL' | |
7 | - }] | |
8 | - ] | |
1 | +describe NotificationService::SlackService, type: 'model' do | |
2 | + it "it should send a notification to Slack with hook url" do | |
3 | + # setup | |
4 | + notice = Fabricate :notice | |
5 | + notification_service = Fabricate :slack_notification_service, :app => notice.app, :service_url => "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX" | |
6 | + problem = notice.problem | |
9 | 7 | |
10 | - def check_params | |
11 | - if Fields.detect {|f| self[f[0]].blank? } | |
12 | - errors.add :base, "You must specify your Slack Hook url." | |
13 | - end | |
14 | - end | |
15 | - | |
16 | - def message_for_slack(problem) | |
17 | - "[#{problem.app.name}][#{problem.environment}][#{problem.where}]: #{problem.error_class} #{problem_url(problem)}" | |
18 | - end | |
19 | - | |
20 | - def post_payload(problem) | |
21 | - { | |
8 | + # faraday stubbing | |
9 | + payload = { | |
22 | 10 | :attachments => [ |
23 | 11 | { |
24 | - :fallback => message_for_slack(problem), | |
25 | - :pretext => "<#{problem_url(problem)}|Errbit - #{problem.app.name}: #{problem.error_class}>", | |
12 | + :fallback => notification_service.message_for_slack(problem), | |
13 | + :pretext => "<#{notification_service.problem_url(problem)}|Errbit - #{problem.app.name}: #{problem.error_class}>", | |
26 | 14 | :color => "#D00000", |
27 | 15 | :fields => [ |
28 | 16 | { |
... | ... | @@ -59,13 +47,8 @@ class NotificationServices::SlackService < NotificationService |
59 | 47 | } |
60 | 48 | ] |
61 | 49 | }.to_json |
62 | - end | |
63 | - | |
64 | - def create_notification(problem) | |
65 | - HTTParty.post(service_url, :body => post_payload(problem), :headers => { 'Content-Type' => 'application/json' }) | |
66 | - end | |
50 | + expect(HTTParty).to receive(:post).with(notification_service.service_url, :body => payload, :headers => {"Content-Type" => "application/json"}).and_return(true) | |
67 | 51 | |
68 | - def configured? | |
69 | - service_url.present? | |
52 | + notification_service.create_notification(problem) | |
70 | 53 | end |
71 | 54 | end | ... | ... |