flapjack-diner 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.rubocop.yml +21 -0
  4. data/.rubocop_todo.yml +135 -0
  5. data/Gemfile +7 -0
  6. data/README.md +86 -20
  7. data/flapjack-diner.gemspec +11 -15
  8. data/lib/flapjack-diner.rb +23 -548
  9. data/lib/flapjack-diner/argument_validator.rb +31 -22
  10. data/lib/flapjack-diner/resources/checks.rb +58 -0
  11. data/lib/flapjack-diner/resources/contacts.rb +70 -0
  12. data/lib/flapjack-diner/resources/entities.rb +68 -0
  13. data/lib/flapjack-diner/resources/maintenance_periods.rb +82 -0
  14. data/lib/flapjack-diner/resources/media.rb +61 -0
  15. data/lib/flapjack-diner/resources/notification_rules.rb +66 -0
  16. data/lib/flapjack-diner/resources/notifications.rb +27 -0
  17. data/lib/flapjack-diner/resources/pagerduty_credentials.rb +60 -0
  18. data/lib/flapjack-diner/resources/reports.rb +33 -0
  19. data/lib/flapjack-diner/tools.rb +277 -0
  20. data/lib/flapjack-diner/version.rb +1 -1
  21. data/spec/argument_validator_spec.rb +15 -15
  22. data/spec/flapjack-diner_spec.rb +58 -1275
  23. data/spec/pacts/flapjack-diner-flapjack.json +4522 -0
  24. data/spec/resources/checks_spec.rb +171 -0
  25. data/spec/resources/contacts_spec.rb +297 -0
  26. data/spec/resources/entities_spec.rb +181 -0
  27. data/spec/resources/maintenance_periods_spec.rb +603 -0
  28. data/spec/resources/media_spec.rb +277 -0
  29. data/spec/resources/notification_rules_spec.rb +341 -0
  30. data/spec/resources/notifications_spec.rb +210 -0
  31. data/spec/resources/pagerduty_credentials_spec.rb +243 -0
  32. data/spec/resources/reports_spec.rb +255 -0
  33. data/spec/spec_helper.rb +14 -2
  34. metadata +35 -72
@@ -0,0 +1,277 @@
1
+ require 'spec_helper'
2
+ require 'flapjack-diner'
3
+
4
+ describe Flapjack::Diner::Resources::Media, :pact => true do
5
+
6
+ before(:each) do
7
+ Flapjack::Diner.base_uri('localhost:19081')
8
+ Flapjack::Diner.logger = nil
9
+ end
10
+
11
+ context 'create' do
12
+
13
+ it "submits a POST request for a medium" do
14
+ data = [{
15
+ :type => 'sms',
16
+ :address => '0123456789',
17
+ :interval => 300,
18
+ :rollup_threshold => 5
19
+ }]
20
+
21
+ flapjack.given("a contact with id 'abc' exists").
22
+ upon_receiving("a POST request with one medium").
23
+ with(:method => :post, :path => '/contacts/abc/media',
24
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
25
+ :body => {:media => data}).
26
+ will_respond_with(
27
+ :status => 201,
28
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
29
+ :body => ['abc_sms'] )
30
+
31
+ result = Flapjack::Diner.create_contact_media('abc', data)
32
+ expect(result).not_to be_nil
33
+ expect(result).to eq(['abc_sms'])
34
+ end
35
+
36
+ it "submits a POST request for several media" do
37
+ data = [{
38
+ :type => 'sms',
39
+ :address => '0123456789',
40
+ :interval => 300,
41
+ :rollup_threshold => 5
42
+ }, {
43
+ :type => 'email',
44
+ :address => 'ablated@example.org',
45
+ :interval => 180,
46
+ :rollup_threshold => 3
47
+ }]
48
+
49
+ flapjack.given("a contact with id 'abc' exists").
50
+ upon_receiving("a POST request with two media").
51
+ with(:method => :post, :path => '/contacts/abc/media',
52
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
53
+ :body => {:media => data}).
54
+ will_respond_with(
55
+ :status => 201,
56
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
57
+ :body => ['abc_sms', 'abc_email'] )
58
+
59
+ result = Flapjack::Diner.create_contact_media('abc', data)
60
+ expect(result).not_to be_nil
61
+ expect(result).to eq(['abc_sms', 'abc_email'])
62
+ end
63
+
64
+ it "can't find the contact to create a medium for" do
65
+ data = [{
66
+ :type => 'sms',
67
+ :address => '0123456789',
68
+ :interval => 300,
69
+ :rollup_threshold => 5
70
+ }]
71
+
72
+ flapjack.given("no contact exists").
73
+ upon_receiving("a POST request with one medium").
74
+ with(:method => :post, :path => '/contacts/abc/media',
75
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
76
+ :body => {:media => data}).
77
+ will_respond_with(
78
+ :status => 422,
79
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
80
+ :body => {:errors => ["Contact id: 'abc' could not be loaded"]} )
81
+
82
+ result = Flapjack::Diner.create_contact_media('abc', data)
83
+ expect(result).to be_nil
84
+ expect(Flapjack::Diner.last_error).to eq(:status_code => 422,
85
+ :errors => ["Contact id: 'abc' could not be loaded"])
86
+ end
87
+
88
+ end
89
+
90
+ context 'read' do
91
+
92
+ let(:sms_data) {
93
+ {
94
+ :type => 'sms',
95
+ :address => '0123456789',
96
+ :interval => 300,
97
+ :rollup_threshold => 5
98
+ }
99
+ }
100
+
101
+ let(:email_data) {
102
+ {
103
+ :type => 'email',
104
+ :address => 'ablated@example.org',
105
+ :interval => 180,
106
+ :rollup_threshold => 3
107
+ }
108
+ }
109
+
110
+ let(:links) { {:links => {:contacts => ['abc']}} }
111
+
112
+ it "submits a GET request for all media" do
113
+ media_data = [email_data.merge(links), sms_data.merge(links)]
114
+
115
+ flapjack.given("a contact with id 'abc' has email and sms media").
116
+ upon_receiving("a GET request for all media").
117
+ with(:method => :get, :path => '/media').
118
+ will_respond_with(
119
+ :status => 200,
120
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
121
+ :body => {:media => media_data} )
122
+
123
+ result = Flapjack::Diner.media
124
+ expect(result).to eq(media_data)
125
+ end
126
+
127
+ it "submits a GET request for one medium" do
128
+ media_data = [sms_data.merge(links)]
129
+
130
+ flapjack.given("a contact with id 'abc' has email and sms media").
131
+ upon_receiving("a GET request for sms media").
132
+ with(:method => :get, :path => '/media/abc_sms').
133
+ will_respond_with(
134
+ :status => 200,
135
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
136
+ :body => {:media => media_data} )
137
+
138
+ result = Flapjack::Diner.media('abc_sms')
139
+ expect(result).to eq(media_data)
140
+ end
141
+
142
+ it "submits a GET request for several media" do
143
+ media_data = [email_data.merge(links), sms_data.merge(links)]
144
+
145
+ flapjack.given("a contact with id 'abc' has email and sms media").
146
+ upon_receiving("a GET request for email and sms media").
147
+ with(:method => :get, :path => '/media/abc_email,abc_sms').
148
+ will_respond_with(
149
+ :status => 200,
150
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
151
+ :body => {:media => media_data} )
152
+
153
+ result = Flapjack::Diner.media('abc_email', 'abc_sms')
154
+ expect(result).to eq(media_data)
155
+ end
156
+
157
+ it "can't find the contact with media to read" do
158
+ flapjack.given("no contact exists").
159
+ upon_receiving("a GET request for sms media").
160
+ with(:method => :get, :path => '/media/abc_sms').
161
+ will_respond_with(
162
+ :status => 404,
163
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
164
+ :body => {:errors => ["could not find contact 'abc'"]} )
165
+
166
+ result = Flapjack::Diner.media('abc_sms')
167
+ expect(result).to be_nil
168
+ expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
169
+ :errors => ["could not find contact 'abc'"])
170
+ end
171
+
172
+ end
173
+
174
+ context 'update' do
175
+
176
+ it "submits a PATCH request for one medium" do
177
+ flapjack.given("a contact with id 'abc' has email and sms media").
178
+ upon_receiving("a PATCH request for email media").
179
+ with(:method => :patch,
180
+ :path => '/media/abc_email',
181
+ :headers => {'Content-Type'=>'application/json-patch+json'},
182
+ :body => [{:op => 'replace', :path => '/media/0/interval', :value => 50},
183
+ {:op => 'replace', :path => '/media/0/rollup_threshold', :value => 3}]).
184
+ will_respond_with(
185
+ :status => 204,
186
+ :body => '' )
187
+
188
+ result = Flapjack::Diner.update_media('abc_email', :interval => 50, :rollup_threshold => 3)
189
+ expect(result).not_to be_nil
190
+ expect(result).to be_truthy
191
+ end
192
+
193
+ it "submits a PATCH request for several media" do
194
+ flapjack.given("a contact with id 'abc' has email and sms media").
195
+ upon_receiving("a PATCH request for email and sms media").
196
+ with(:method => :patch,
197
+ :path => '/media/abc_email,abc_sms',
198
+ :headers => {'Content-Type'=>'application/json-patch+json'},
199
+ :body => [{:op => 'replace', :path => '/media/0/interval', :value => 50},
200
+ {:op => 'replace', :path => '/media/0/rollup_threshold', :value => 3}]).
201
+ will_respond_with(
202
+ :status => 204,
203
+ :body => '' )
204
+
205
+ result = Flapjack::Diner.update_media('abc_email', 'abc_sms', :interval => 50, :rollup_threshold => 3)
206
+ expect(result).not_to be_nil
207
+ expect(result).to be_truthy
208
+ end
209
+
210
+ it "can't find the contact with media to update" do
211
+ flapjack.given("no contact exists").
212
+ upon_receiving("a PATCH request for email media").
213
+ with(:method => :patch,
214
+ :path => '/media/abc_email',
215
+ :headers => {'Content-Type'=>'application/json-patch+json'},
216
+ :body => [{:op => 'replace', :path => '/media/0/interval', :value => 50}]).
217
+ will_respond_with(:status => 404,
218
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
219
+ :body => {:errors => ["could not find contact 'abc'"]} )
220
+
221
+ result = Flapjack::Diner.update_media('abc_email', :interval => 50)
222
+ expect(result).to be_nil
223
+ expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
224
+ :errors => ["could not find contact 'abc'"])
225
+ end
226
+
227
+ end
228
+
229
+ context 'delete' do
230
+ it "submits a DELETE request for one medium" do
231
+
232
+ flapjack.given("a contact with id 'abc' has email and sms media").
233
+ upon_receiving("a DELETE request for one medium").
234
+ with(:method => :delete,
235
+ :path => '/media/abc_email',
236
+ :body => nil).
237
+ will_respond_with(:status => 204,
238
+ :body => '')
239
+
240
+ result = Flapjack::Diner.delete_media('abc_email')
241
+ expect(result).not_to be_nil
242
+ expect(result).to be_truthy
243
+ end
244
+
245
+ it "submits a DELETE request for several media" do
246
+ flapjack.given("a contact with id 'abc' has email and sms media").
247
+ upon_receiving("a DELETE request for two media").
248
+ with(:method => :delete,
249
+ :path => '/media/abc_email,abc_sms',
250
+ :body => nil).
251
+ will_respond_with(:status => 204,
252
+ :body => '')
253
+
254
+ result = Flapjack::Diner.delete_media('abc_email', 'abc_sms')
255
+ expect(result).not_to be_nil
256
+ expect(result).to be_truthy
257
+ end
258
+
259
+ it "can't find the contact with media to delete" do
260
+ flapjack.given("no contact exists").
261
+ upon_receiving("a DELETE request for one medium").
262
+ with(:method => :delete,
263
+ :path => '/media/abc_email',
264
+ :body => nil).
265
+ will_respond_with(:status => 404,
266
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
267
+ :body => {:errors => ["could not find contact 'abc'"]} )
268
+
269
+ result = Flapjack::Diner.delete_media('abc_email')
270
+ expect(result).to be_nil
271
+ expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
272
+ :errors => ["could not find contact 'abc'"])
273
+ end
274
+
275
+ end
276
+
277
+ end
@@ -0,0 +1,341 @@
1
+ require 'spec_helper'
2
+ require 'flapjack-diner'
3
+
4
+ describe Flapjack::Diner::Resources::NotificationRules, :pact => true do
5
+
6
+ let(:rule_id_regexp) {
7
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
8
+ }
9
+
10
+ before(:each) do
11
+ Flapjack::Diner.base_uri('localhost:19081')
12
+ Flapjack::Diner.logger = nil
13
+ end
14
+
15
+ context 'create' do
16
+
17
+ it "submits a POST request for a notification rule" do
18
+ data = [{
19
+ :entity_tags => ["database","physical"],
20
+ :entities => ["foo-app-01.example.com"],
21
+ :time_restrictions => nil,
22
+ :warning_media => ["email"],
23
+ :critical_media => ["sms", "email"],
24
+ :warning_blackhole => false,
25
+ :critical_blackhole => false
26
+ }]
27
+
28
+ flapjack.given("a contact with id 'abc' exists").
29
+ upon_receiving("a POST request with one notification rule").
30
+ with(:method => :post, :path => '/contacts/abc/notification_rules',
31
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
32
+ :body => {:notification_rules => data}).
33
+ will_respond_with(
34
+ :status => 201,
35
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
36
+ :body => [ Pact::Term.new(
37
+ :generate => '05983623-fcef-42da-af44-ed6990b500fa',
38
+ :matcher => rule_id_regexp
39
+ ) ]
40
+ )
41
+
42
+ result = Flapjack::Diner.create_contact_notification_rules('abc', data)
43
+ expect(result).not_to be_nil
44
+ expect(result).to eq(['05983623-fcef-42da-af44-ed6990b500fa'])
45
+ end
46
+
47
+ it "submits a POST request for several notification rules" do
48
+ data = [{
49
+ :entity_tags => ["database","physical"],
50
+ :entities => ["foo-app-01.example.com"],
51
+ :time_restrictions => nil,
52
+ :warning_media => ["email"],
53
+ :critical_media => ["sms", "email"],
54
+ :warning_blackhole => false,
55
+ :critical_blackhole => false
56
+ }, {
57
+ :entity_tags => nil,
58
+ :entities => ["foo-app-02.example.com"],
59
+ :time_restrictions => nil,
60
+ :warning_media => ["email"],
61
+ :critical_media => ["sms", "email"],
62
+ :warning_blackhole => true,
63
+ :critical_blackhole => false
64
+ }]
65
+
66
+ flapjack.given("a contact with id 'abc' exists").
67
+ upon_receiving("a POST request with two notification rules").
68
+ with(:method => :post, :path => '/contacts/abc/notification_rules',
69
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
70
+ :body => {:notification_rules => data}).
71
+ will_respond_with(
72
+ :status => 201,
73
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
74
+ :body => [ Pact::Term.new(
75
+ :generate => '05983623-fcef-42da-af44-ed6990b500fa',
76
+ :matcher => rule_id_regexp
77
+ ), Pact::Term.new(
78
+ :generate => '20f182fc-6e32-4794-9007-97366d162c51',
79
+ :matcher => rule_id_regexp
80
+ ) ]
81
+ )
82
+
83
+ result = Flapjack::Diner.create_contact_notification_rules('abc', data)
84
+ expect(result).not_to be_nil
85
+ expect(result).to eq(['05983623-fcef-42da-af44-ed6990b500fa',
86
+ '20f182fc-6e32-4794-9007-97366d162c51'])
87
+ end
88
+
89
+ it "can't find the contact to add a notification rule to" do
90
+ data = [{
91
+ :entity_tags => ["database","physical"],
92
+ :entities => ["foo-app-01.example.com"],
93
+ :time_restrictions => nil,
94
+ :warning_media => ["email"],
95
+ :critical_media => ["sms", "email"],
96
+ :warning_blackhole => false,
97
+ :critical_blackhole => false
98
+ }]
99
+
100
+ flapjack.given("no contact exists").
101
+ upon_receiving("a POST request with one notification rule").
102
+ with(:method => :post, :path => '/contacts/abc/notification_rules',
103
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
104
+ :body => {:notification_rules => data}).
105
+ will_respond_with(
106
+ :status => 404,
107
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
108
+ :body => {:errors => ["could not find contact 'abc'"]}
109
+ )
110
+
111
+ result = Flapjack::Diner.create_contact_notification_rules('abc', data)
112
+ expect(result).to be_nil
113
+ expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
114
+ :errors => ["could not find contact 'abc'"])
115
+ end
116
+
117
+ end
118
+
119
+ context 'read' do
120
+ it "submits a GET request for all notification rules" do
121
+ data = {
122
+ :id => '05983623-fcef-42da-af44-ed6990b500fa',
123
+ :tags => [],
124
+ :regex_tags => [],
125
+ :entities => [],
126
+ :regex_entities => [],
127
+ :time_restrictions => [],
128
+ :warning_media => ["email"],
129
+ :critical_media => ["sms", "email"],
130
+ :warning_blackhole => false,
131
+ :critical_blackhole => false
132
+ }
133
+
134
+ flapjack.given("a contact 'abc' with generic notification rule '05983623-fcef-42da-af44-ed6990b500fa' exists").
135
+ upon_receiving("a GET request for all notification rules").
136
+ with(:method => :get, :path => '/notification_rules').
137
+ will_respond_with(
138
+ :status => 200,
139
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
140
+ :body => {:notification_rules => [data]} )
141
+
142
+ result = Flapjack::Diner.notification_rules
143
+ expect(result).not_to be_nil
144
+ expect(result).to eq([data])
145
+ end
146
+
147
+ it "submits a GET request for one notification rule" do
148
+ data = {
149
+ :id => '05983623-fcef-42da-af44-ed6990b500fa',
150
+ :tags => [],
151
+ :regex_tags => [],
152
+ :entities => [],
153
+ :regex_entities => [],
154
+ :time_restrictions => [],
155
+ :warning_media => ["email"],
156
+ :critical_media => ["sms", "email"],
157
+ :warning_blackhole => false,
158
+ :critical_blackhole => false
159
+ }
160
+
161
+ flapjack.given("a contact 'abc' with generic notification rule '05983623-fcef-42da-af44-ed6990b500fa' exists").
162
+ upon_receiving("a GET request for a single notification rule").
163
+ with(:method => :get, :path => '/notification_rules/05983623-fcef-42da-af44-ed6990b500fa').
164
+ will_respond_with(
165
+ :status => 200,
166
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
167
+ :body => {:notification_rules => [data]} )
168
+
169
+ result = Flapjack::Diner.notification_rules('05983623-fcef-42da-af44-ed6990b500fa')
170
+ expect(result).not_to be_nil
171
+ expect(result).to eq([data])
172
+ end
173
+
174
+ it "submits a GET request for several notification rules" do
175
+ data = {
176
+ :id => '05983623-fcef-42da-af44-ed6990b500fa',
177
+ :tags => [],
178
+ :regex_tags => [],
179
+ :entities => [],
180
+ :regex_entities => [],
181
+ :time_restrictions => [],
182
+ :warning_media => ["email"],
183
+ :critical_media => ["sms", "email"],
184
+ :warning_blackhole => false,
185
+ :critical_blackhole => false
186
+ }
187
+
188
+ data_2 = {
189
+ :id => '20f182fc-6e32-4794-9007-97366d162c51',
190
+ :tags => ['physical'],
191
+ :regex_tags => [],
192
+ :entities => ['example.com'],
193
+ :regex_entities => [],
194
+ :time_restrictions => [],
195
+ :warning_media => ["email"],
196
+ :critical_media => ["sms", "email"],
197
+ :warning_blackhole => true,
198
+ :critical_blackhole => true
199
+ }
200
+
201
+ flapjack.given("a contact 'abc' with generic notification rule '05983623-fcef-42da-af44-ed6990b500fa' and notification rule '20f182fc-6e32-4794-9007-97366d162c51' exists").
202
+ upon_receiving("a GET request for two notification rules").
203
+ with(:method => :get, :path => '/notification_rules/05983623-fcef-42da-af44-ed6990b500fa,20f182fc-6e32-4794-9007-97366d162c51').
204
+ will_respond_with(
205
+ :status => 200,
206
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
207
+ :body => {:notification_rules => [data, data_2]} )
208
+
209
+ result = Flapjack::Diner.notification_rules('05983623-fcef-42da-af44-ed6990b500fa',
210
+ '20f182fc-6e32-4794-9007-97366d162c51')
211
+ expect(result).not_to be_nil
212
+ expect(result).to eq([data, data_2])
213
+ end
214
+
215
+ it "can't find the notification rule to read" do
216
+ flapjack.given("no notification rule exists").
217
+ upon_receiving("a GET request for a single notification rule").
218
+ with(:method => :get, :path => '/notification_rules/05983623-fcef-42da-af44-ed6990b500fa').
219
+ will_respond_with(
220
+ :status => 404,
221
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
222
+ :body => {:errors => ["could not find notification rules '05983623-fcef-42da-af44-ed6990b500fa'"]}
223
+ )
224
+
225
+ result = Flapjack::Diner.notification_rules('05983623-fcef-42da-af44-ed6990b500fa')
226
+ expect(result).to be_nil
227
+ expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
228
+ :errors => ["could not find notification rules '05983623-fcef-42da-af44-ed6990b500fa'"])
229
+ end
230
+
231
+ end
232
+
233
+ context 'update' do
234
+
235
+ it "submits a PATCH request for one notification rule" do
236
+ flapjack.given("a contact 'abc' with generic notification rule '05983623-fcef-42da-af44-ed6990b500fa' exists").
237
+ upon_receiving("a PATCH request to change properties for a single notification rule").
238
+ with(:method => :patch,
239
+ :path => '/notification_rules/05983623-fcef-42da-af44-ed6990b500fa',
240
+ :body => [{:op => 'replace', :path => '/notification_rules/0/warning_blackhole', :value => false}],
241
+ :headers => {'Content-Type'=>'application/json-patch+json'}).
242
+ will_respond_with(
243
+ :status => 204,
244
+ :body => '')
245
+
246
+ result = Flapjack::Diner.update_notification_rules('05983623-fcef-42da-af44-ed6990b500fa',
247
+ :warning_blackhole => false)
248
+ expect(result).not_to be_nil
249
+ expect(result).to be_truthy
250
+ end
251
+
252
+ it "submits a PATCH request for several notification rules" do
253
+ flapjack.given("a contact 'abc' with generic notification rule '05983623-fcef-42da-af44-ed6990b500fa' and notification rule '20f182fc-6e32-4794-9007-97366d162c51' exists").
254
+ upon_receiving("a PATCH request to change properties for two notification rules").
255
+ with(:method => :patch,
256
+ :path => '/notification_rules/05983623-fcef-42da-af44-ed6990b500fa,20f182fc-6e32-4794-9007-97366d162c51',
257
+ :body => [{:op => 'replace', :path => '/notification_rules/0/warning_blackhole', :value => false}],
258
+ :headers => {'Content-Type'=>'application/json-patch+json'}).
259
+ will_respond_with(
260
+ :status => 204,
261
+ :body => '')
262
+
263
+ result = Flapjack::Diner.update_notification_rules('05983623-fcef-42da-af44-ed6990b500fa',
264
+ '20f182fc-6e32-4794-9007-97366d162c51', :warning_blackhole => false)
265
+ expect(result).not_to be_nil
266
+ expect(result).to be_truthy
267
+ end
268
+
269
+ it "can't find the notification rule to update" do
270
+ flapjack.given("no notification rule exists").
271
+ upon_receiving("a PATCH request to change properties for a single notification rule").
272
+ with(:method => :patch,
273
+ :path => '/notification_rules/05983623-fcef-42da-af44-ed6990b500fa',
274
+ :body => [{:op => 'replace', :path => '/notification_rules/0/warning_blackhole', :value => false}],
275
+ :headers => {'Content-Type'=>'application/json-patch+json'}).
276
+ will_respond_with(
277
+ :status => 404,
278
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
279
+ :body => {:errors => ["could not find notification rule '05983623-fcef-42da-af44-ed6990b500fa'"]}
280
+ )
281
+
282
+ result = Flapjack::Diner.update_notification_rules('05983623-fcef-42da-af44-ed6990b500fa',
283
+ :warning_blackhole => false)
284
+ expect(result).to be_nil
285
+ expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
286
+ :errors => ["could not find notification rule '05983623-fcef-42da-af44-ed6990b500fa'"])
287
+ end
288
+
289
+ end
290
+
291
+ context 'delete' do
292
+ it "submits a DELETE request for a notification rule" do
293
+ flapjack.given("a contact 'abc' with generic notification rule '05983623-fcef-42da-af44-ed6990b500fa' exists").
294
+ upon_receiving("a DELETE request for a single notification rule").
295
+ with(:method => :delete,
296
+ :path => '/notification_rules/05983623-fcef-42da-af44-ed6990b500fa',
297
+ :body => nil).
298
+ will_respond_with(:status => 204,
299
+ :body => '')
300
+
301
+ result = Flapjack::Diner.delete_notification_rules('05983623-fcef-42da-af44-ed6990b500fa')
302
+ expect(result).not_to be_nil
303
+ expect(result).to be_truthy
304
+ end
305
+
306
+ it "submits a DELETE request for several notification rules" do
307
+ flapjack.given("a contact 'abc' with generic notification rule '05983623-fcef-42da-af44-ed6990b500fa' and notification rule '20f182fc-6e32-4794-9007-97366d162c51' exists").
308
+ upon_receiving("a DELETE request for two notification rules").
309
+ with(:method => :delete,
310
+ :path => '/notification_rules/05983623-fcef-42da-af44-ed6990b500fa,20f182fc-6e32-4794-9007-97366d162c51',
311
+ :body => nil).
312
+ will_respond_with(:status => 204,
313
+ :body => '')
314
+
315
+ result = Flapjack::Diner.delete_notification_rules('05983623-fcef-42da-af44-ed6990b500fa',
316
+ '20f182fc-6e32-4794-9007-97366d162c51')
317
+ expect(result).not_to be_nil
318
+ expect(result).to be_truthy
319
+ end
320
+
321
+ it "can't find the notification rule to delete" do
322
+ flapjack.given("no notification rule exists").
323
+ upon_receiving("a DELETE request for a single notification rule").
324
+ with(:method => :delete,
325
+ :path => '/notification_rules/05983623-fcef-42da-af44-ed6990b500fa',
326
+ :body => nil).
327
+ will_respond_with(
328
+ :status => 404,
329
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
330
+ :body => {:errors => ["could not find notification rule '05983623-fcef-42da-af44-ed6990b500fa'"]}
331
+ )
332
+
333
+ result = Flapjack::Diner.delete_notification_rules('05983623-fcef-42da-af44-ed6990b500fa')
334
+ expect(result).to be_nil
335
+ expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
336
+ :errors => ["could not find notification rule '05983623-fcef-42da-af44-ed6990b500fa'"])
337
+
338
+ end
339
+ end
340
+
341
+ end