flapjack 0.8.4 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,3 +20,8 @@
20
20
  <% end %>
21
21
  </table>
22
22
  <% end %>
23
+
24
+ <a href="/edit_contacts"/>
25
+ Edit contacts
26
+ <span class="label label-danger">beta</span>
27
+ </a>
@@ -1,12 +1,13 @@
1
1
  <%
2
2
  require_css 'select2'
3
+ require_css 'select2-bootstrap'
3
4
 
4
5
  require_js 'underscore'
5
6
  require_js 'jquery-1.10.2'
6
- require_js 'select2'
7
7
  require_js 'backbone'
8
8
  require_js 'backbone.jsonapi'
9
9
  require_js 'bootstrap.min'
10
+ require_js 'select2'
10
11
  require_js 'contacts'
11
12
  %>
12
13
 
@@ -19,25 +20,71 @@
19
20
  <script type="text/template" id="contact-list-item-template">
20
21
  <td><@- first_name @></td>
21
22
  <td><@- last_name @></td>
22
- <td><@- email @></td>
23
+ <td>
24
+ <button type="button" class="close button delete delete-contact" aria-hidden="true">&minus;</button>
25
+ </td>
23
26
  </script>
24
27
 
25
- <div id="data-api-url" data-api-url="<%= @api_url %>">
26
- <div class="page-header">
27
- <h2>Edit Contacts</h2>
28
+ <script type="text/template" id="contact-entities-list-item-template">
29
+ <td><@- name @></td>
30
+ <td><button type="button" class="close button delete delete-entity" aria-hidden="true">&minus;</button></td>
31
+ </script>
32
+
33
+ <script type="text/template" id="contact-media-list-item-template">
34
+ <td>
35
+ <@- labels[type] @>
36
+ </td>
37
+ <td>
38
+ <input type="text" data-attr="address" class="form-control" value="<@- address @>">
39
+ </td>
40
+ <td>
41
+ <input type="text" data-attr="interval" class="form-control" value="<@- interval @>">
42
+ </td>
43
+ <td>
44
+ <input type="text" data-attr="rollup_threshold" class="form-control" value="<@- rollup_threshold @>">
45
+ </td>
46
+ </script>
47
+
48
+ <script type="text/template" id="contact-template">
49
+ <div class="form-group">
50
+ <label class="col-sm-3 control-label" for="contact_first_name">First name</label>
51
+ <div class="col-sm-9">
52
+ <input type="text" autofocus="autofocus" name="contact_first_name" class="form-control" value="<@- first_name @>">
53
+ </div>
54
+ </div>
55
+ <div class="form-group">
56
+ <label class="col-sm-3 control-label" for="contact_last_name">Last name</label>
57
+ <div class="col-sm-9">
58
+ <input type="text" name="contact_last_name" class="form-control" value="<@- last_name @>">
28
59
  </div>
29
- <div id="container">
30
- <table class="table">
31
- <thead>
32
- <tr>
33
- <th>First Name</th>
34
- <th>Last Name</th>
35
- <th>Email</th>
36
- </tr>
37
- </thead>
38
- <tbody id="contactList">
39
- </tbody>
40
- </table>
60
+ </div>
61
+ </script>
62
+
63
+ <script type="text/template" id="contact-entity-chooser">
64
+ <input type="hidden" id="entityChooser" style="width: 440px">
65
+ <button id="add-contact-entity" type="button" class="btn btn-default btn-xs">
66
+ <i class="fa fa-plus-square"></i>
67
+ &nbsp;
68
+ Add Entities
69
+ </button>
70
+ </script>
71
+
72
+ <div id="data-api-url" data-api-url="<%= @api_url %>">
73
+ <div class="page-header">
74
+ <h2>Edit Contacts</h2>
75
+ </div>
76
+ <div id="container">
77
+ <table class="table">
78
+ <thead>
79
+ <tr>
80
+ <th>First Name</th>
81
+ <th>Last Name</th>
82
+ <th>&nbsp;</th>
83
+ </tr>
84
+ </thead>
85
+ <tbody id="contactList">
86
+ </tbody>
87
+ </table>
41
88
 
42
89
  <!-- Modal -->
43
90
  <div class="modal fade" id="contactModal" tabindex="-1" role="dialog" aria-labelledby="contactModalLabel" aria-hidden="true">
@@ -50,30 +97,39 @@
50
97
  <div class="modal-body">
51
98
 
52
99
  <form action="/contacts" method="post" role="form" class="form-horizontal">
53
- <div class="form-group">
54
- <label class="col-sm-3 control-label" for="contact_first_name">First name</label>
55
- <div class="col-sm-9">
56
- <input type="text" name="contact_first_name" class="form-control" value="">
57
- </div>
58
- </div>
59
- <div class="form-group">
60
- <label class="col-sm-3 control-label" for="contact_last_name">Last name</label>
61
- <div class="col-sm-9">
62
- <input type="text" name="contact_last_name" class="form-control" value="">
63
- </div>
64
- </div>
65
- <div class="form-group">
66
- <label class="col-sm-3 control-label" for="contact_email">Email</label>
67
- <div class="col-sm-9">
68
- <input type="text" name="contact_email" class="form-control" value="">
69
- </div>
100
+
101
+ <div class="modal-footer">
102
+ <button type="button" class="btn btn-success" id="contactAccept">Create Contact</button>
70
103
  </div>
71
104
  </form><!-- form-horizontal-->
72
105
 
73
- </div>
74
- <div class="modal-footer">
75
- <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
76
- <button type="button" class="btn btn-success">Create Contact</button>
106
+ <table class="table">
107
+ <thead>
108
+ <tr>
109
+ <th style="width: 15%">Media</th>
110
+ <th style="width: 65%">Address</th>
111
+ <th style="width: 10%">Interval</th>
112
+ <th style="width: 10%">Rollup</th>
113
+ </tr>
114
+ </thead>
115
+ <tbody id="contactMediaList">
116
+ </tbody>
117
+ </table>
118
+
119
+ <div id="entityAdd">
120
+ </div>
121
+
122
+ <table class="table" style="margin-top: 1em">
123
+ <thead>
124
+ <tr>
125
+ <th>Entities</th>
126
+ <th>&nbsp;</th>
127
+ </tr>
128
+ </thead>
129
+ <tbody id="contactEntityList">
130
+ </tbody>
131
+ </table>
132
+
77
133
  </div>
78
134
  </div><!-- /.modal-content -->
79
135
  </div><!-- /.modal-dialog -->
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  module Flapjack
4
- VERSION = "0.8.4"
4
+ VERSION = "0.8.5"
5
5
  end
@@ -76,25 +76,32 @@ describe 'Flapjack::Gateways::JSONAPI::ContactMethods', :sinatra => true, :logge
76
76
  it "returns all the contacts" do
77
77
  expect(Flapjack::Data::Contact).to receive(:entities_jsonapi).
78
78
  with([contact.id], :redis => redis).and_return([[], {}])
79
+ expect(contact).to receive(:media).and_return({})
79
80
  expect(contact).to receive(:linked_entity_ids=).with(nil)
80
- expect(contact).to receive(:to_json).and_return(contact_core.to_json)
81
+ expect(contact).to receive(:linked_media_ids=).with(nil)
82
+ expect(contact).to receive(:to_jsonapi).and_return(contact_core.to_json)
81
83
  expect(Flapjack::Data::Contact).to receive(:all).with(:redis => redis).
82
84
  and_return([contact])
83
85
 
84
86
  aget '/contacts'
85
87
  expect(last_response).to be_ok
86
- expect(last_response.body).to eq({:contacts => [contact_core]}.to_json)
88
+ expect(last_response.body).to eq({:contacts => [contact_core], :linked => {'entities' => [], 'media' => []}}.to_json)
87
89
  end
88
90
 
89
91
  it "returns the core information of a specified contact" do
90
- expect(contact).to receive(:entities).and_return([])
91
- expect(contact).to receive(:to_json).and_return(contact_core.to_json)
92
+ #expect(contact).to receive(:entities).and_return([])
93
+ expect(Flapjack::Data::Contact).to receive(:entities_jsonapi).
94
+ with([contact.id], :redis => redis).and_return([[], {}])
95
+ expect(contact).to receive(:media).and_return({})
96
+ expect(contact).to receive(:linked_entity_ids=).with(nil)
97
+ expect(contact).to receive(:linked_media_ids=).with(nil)
98
+ expect(contact).to receive(:to_jsonapi).and_return(contact_core.to_json)
92
99
  expect(Flapjack::Data::Contact).to receive(:find_by_id).
93
100
  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
94
101
 
95
102
  aget "/contacts/#{contact.id}"
96
103
  expect(last_response).to be_ok
97
- expect(last_response.body).to eq({:contacts => [contact_core]}.to_json)
104
+ expect(last_response.body).to eq({:contacts => [contact_core], :linked => {'entities' => [], 'media' => []}}.to_json)
98
105
  end
99
106
 
100
107
  it "does not return information for a contact that does not exist" do
@@ -106,6 +113,7 @@ describe 'Flapjack::Gateways::JSONAPI::ContactMethods', :sinatra => true, :logge
106
113
  end
107
114
 
108
115
  it "creates a contact with supplied ID" do
116
+ #FIXME: I think media should be removed from this interface
109
117
  contact_data = {
110
118
  "id" => "0362",
111
119
  "first_name" => "John",
@@ -136,7 +144,7 @@ describe 'Flapjack::Gateways::JSONAPI::ContactMethods', :sinatra => true, :logge
136
144
  expect(Flapjack::Data::Contact).to receive(:find_by_id).
137
145
  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
138
146
  expect(contact).to receive(:update)
139
- expect(contact).to receive(:to_json).and_return('{"sausage": "good"}')
147
+ expect(contact).to receive(:to_jsonapi).and_return('{"sausage": "good"}')
140
148
 
141
149
  aput "/contacts/21", {:contacts => [{'sausage' => 'good'}]}.to_json,
142
150
  {'CONTENT_TYPE' => JSON_REQUEST_MIME}
@@ -164,142 +172,6 @@ describe 'Flapjack::Gateways::JSONAPI::ContactMethods', :sinatra => true, :logge
164
172
  expect(last_response.status).to eq(422)
165
173
  end
166
174
 
167
- it "replaces contacts with a submitted list" do
168
- contacts = {'contacts' =>
169
- [{"id" => "0362",
170
- "first_name" => "John",
171
- "last_name" => "Smith",
172
- "email" => "johns@example.dom",
173
- "media" => {"email" => "johns@example.dom",
174
- "jabber" => "johns@conference.localhost"}},
175
- {"id" => "0363",
176
- "first_name" => "Jane",
177
- "last_name" => "Jones",
178
- "email" => "jane@example.dom",
179
- "media" => {"email" => "jane@example.dom"}}
180
- ]
181
- }
182
-
183
- expect(Flapjack::Data::Semaphore).to receive(:new).
184
- with("contact_mass_update", {:redis => redis, :expiry => 30}).and_return(semaphore)
185
- expect(Flapjack::Data::Contact).to receive(:all).with(:redis => redis).and_return([])
186
- expect(Flapjack::Data::Contact).to receive(:add).twice
187
- expect(semaphore).to receive(:release).and_return(true)
188
-
189
- apost "/contacts_atomic", contacts.to_json, {'CONTENT_TYPE' => JSON_REQUEST_MIME}
190
- expect(last_response.status).to eq(204)
191
- end
192
-
193
- it "does not replace contacts if the data is improperly formatted" do
194
- expect(Flapjack::Data::Contact).not_to receive(:add)
195
-
196
- apost "/contacts_atomic", {'contacts' => ["Hello", "again"]}.to_json,
197
- {'CONTENT_TYPE' => JSON_REQUEST_MIME}
198
- expect(last_response.status).to eq(422)
199
- end
200
-
201
- it "does not replace contacts if they don't contain an id in the source" do
202
- contacts = {'contacts' =>
203
- [{"id" => "0362",
204
- "first_name" => "John",
205
- "last_name" => "Smith",
206
- "email" => "johns@example.dom",
207
- "media" => {"email" => "johns@example.dom",
208
- "jabber" => "johns@conference.localhost"}},
209
- {"first_name" => "Jane",
210
- "last_name" => "Jones",
211
- "email" => "jane@example.dom",
212
- "media" => {"email" => "jane@example.dom"}}
213
- ]
214
- }
215
-
216
- expect(Flapjack::Data::Semaphore).to receive(:new).
217
- with("contact_mass_update", {:redis => redis, :expiry => 30}).and_return(semaphore)
218
- expect(Flapjack::Data::Contact).to receive(:all).with(:redis => redis).and_return([])
219
- expect(Flapjack::Data::Contact).to receive(:add)
220
- expect(semaphore).to receive(:release).and_return(true)
221
-
222
- apost "/contacts_atomic", contacts.to_json, {'CONTENT_TYPE' => JSON_REQUEST_MIME}
223
- expect(last_response.status).to eq(204)
224
- end
225
-
226
- it "updates a contact in a bulk replacement list if it is already present" do
227
- contacts = {'contacts' =>
228
- [{"id" => "0362",
229
- "first_name" => "John",
230
- "last_name" => "Smith",
231
- "email" => "johns@example.dom",
232
- "media" => {"email" => "johns@example.dom",
233
- "jabber" => "johns@conference.localhost"}},
234
- {"id" => "0363",
235
- "first_name" => "Jane",
236
- "last_name" => "Jones",
237
- "email" => "jane@example.dom",
238
- "media" => {"email" => "jane@example.dom"}}
239
- ]
240
- }
241
-
242
- expect(Flapjack::Data::Semaphore).to receive(:new).
243
- with("contact_mass_update", {:redis => redis, :expiry => 30}).and_return(semaphore)
244
- existing = double(Flapjack::Data::Contact)
245
- expect(existing).to receive(:id).and_return("0363")
246
- expect(existing).to receive(:update).with(contacts['contacts'][1])
247
-
248
- expect(Flapjack::Data::Contact).to receive(:all).with(:redis => redis).and_return([existing])
249
- expect(Flapjack::Data::Contact).to receive(:add).with(contacts['contacts'][0], :redis => redis)
250
- expect(semaphore).to receive(:release).and_return(true)
251
-
252
- apost "/contacts_atomic", contacts.to_json, {'CONTENT_TYPE' => JSON_REQUEST_MIME}
253
- expect(last_response.status).to eq(204)
254
- end
255
-
256
- it "deletes a contact not found in a bulk update list" do
257
- contacts = {'contacts' =>
258
- [{"id" => "0363",
259
- "first_name" => "Jane",
260
- "last_name" => "Jones",
261
- "email" => "jane@example.dom",
262
- "media" => {"email" => "jane@example.dom"}}
263
- ]
264
- }
265
-
266
- expect(Flapjack::Data::Semaphore).to receive(:new).
267
- with("contact_mass_update", {:redis => redis, :expiry => 30}).and_return(semaphore)
268
- existing = double(Flapjack::Data::Contact)
269
- expect(existing).to receive(:id).twice.and_return("0362")
270
- expect(existing).to receive(:delete!)
271
-
272
- expect(Flapjack::Data::Contact).to receive(:all).with(:redis => redis).and_return([existing])
273
- expect(Flapjack::Data::Contact).to receive(:add).with(contacts['contacts'][0], :redis => redis)
274
- expect(semaphore).to receive(:release).and_return(true)
275
-
276
- apost "/contacts_atomic", contacts.to_json, {'CONTENT_TYPE' => JSON_REQUEST_MIME}
277
- expect(last_response.status).to eq(204)
278
- end
279
-
280
- it "lists a contact's notification rules" do
281
- notification_rule_2 = double(Flapjack::Data::NotificationRule, :id => '2', :contact_id => '21')
282
- expect(notification_rule).to receive(:to_json).and_return('"rule_1"')
283
- expect(notification_rule_2).to receive(:to_json).and_return('"rule_2"')
284
- notification_rules = [ notification_rule, notification_rule_2 ]
285
-
286
- expect(contact).to receive(:notification_rules).and_return(notification_rules)
287
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
288
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
289
-
290
- aget "/contacts/#{contact.id}/notification_rules"
291
- expect(last_response).to be_ok
292
- expect(last_response.body).to eq('["rule_1","rule_2"]')
293
- end
294
-
295
- it "does not list notification rules for a contact that does not exist" do
296
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
297
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
298
-
299
- aget "/contacts/#{contact.id}/notification_rules"
300
- expect(last_response.status).to eq(404)
301
- end
302
-
303
175
  it "returns a specified notification rule" do
304
176
  expect(notification_rule).to receive(:to_json).and_return('"rule_1"')
305
177
  expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
@@ -349,14 +221,6 @@ describe 'Flapjack::Gateways::JSONAPI::ContactMethods', :sinatra => true, :logge
349
221
  expect(last_response.status).to eq(404)
350
222
  end
351
223
 
352
- it "does not create a notification_rule if a rule id is provided" do
353
- expect(contact).not_to receive(:add_notification_rule)
354
-
355
- apost "/notification_rules", {"notification_rules" => [notification_rule_data.merge(:id => 1)]}.to_json,
356
- {'CONTENT_TYPE' => JSON_REQUEST_MIME}
357
- expect(last_response.status).to eq(422)
358
- end
359
-
360
224
  # PUT /notification_rules/RULE_ID
361
225
  it "updates a notification rule" do
362
226
  expect(Flapjack::Data::Contact).to receive(:find_by_id).
@@ -431,400 +295,24 @@ describe 'Flapjack::Gateways::JSONAPI::ContactMethods', :sinatra => true, :logge
431
295
  expect(last_response.status).to eq(404)
432
296
  end
433
297
 
434
- # GET /contacts/CONTACT_ID/media
435
- it "returns the media of a contact" do
436
- expect(contact).to receive(:media).and_return(media)
437
- expect(contact).to receive(:media_intervals).and_return(media_intervals)
438
- expect(contact).to receive(:media_rollup_thresholds).and_return(media_rollup_thresholds)
439
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
440
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
441
- result = Hash[ *(media.keys.collect {|m|
442
- [m, {'address' => media[m],
443
- 'interval' => media_intervals[m],
444
- 'rollup_threshold' => media_rollup_thresholds[m] }]
445
- }).flatten(1)].to_json
446
-
447
- aget "/contacts/#{contact.id}/media"
448
- expect(last_response).to be_ok
449
- expect(last_response.body).to eq(result)
450
- end
451
-
452
- it "does not return the media of a contact if the contact is not present" do
453
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
454
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
455
-
456
- aget "/contacts/#{contact.id}/media"
457
- expect(last_response.status).to eq(404)
458
- end
459
-
460
- # GET /contacts/CONTACT_ID/media/MEDIA
461
- it "returns the specified media of a contact" do
462
- expect(contact).to receive(:media).and_return(media)
463
- expect(contact).to receive(:media_intervals).and_return(media_intervals)
464
- expect(contact).to receive(:media_rollup_thresholds).and_return(media_rollup_thresholds)
465
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
466
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
467
-
468
- result = {
469
- 'address' => media['sms'],
470
- 'interval' => media_intervals['sms'],
471
- 'rollup_threshold' => media_rollup_thresholds['sms'],
472
- }
473
-
474
- aget "/contacts/#{contact.id}/media/sms"
475
- expect(last_response).to be_ok
476
- expect(last_response.body).to eq(result.to_json)
477
- end
478
-
479
- it "does not return the media of a contact if the contact is not present" do
480
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
481
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
482
-
483
- aget "/contacts/#{contact.id}/media/sms"
484
- expect(last_response.status).to eq(404)
485
- end
486
-
487
- it "does not return the media of a contact if the media is not present" do
488
- expect(contact).to receive(:media).and_return(media)
489
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
490
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
491
-
492
- aget "/contacts/#{contact.id}/media/telepathy"
493
- expect(last_response.status).to eq(404)
494
- end
495
-
496
- # PUT, DELETE /contacts/CONTACT_ID/media/MEDIA
497
- it "creates/updates a media of a contact" do
498
- # as far as API is concerned these are the same -- contact.rb spec test
499
- # may distinguish between them
500
- alt_media = media.merge('sms' => '04987654321')
501
- alt_media_intervals = media_intervals.merge('sms' => '200')
502
- alt_media_rollup_thresholds = media_rollup_thresholds.merge('sms' => '5')
503
-
504
- expect(contact).to receive(:set_address_for_media).with('sms', '04987654321')
505
- expect(contact).to receive(:set_interval_for_media).with('sms', '200')
506
- expect(contact).to receive(:set_rollup_threshold_for_media).with('sms', '5')
507
- expect(contact).to receive(:media).and_return(alt_media)
508
- expect(contact).to receive(:media_intervals).and_return(alt_media_intervals)
509
- expect(contact).to receive(:media_rollup_thresholds).and_return(alt_media_rollup_thresholds)
510
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
511
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
512
-
513
- result = {'address' => alt_media['sms'],
514
- 'interval' => alt_media_intervals['sms'],
515
- 'rollup_threshold' => alt_media_rollup_thresholds['sms']}
516
-
517
- aput "/contacts/#{contact.id}/media/sms", :address => '04987654321',
518
- :interval => '200', :rollup_threshold => '5'
519
- expect(last_response).to be_ok
520
- expect(last_response.body).to eq(result.to_json)
521
- end
522
-
523
- it "updates a contact's pagerduty media credentials" do
524
- result = {'service_key' => "flapjacktest@conference.jabber.sausage.net",
525
- 'subdomain' => "sausage.pagerduty.com",
526
- 'username' => "sausage@example.com",
527
- 'password' => "sausage"}
528
-
529
- expect(contact).to receive(:set_pagerduty_credentials).with(result)
530
- expect(contact).to receive(:pagerduty_credentials).and_return(result)
531
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
532
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
533
-
534
- aput "/contacts/#{contact.id}/media/pagerduty", :service_key => result['service_key'],
535
- :subdomain => result['subdomain'], :username => result['username'],
536
- :password => result['password']
537
-
538
- expect(last_response).to be_ok
539
- expect(last_response.body).to eq(result.to_json)
540
- end
541
-
542
- it "does not create a media of a contact that's not present" do
543
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
544
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
545
-
546
- aput "/contacts/#{contact.id}/media/sms", :address => '04987654321', :interval => '200'
547
- expect(last_response.status).to eq(404)
548
- end
549
-
550
- it "does not create a media of a contact if no address is provided" do
551
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
552
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
553
-
554
- aput "/contacts/#{contact.id}/media/sms", :interval => '200'
555
- expect(last_response.status).to eq(422)
556
- end
557
-
558
- it "creates a media of a contact even if no interval is provided" do
559
- alt_media = media.merge('sms' => '04987654321')
560
- alt_media_intervals = media_intervals.merge('sms' => nil)
561
- alt_media_rollup_thresholds = media_rollup_thresholds.merge('sms' => nil)
562
-
563
- expect(contact).to receive(:set_address_for_media).with('sms', '04987654321')
564
- expect(contact).to receive(:set_interval_for_media).with('sms', nil)
565
- expect(contact).to receive(:set_rollup_threshold_for_media).with("sms", nil)
566
- expect(contact).to receive(:media).and_return(alt_media)
567
- expect(contact).to receive(:media_intervals).and_return(alt_media_intervals)
568
- expect(contact).to receive(:media_rollup_thresholds).and_return(alt_media_rollup_thresholds)
569
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
570
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
571
-
572
- aput "/contacts/#{contact.id}/media/sms", :address => '04987654321'
573
- expect(last_response).to be_ok
574
- end
575
-
576
- it "deletes a media of a contact" do
577
- expect(contact).to receive(:remove_media).with('sms')
578
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
579
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
580
-
581
- adelete "/contacts/#{contact.id}/media/sms"
582
- expect(last_response.status).to eq(204)
583
- end
584
-
585
- it "does not delete a media of a contact that's not present" do
586
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
587
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
588
-
589
- adelete "/contacts/#{contact.id}/media/sms"
590
- expect(last_response.status).to eq(404)
591
- end
592
-
593
- # GET /contacts/CONTACT_ID/timezone
594
- it "returns the timezone of a contact" do
595
- expect(contact).to receive(:timezone).and_return(::ActiveSupport::TimeZone.new('Australia/Sydney'))
596
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
597
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
598
-
599
- aget "/contacts/#{contact.id}/timezone"
600
- expect(last_response).to be_ok
601
- expect(last_response.body).to eq('"Australia/Sydney"')
602
- end
603
-
604
- it "doesn't get the timezone of a contact that doesn't exist" do
605
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
606
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
607
-
608
- aget "/contacts/#{contact.id}/timezone"
609
- expect(last_response.status).to eq(404)
610
- end
611
-
612
- # PUT /contacts/CONTACT_ID/timezone
613
- it "sets the timezone of a contact" do
614
- expect(contact).to receive(:timezone=).with('Australia/Perth')
615
- expect(contact).to receive(:timezone).and_return(ActiveSupport::TimeZone.new('Australia/Perth'))
616
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
617
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
618
-
619
- aput "/contacts/#{contact.id}/timezone", {:timezone => 'Australia/Perth'}
620
- expect(last_response).to be_ok
621
- end
622
-
623
- it "doesn't set the timezone of a contact who can't be found" do
624
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
625
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
626
-
627
- aput "/contacts/#{contact.id}/timezone", {:timezone => 'Australia/Perth'}
628
- expect(last_response.status).to eq(404)
629
- end
630
-
631
- # DELETE /contacts/CONTACT_ID/timezone
632
- it "deletes the timezone of a contact" do
633
- expect(contact).to receive(:timezone=).with(nil)
634
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
635
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
636
-
637
- adelete "/contacts/#{contact.id}/timezone"
638
- expect(last_response.status).to eq(204)
639
- end
640
-
641
- it "does not delete the timezone of a contact that's not present" do
642
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
643
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
644
-
645
- adelete "/contacts/#{contact.id}/timezone"
646
- expect(last_response.status).to eq(404)
647
- end
648
-
649
- it "sets a single tag on a contact and returns current tags" do
650
- expect(contact).to receive(:add_tags).with('web')
651
- expect(contact).to receive(:tags).and_return(['web'])
652
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
653
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
654
-
655
- apost "contacts/#{contact.id}/tags", {:tags => ['web']}.to_json, {'CONTENT_TYPE' => JSON_REQUEST_MIME}
656
- expect(last_response).to be_ok
657
- expect(last_response.body).to eq({:tags => ['web']}.to_json)
658
- end
659
-
660
- it "does not set a single tag on a contact that's not found" do
661
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
662
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
663
-
664
- apost "contacts/#{contact.id}/tags", {:tags => ['web']}.to_json, {'CONTENT_TYPE' => JSON_REQUEST_MIME}
665
- expect(last_response.status).to eq(404)
666
- end
298
+ it "returns the media of a contact"
667
299
 
668
- it "sets multiple tags on a contact and returns current tags" do
669
- expect(contact).to receive(:add_tags).with('web', 'app')
670
- expect(contact).to receive(:tags).and_return(['web', 'app'])
671
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
672
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
300
+ it "returns the specified media of a contact"
673
301
 
674
- apost "contacts/#{contact.id}/tags", {:tags => ['web', 'app']}.to_json, {'CONTENT_TYPE' => JSON_REQUEST_MIME}
675
- expect(last_response).to be_ok
676
- expect(last_response.body).to eq({:tags => ['web', 'app']}.to_json)
677
- end
302
+ it "does not return the media of a contact if the media is not present"
678
303
 
679
- it "does not set multiple tags on a contact that's not found" do
680
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
681
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
304
+ it "creates/updates a media of a contact"
682
305
 
683
- apost "contacts/#{contact.id}/tags", {:tags => ['web', 'app']}.to_json, {'CONTENT_TYPE' => JSON_REQUEST_MIME}
684
- expect(last_response.status).to eq(404)
685
- end
306
+ it "updates a contact's pagerduty media credentials"
686
307
 
687
- it "removes a single tag from a contact" do
688
- expect(contact).to receive(:delete_tags).with('web')
689
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
690
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
308
+ it "does not create a media of a contact that's not present"
691
309
 
692
- adelete "contacts/#{contact.id}/tags", {:tags => ['web']}.to_json, {'CONTENT_TYPE' => JSON_REQUEST_MIME}
693
- expect(last_response.status).to eq(204)
694
- end
310
+ it "does not create a media of a contact if no address is provided"
695
311
 
696
- it "does not remove a single tag from a contact that's not found" do
697
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
698
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
312
+ it "creates a media of a contact even if no interval is provided"
699
313
 
700
- adelete "contacts/#{contact.id}/tags", {:tags => ['web']}.to_json, {'CONTENT_TYPE' => JSON_REQUEST_MIME}
701
- expect(last_response.status).to eq(404)
702
- end
703
-
704
- it "removes multiple tags from a contact" do
705
- expect(contact).to receive(:delete_tags).with('web', 'app')
706
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
707
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
708
-
709
- adelete "contacts/#{contact.id}/tags", {:tags => ['web', 'app']}.to_json, {'CONTENT_TYPE' => JSON_REQUEST_MIME}
710
- expect(last_response.status).to eq(204)
711
- end
712
-
713
- it "does not remove multiple tags from a contact that's not found" do
714
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
715
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
716
-
717
- adelete "contacts/#{contact.id}/tags", {:tags => ['web', 'app']}.to_json, {'CONTENT_TYPE' => JSON_REQUEST_MIME}
718
- expect(last_response.status).to eq(404)
719
- end
720
-
721
- it "gets all tags on a contact" do
722
- expect(contact).to receive(:tags).and_return(['web', 'app'])
723
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
724
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
725
-
726
- aget "contacts/#{contact.id}/tags"
727
- expect(last_response).to be_ok
728
- expect(last_response.body).to eq({"tags"=>['web', 'app']}.to_json)
729
- end
730
-
731
- it "does not get all tags on a contact that's not found" do
732
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
733
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
734
-
735
- aget "contacts/#{contact.id}/tags"
736
- expect(last_response.status).to eq(404)
737
- end
738
-
739
- it "gets all entity tags for a contact" do
740
- entity_1 = double(Flapjack::Data::Entity)
741
- expect(entity_1).to receive(:name).and_return('entity_1')
742
- entity_2 = double(Flapjack::Data::Entity)
743
- expect(entity_2).to receive(:name).and_return('entity_2')
744
- tag_data = [{:entity => entity_1, :tags => ['web']},
745
- {:entity => entity_2, :tags => ['app']}]
746
- expect(contact).to receive(:entities).with(:tags => true).
747
- and_return(tag_data)
748
-
749
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
750
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
751
-
752
- aget "contacts/#{contact.id}/entity_tags"
753
- expect(last_response).to be_ok
754
- tag_response = {'entity_1' => ['web'],
755
- 'entity_2' => ['app']}
756
- expect(last_response.body).to eq(tag_response.to_json)
757
- end
758
-
759
- it "does not get all entity tags for a contact that's not found" do
760
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
761
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
762
-
763
- aget "contacts/#{contact.id}/entity_tags"
764
- expect(last_response.status).to eq(404)
765
- end
766
-
767
- it "adds tags to multiple entities for a contact" do
768
- entity_1 = double(Flapjack::Data::Entity)
769
- expect(entity_1).to receive(:name).twice.and_return('entity_1')
770
- expect(entity_1).to receive(:add_tags).with('web')
771
- entity_2 = double(Flapjack::Data::Entity)
772
- expect(entity_2).to receive(:name).twice.and_return('entity_2')
773
- expect(entity_2).to receive(:add_tags).with('app')
774
-
775
- entities = [{:entity => entity_1}, {:entity => entity_2}]
776
- expect(contact).to receive(:entities).and_return(entities)
777
- tag_data = [{:entity => entity_1, :tags => ['web']},
778
- {:entity => entity_2, :tags => ['app']}]
779
- expect(contact).to receive(:entities).with(:tags => true).and_return(tag_data)
780
-
781
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
782
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
783
-
784
- apost "contacts/#{contact.id}/entity_tags",
785
- :entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
786
- expect(last_response).to be_ok
787
- tag_response = {'entity_1' => ['web'],
788
- 'entity_2' => ['app']}
789
- expect(last_response.body).to eq(tag_response.to_json)
790
- end
791
-
792
- it "does not add tags to multiple entities for a contact that's not found" do
793
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
794
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
795
-
796
- apost "contacts/#{contact.id}/entity_tags",
797
- :entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
798
- expect(last_response.status).to eq(404)
799
- end
800
-
801
- it "deletes tags from multiple entities for a contact" do
802
- entity_1 = double(Flapjack::Data::Entity)
803
- expect(entity_1).to receive(:name).and_return('entity_1')
804
- expect(entity_1).to receive(:delete_tags).with('web')
805
- entity_2 = double(Flapjack::Data::Entity)
806
- expect(entity_2).to receive(:name).and_return('entity_2')
807
- expect(entity_2).to receive(:delete_tags).with('app')
808
-
809
- entities = [{:entity => entity_1}, {:entity => entity_2}]
810
- expect(contact).to receive(:entities).and_return(entities)
811
-
812
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
813
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
814
-
815
- adelete "contacts/#{contact.id}/entity_tags",
816
- :entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
817
- expect(last_response.status).to eq(204)
818
- end
819
-
820
- it "does not delete tags from multiple entities for a contact that's not found" do
821
- expect(Flapjack::Data::Contact).to receive(:find_by_id).
822
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
823
-
824
- adelete "contacts/#{contact.id}/entity_tags",
825
- :entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
826
- expect(last_response.status).to eq(404)
827
- end
314
+ it "deletes a media of a contact"
828
315
 
316
+ it "does not delete a media of a contact that's not present"
829
317
 
830
318
  end