flapjack 0.9.6 → 1.0.0rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rspec +6 -0
- data/.travis.yml +20 -16
- data/CHANGELOG.md +11 -25
- data/Dockerfile +8 -0
- data/Gemfile +2 -5
- data/bin/flapjack +24 -213
- data/etc/flapjack_config.yaml.example +6 -30
- data/features/cli.feature +16 -14
- data/features/cli_flapjack-feed-events.feature +12 -13
- data/features/cli_flapjack-nagios-receiver.feature +14 -15
- data/features/cli_flapjack-populator.feature +16 -15
- data/features/cli_flapper.feature +12 -12
- data/features/cli_receive-events.feature +6 -5
- data/features/cli_simulate-failed-check.feature +7 -6
- data/features/steps/cli_steps.rb +2 -2
- data/features/support/env.rb +1 -0
- data/flapjack.gemspec +1 -0
- data/lib/flapjack/cli/flapper.rb +200 -0
- data/lib/flapjack/cli/import.rb +102 -0
- data/lib/flapjack/cli/receiver.rb +656 -0
- data/lib/flapjack/cli/server.rb +256 -0
- data/lib/flapjack/cli/simulate.rb +180 -0
- data/lib/flapjack/configuration.rb +2 -0
- data/lib/flapjack/data/entity_check.rb +5 -22
- data/lib/flapjack/data/event.rb +7 -12
- data/lib/flapjack/gateways/email.rb +4 -1
- data/lib/flapjack/gateways/jabber.rb +12 -36
- data/lib/flapjack/gateways/jsonapi/check_presenter.rb +6 -6
- data/lib/flapjack/gateways/jsonapi/report_methods.rb +5 -3
- data/lib/flapjack/gateways/pagerduty.rb +1 -1
- data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +1 -1
- data/lib/flapjack/gateways/web/public/js/modules/contact.js +2 -2
- data/lib/flapjack/gateways/web/public/js/modules/entity.js +2 -2
- data/lib/flapjack/gateways/web/public/js/modules/medium.js +4 -4
- data/lib/flapjack/gateways/web/public/js/self_stats.js +1 -1
- data/lib/flapjack/gateways/web/views/check.html.erb +7 -7
- data/lib/flapjack/gateways/web/views/checks.html.erb +2 -3
- data/lib/flapjack/gateways/web/views/contact.html.erb +4 -4
- data/lib/flapjack/gateways/web/views/contacts.html.erb +2 -2
- data/lib/flapjack/gateways/web/views/edit_contacts.html.erb +1 -1
- data/lib/flapjack/gateways/web/views/entities.html.erb +1 -1
- data/lib/flapjack/gateways/web/views/entity.html.erb +1 -1
- data/lib/flapjack/gateways/web/views/index.html.erb +2 -2
- data/lib/flapjack/gateways/web/views/layout.erb +10 -10
- data/lib/flapjack/gateways/web/views/self_stats.html.erb +1 -1
- data/lib/flapjack/gateways/web.rb +36 -7
- data/lib/flapjack/pikelet.rb +0 -2
- data/lib/flapjack/processor.rb +3 -1
- data/lib/flapjack/redis_pool.rb +2 -6
- data/lib/flapjack/version.rb +1 -1
- data/spec/lib/flapjack/coordinator_spec.rb +3 -3
- data/spec/lib/flapjack/data/entity_check_spec.rb +2 -6
- data/spec/lib/flapjack/data/event_spec.rb +0 -31
- data/spec/lib/flapjack/gateways/email_spec.rb +109 -0
- data/spec/lib/flapjack/gateways/jabber_spec.rb +18 -16
- data/spec/lib/flapjack/gateways/jsonapi/check_presenter_spec.rb +12 -24
- data/spec/lib/flapjack/gateways/pagerduty_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/web/views/check.html.erb_spec.rb +2 -0
- data/spec/lib/flapjack/gateways/web/views/contact.html.erb_spec.rb +2 -0
- data/spec/lib/flapjack/gateways/web/views/index.html.erb_spec.rb +2 -0
- data/spec/lib/flapjack/gateways/web_spec.rb +194 -145
- data/spec/lib/flapjack/redis_pool_spec.rb +0 -1
- data/spec/support/profile_all_formatter.rb +44 -0
- data/spec/support/uncolored_doc_formatter.rb +9 -0
- data/tasks/benchmarks.rake +0 -4
- metadata +28 -38
- data/.ruby-version +0 -1
- data/Gemfile-ruby1.9 +0 -28
- data/Gemfile-ruby1.9.lock +0 -227
- data/bin/flapjack-feed-events +0 -124
- data/bin/flapjack-nagios-receiver +0 -246
- data/bin/flapjack-nsca-receiver +0 -246
- data/bin/flapjack-populator +0 -132
- data/bin/flapper +0 -152
- data/bin/receive-events +0 -179
- data/bin/simulate-failed-check +0 -151
- data/lib/flapjack/data/migration.rb +0 -36
- data/lib/flapjack/gateways/api/contact_methods.rb +0 -369
- data/lib/flapjack/gateways/api/entity_check_presenter.rb +0 -218
- data/lib/flapjack/gateways/api/entity_methods.rb +0 -361
- data/lib/flapjack/gateways/api/entity_presenter.rb +0 -75
- data/lib/flapjack/gateways/api/rack/json_params_parser.rb +0 -26
- data/lib/flapjack/gateways/api.rb +0 -124
- data/spec/lib/flapjack/gateways/api/contact_methods_spec.rb +0 -772
- data/spec/lib/flapjack/gateways/api/entity_check_presenter_spec.rb +0 -211
- data/spec/lib/flapjack/gateways/api/entity_methods_spec.rb +0 -863
- data/spec/lib/flapjack/gateways/api/entity_presenter_spec.rb +0 -108
- data/spec/lib/flapjack/gateways/api_spec.rb +0 -30
@@ -1,772 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'flapjack/gateways/api'
|
3
|
-
|
4
|
-
describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger => true do
|
5
|
-
|
6
|
-
def app
|
7
|
-
Flapjack::Gateways::API
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:contact) { double(Flapjack::Data::Contact, :id => '21') }
|
11
|
-
let(:contact_core) {
|
12
|
-
{'id' => contact.id,
|
13
|
-
'first_name' => "Ada",
|
14
|
-
'last_name' => "Lovelace",
|
15
|
-
'email' => "ada@example.com",
|
16
|
-
'tags' => ["legend", "first computer programmer"]
|
17
|
-
}
|
18
|
-
}
|
19
|
-
|
20
|
-
let(:media) {
|
21
|
-
{'email' => 'ada@example.com',
|
22
|
-
'sms' => '04123456789'
|
23
|
-
}
|
24
|
-
}
|
25
|
-
|
26
|
-
let(:media_intervals) {
|
27
|
-
{'email' => 500,
|
28
|
-
'sms' => 300
|
29
|
-
}
|
30
|
-
}
|
31
|
-
|
32
|
-
let(:media_rollup_thresholds) {
|
33
|
-
{'email' => 5}
|
34
|
-
}
|
35
|
-
|
36
|
-
let(:redis) { double(::Redis) }
|
37
|
-
|
38
|
-
let(:notification_rule) {
|
39
|
-
double(Flapjack::Data::NotificationRule, :id => '1', :contact_id => '21')
|
40
|
-
}
|
41
|
-
|
42
|
-
let(:notification_rule_data) {
|
43
|
-
{"contact_id" => "21",
|
44
|
-
"tags" => ["database","physical"],
|
45
|
-
"regex_tags" => ["^data.*$","^(physical|bare_metal)$"],
|
46
|
-
"entities" => ["foo-app-01.example.com"],
|
47
|
-
"regex_entities" => ["^foo-\S{3}-\d{2}.example.com$"],
|
48
|
-
"time_restrictions" => nil,
|
49
|
-
"unknown_media" => ["jabber"],
|
50
|
-
"warning_media" => ["email"],
|
51
|
-
"critical_media" => ["sms", "email"],
|
52
|
-
"unknown_blackhole" => false,
|
53
|
-
"warning_blackhole" => false,
|
54
|
-
"critical_blackhole" => false
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
before(:all) do
|
59
|
-
Flapjack::Gateways::API.class_eval {
|
60
|
-
set :raise_errors, true
|
61
|
-
}
|
62
|
-
end
|
63
|
-
|
64
|
-
before(:each) do
|
65
|
-
expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
|
66
|
-
Flapjack::Gateways::API.instance_variable_set('@config', {})
|
67
|
-
Flapjack::Gateways::API.instance_variable_set('@logger', @logger)
|
68
|
-
Flapjack::Gateways::API.start
|
69
|
-
end
|
70
|
-
|
71
|
-
it "creates contacts from a submitted list" do
|
72
|
-
contacts = {'contacts' =>
|
73
|
-
[{"id" => "0362",
|
74
|
-
"first_name" => "John",
|
75
|
-
"last_name" => "Smith",
|
76
|
-
"email" => "johns@example.dom",
|
77
|
-
"media" => {"email" => "johns@example.dom",
|
78
|
-
"jabber" => "johns@conference.localhost"}},
|
79
|
-
{"id" => "0363",
|
80
|
-
"first_name" => "Jane",
|
81
|
-
"last_name" => "Jones",
|
82
|
-
"email" => "jane@example.dom",
|
83
|
-
"media" => {"email" => "jane@example.dom"}}
|
84
|
-
]
|
85
|
-
}
|
86
|
-
|
87
|
-
expect(Flapjack::Data::Contact).to receive(:all).with(:redis => redis).and_return([])
|
88
|
-
expect(Flapjack::Data::Contact).to receive(:add).twice
|
89
|
-
|
90
|
-
apost "/contacts", contacts.to_json, {'CONTENT_TYPE' => 'application/json'}
|
91
|
-
expect(last_response.status).to eq(204)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "does not create contacts if the data is improperly formatted" do
|
95
|
-
expect(Flapjack::Data::Contact).not_to receive(:add)
|
96
|
-
|
97
|
-
apost "/contacts", {'contacts' => ["Hello", "again"]}.to_json,
|
98
|
-
{'CONTENT_TYPE' => 'application/json'}
|
99
|
-
expect(last_response.status).to eq(403)
|
100
|
-
end
|
101
|
-
|
102
|
-
it "does not create contacts if they don't contain an id" do
|
103
|
-
contacts = {'contacts' =>
|
104
|
-
[{"id" => "0362",
|
105
|
-
"first_name" => "John",
|
106
|
-
"last_name" => "Smith",
|
107
|
-
"email" => "johns@example.dom",
|
108
|
-
"media" => {"email" => "johns@example.dom",
|
109
|
-
"jabber" => "johns@conference.localhost"}},
|
110
|
-
{"first_name" => "Jane",
|
111
|
-
"last_name" => "Jones",
|
112
|
-
"email" => "jane@example.dom",
|
113
|
-
"media" => {"email" => "jane@example.dom"}}
|
114
|
-
]
|
115
|
-
}
|
116
|
-
|
117
|
-
expect(Flapjack::Data::Contact).to receive(:all).with(:redis => redis).and_return([])
|
118
|
-
expect(Flapjack::Data::Contact).to receive(:add)
|
119
|
-
|
120
|
-
apost "/contacts", contacts.to_json, {'CONTENT_TYPE' => 'application/json'}
|
121
|
-
expect(last_response.status).to eq(204)
|
122
|
-
end
|
123
|
-
|
124
|
-
it "updates a contact if it is already present" do
|
125
|
-
contacts = {'contacts' =>
|
126
|
-
[{"id" => "0362",
|
127
|
-
"first_name" => "John",
|
128
|
-
"last_name" => "Smith",
|
129
|
-
"email" => "johns@example.dom",
|
130
|
-
"media" => {"email" => "johns@example.dom",
|
131
|
-
"jabber" => "johns@conference.localhost"}},
|
132
|
-
{"id" => "0363",
|
133
|
-
"first_name" => "Jane",
|
134
|
-
"last_name" => "Jones",
|
135
|
-
"email" => "jane@example.dom",
|
136
|
-
"media" => {"email" => "jane@example.dom"}}
|
137
|
-
]
|
138
|
-
}
|
139
|
-
|
140
|
-
existing = double(Flapjack::Data::Contact)
|
141
|
-
expect(existing).to receive(:id).and_return("0363")
|
142
|
-
expect(existing).to receive(:update).with(contacts['contacts'][1])
|
143
|
-
|
144
|
-
expect(Flapjack::Data::Contact).to receive(:all).with(:redis => redis).and_return([existing])
|
145
|
-
expect(Flapjack::Data::Contact).to receive(:add).with(contacts['contacts'][0], :redis => redis)
|
146
|
-
|
147
|
-
apost "/contacts", contacts.to_json, {'CONTENT_TYPE' => 'application/json'}
|
148
|
-
expect(last_response.status).to eq(204)
|
149
|
-
end
|
150
|
-
|
151
|
-
it "deletes a contact not found in a bulk update list" do
|
152
|
-
contacts = {'contacts' =>
|
153
|
-
[{"id" => "0363",
|
154
|
-
"first_name" => "Jane",
|
155
|
-
"last_name" => "Jones",
|
156
|
-
"email" => "jane@example.dom",
|
157
|
-
"media" => {"email" => "jane@example.dom"}}
|
158
|
-
]
|
159
|
-
}
|
160
|
-
|
161
|
-
existing = double(Flapjack::Data::Contact)
|
162
|
-
expect(existing).to receive(:id).twice.and_return("0362")
|
163
|
-
expect(existing).to receive(:delete!)
|
164
|
-
|
165
|
-
expect(Flapjack::Data::Contact).to receive(:all).with(:redis => redis).and_return([existing])
|
166
|
-
expect(Flapjack::Data::Contact).to receive(:add).with(contacts['contacts'][0], :redis => redis)
|
167
|
-
|
168
|
-
apost "/contacts", contacts.to_json, {'CONTENT_TYPE' => 'application/json'}
|
169
|
-
expect(last_response.status).to eq(204)
|
170
|
-
end
|
171
|
-
|
172
|
-
it "returns all the contacts" do
|
173
|
-
expect(contact).to receive(:to_json).and_return(contact_core.to_json)
|
174
|
-
expect(Flapjack::Data::Contact).to receive(:all).with(:redis => redis).
|
175
|
-
and_return([contact])
|
176
|
-
|
177
|
-
aget '/contacts'
|
178
|
-
expect(last_response).to be_ok
|
179
|
-
expect(last_response.body).to eq([contact_core].to_json)
|
180
|
-
end
|
181
|
-
|
182
|
-
it "returns the core information of a specified contact" do
|
183
|
-
expect(contact).to receive(:to_json).and_return(contact_core.to_json)
|
184
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
185
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
186
|
-
|
187
|
-
aget "/contacts/#{contact.id}"
|
188
|
-
expect(last_response).to be_ok
|
189
|
-
expect(last_response.body).to eq(contact_core.to_json)
|
190
|
-
end
|
191
|
-
|
192
|
-
it "does not return information for a contact that does not exist" do
|
193
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
194
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
195
|
-
|
196
|
-
aget "/contacts/#{contact.id}"
|
197
|
-
expect(last_response).to be_forbidden
|
198
|
-
end
|
199
|
-
|
200
|
-
it "lists a contact's notification rules" do
|
201
|
-
notification_rule_2 = double(Flapjack::Data::NotificationRule, :id => '2', :contact_id => '21')
|
202
|
-
expect(notification_rule).to receive(:to_json).and_return('"rule_1"')
|
203
|
-
expect(notification_rule_2).to receive(:to_json).and_return('"rule_2"')
|
204
|
-
notification_rules = [ notification_rule, notification_rule_2 ]
|
205
|
-
|
206
|
-
expect(contact).to receive(:notification_rules).and_return(notification_rules)
|
207
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
208
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
209
|
-
|
210
|
-
aget "/contacts/#{contact.id}/notification_rules"
|
211
|
-
expect(last_response).to be_ok
|
212
|
-
expect(last_response.body).to eq('["rule_1","rule_2"]')
|
213
|
-
end
|
214
|
-
|
215
|
-
it "does not list notification rules for a contact that does not exist" do
|
216
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
217
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
218
|
-
|
219
|
-
aget "/contacts/#{contact.id}/notification_rules"
|
220
|
-
expect(last_response).to be_forbidden
|
221
|
-
end
|
222
|
-
|
223
|
-
it "returns a specified notification rule" do
|
224
|
-
expect(notification_rule).to receive(:to_json).and_return('"rule_1"')
|
225
|
-
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
226
|
-
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
|
227
|
-
|
228
|
-
aget "/notification_rules/#{notification_rule.id}"
|
229
|
-
expect(last_response).to be_ok
|
230
|
-
expect(last_response.body).to eq('"rule_1"')
|
231
|
-
end
|
232
|
-
|
233
|
-
it "does not return a notification rule that does not exist" do
|
234
|
-
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
235
|
-
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
236
|
-
|
237
|
-
aget "/notification_rules/#{notification_rule.id}"
|
238
|
-
expect(last_response).to be_forbidden
|
239
|
-
end
|
240
|
-
|
241
|
-
# POST /notification_rules
|
242
|
-
it "creates a new notification rule" do
|
243
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
244
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
245
|
-
expect(notification_rule).to receive(:respond_to?).with(:critical_media).and_return(true)
|
246
|
-
expect(notification_rule).to receive(:to_json).and_return('"rule_1"')
|
247
|
-
|
248
|
-
# symbolize the keys
|
249
|
-
notification_rule_data_sym = notification_rule_data.inject({}){|memo,(k,v)|
|
250
|
-
memo[k.to_sym] = v; memo
|
251
|
-
}
|
252
|
-
notification_rule_data_sym.delete(:contact_id)
|
253
|
-
|
254
|
-
expect(contact).to receive(:add_notification_rule).
|
255
|
-
with(notification_rule_data_sym, :logger => @logger).and_return(notification_rule)
|
256
|
-
|
257
|
-
apost "/notification_rules", notification_rule_data.to_json,
|
258
|
-
{'CONTENT_TYPE' => 'application/json'}
|
259
|
-
expect(last_response).to be_ok
|
260
|
-
expect(last_response.body).to eq('"rule_1"')
|
261
|
-
end
|
262
|
-
|
263
|
-
it "does not create a notification_rule for a contact that's not present" do
|
264
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
265
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
266
|
-
|
267
|
-
apost "/notification_rules", notification_rule_data.to_json,
|
268
|
-
{'CONTENT_TYPE' => 'application/json'}
|
269
|
-
expect(last_response).to be_forbidden
|
270
|
-
end
|
271
|
-
|
272
|
-
it "does not create a notification_rule if a rule id is provided" do
|
273
|
-
expect(contact).not_to receive(:add_notification_rule)
|
274
|
-
|
275
|
-
apost "/notification_rules", notification_rule_data.merge(:id => 1).to_json,
|
276
|
-
{'CONTENT_TYPE' => 'application/json'}
|
277
|
-
expect(last_response.status).to eq(403)
|
278
|
-
end
|
279
|
-
|
280
|
-
# PUT /notification_rules/RULE_ID
|
281
|
-
it "updates a notification rule" do
|
282
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
283
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
284
|
-
expect(notification_rule).to receive(:to_json).and_return('"rule_1"')
|
285
|
-
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
286
|
-
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
|
287
|
-
|
288
|
-
# symbolize the keys
|
289
|
-
notification_rule_data_sym = notification_rule_data.inject({}){|memo,(k,v)|
|
290
|
-
memo[k.to_sym] = v; memo
|
291
|
-
}
|
292
|
-
notification_rule_data_sym.delete(:contact_id)
|
293
|
-
|
294
|
-
expect(notification_rule).to receive(:update).with(notification_rule_data_sym, :logger => @logger).and_return(nil)
|
295
|
-
|
296
|
-
aput "/notification_rules/#{notification_rule.id}", notification_rule_data.to_json,
|
297
|
-
{'CONTENT_TYPE' => 'application/json'}
|
298
|
-
expect(last_response).to be_ok
|
299
|
-
expect(last_response.body).to eq('"rule_1"')
|
300
|
-
end
|
301
|
-
|
302
|
-
it "does not update a notification rule that's not present" do
|
303
|
-
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
304
|
-
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
305
|
-
|
306
|
-
aput "/notification_rules/#{notification_rule.id}", notification_rule_data
|
307
|
-
expect(last_response).to be_forbidden
|
308
|
-
end
|
309
|
-
|
310
|
-
it "does not update a notification_rule for a contact that's not present" do
|
311
|
-
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
312
|
-
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
|
313
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
314
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
315
|
-
|
316
|
-
aput "/notification_rules/#{notification_rule.id}", notification_rule_data.to_json,
|
317
|
-
{'CONTENT_TYPE' => 'application/json'}
|
318
|
-
expect(last_response).to be_forbidden
|
319
|
-
end
|
320
|
-
|
321
|
-
it 'uses the contact_id param if the rule being updated lacks that data' do
|
322
|
-
nr_nil = double(Flapjack::Data::NotificationRule, :id => '1', :contact_id => nil)
|
323
|
-
|
324
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
325
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
326
|
-
expect(nr_nil).to receive(:to_json).and_return('"rule_1"')
|
327
|
-
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
328
|
-
with(nr_nil.id, {:redis => redis, :logger => @logger}).and_return(nr_nil)
|
329
|
-
|
330
|
-
# symbolize the keys
|
331
|
-
notification_rule_data_sym = notification_rule_data.inject({}){|memo,(k,v)|
|
332
|
-
memo[k.to_sym] = v; memo
|
333
|
-
}
|
334
|
-
notification_rule_data_sym.delete(:contact_id)
|
335
|
-
|
336
|
-
expect(nr_nil).to receive(:update).with(notification_rule_data_sym, :logger => @logger).and_return(nil)
|
337
|
-
|
338
|
-
aput "/notification_rules/#{nr_nil.id}", notification_rule_data.to_json,
|
339
|
-
{'CONTENT_TYPE' => 'application/json'}
|
340
|
-
expect(last_response).to be_ok
|
341
|
-
expect(last_response.body).to eq('"rule_1"')
|
342
|
-
end
|
343
|
-
|
344
|
-
# DELETE /notification_rules/RULE_ID
|
345
|
-
it "deletes a notification rule" do
|
346
|
-
expect(notification_rule).to receive(:contact_id).and_return(contact.id)
|
347
|
-
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
348
|
-
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
|
349
|
-
expect(contact).to receive(:delete_notification_rule).with(notification_rule)
|
350
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
351
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
352
|
-
|
353
|
-
adelete "/notification_rules/#{notification_rule.id}"
|
354
|
-
expect(last_response.status).to eq(204)
|
355
|
-
end
|
356
|
-
|
357
|
-
it "does not delete a notification rule that's not present" do
|
358
|
-
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
359
|
-
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
360
|
-
|
361
|
-
adelete "/notification_rules/#{notification_rule.id}"
|
362
|
-
expect(last_response).to be_forbidden
|
363
|
-
end
|
364
|
-
|
365
|
-
it "does not delete a notification rule if the contact is not present" do
|
366
|
-
expect(notification_rule).to receive(:contact_id).and_return(contact.id)
|
367
|
-
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
368
|
-
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
|
369
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
370
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
371
|
-
|
372
|
-
adelete "/notification_rules/#{notification_rule.id}"
|
373
|
-
expect(last_response).to be_forbidden
|
374
|
-
end
|
375
|
-
|
376
|
-
# GET /contacts/CONTACT_ID/media
|
377
|
-
it "returns the media of a contact" do
|
378
|
-
expect(contact).to receive(:media).and_return(media)
|
379
|
-
expect(contact).to receive(:media_intervals).and_return(media_intervals)
|
380
|
-
expect(contact).to receive(:media_rollup_thresholds).and_return(media_rollup_thresholds)
|
381
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
382
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
383
|
-
result = Hash[ *(media.keys.collect {|m|
|
384
|
-
[m, {'address' => media[m],
|
385
|
-
'interval' => media_intervals[m],
|
386
|
-
'rollup_threshold' => media_rollup_thresholds[m] }]
|
387
|
-
}).flatten(1)].to_json
|
388
|
-
|
389
|
-
aget "/contacts/#{contact.id}/media"
|
390
|
-
expect(last_response).to be_ok
|
391
|
-
expect(last_response.body).to eq(result)
|
392
|
-
end
|
393
|
-
|
394
|
-
it "does not return the media of a contact if the contact is not present" do
|
395
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
396
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
397
|
-
|
398
|
-
aget "/contacts/#{contact.id}/media"
|
399
|
-
expect(last_response).to be_forbidden
|
400
|
-
end
|
401
|
-
|
402
|
-
# GET /contacts/CONTACT_ID/media/MEDIA
|
403
|
-
it "returns the specified media of a contact" do
|
404
|
-
expect(contact).to receive(:media).and_return(media)
|
405
|
-
expect(contact).to receive(:media_intervals).and_return(media_intervals)
|
406
|
-
expect(contact).to receive(:media_rollup_thresholds).and_return(media_rollup_thresholds)
|
407
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
408
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
409
|
-
|
410
|
-
result = {
|
411
|
-
'address' => media['sms'],
|
412
|
-
'interval' => media_intervals['sms'],
|
413
|
-
'rollup_threshold' => media_rollup_thresholds['sms'],
|
414
|
-
}
|
415
|
-
|
416
|
-
aget "/contacts/#{contact.id}/media/sms"
|
417
|
-
expect(last_response).to be_ok
|
418
|
-
expect(last_response.body).to eq(result.to_json)
|
419
|
-
end
|
420
|
-
|
421
|
-
it "does not return the media of a contact if the contact is not present" do
|
422
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
423
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
424
|
-
|
425
|
-
aget "/contacts/#{contact.id}/media/sms"
|
426
|
-
expect(last_response).to be_forbidden
|
427
|
-
end
|
428
|
-
|
429
|
-
it "does not return the media of a contact if the media is not present" do
|
430
|
-
expect(contact).to receive(:media).and_return(media)
|
431
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
432
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
433
|
-
|
434
|
-
aget "/contacts/#{contact.id}/media/telepathy"
|
435
|
-
expect(last_response).to be_forbidden
|
436
|
-
end
|
437
|
-
|
438
|
-
# PUT, DELETE /contacts/CONTACT_ID/media/MEDIA
|
439
|
-
it "creates/updates a media of a contact" do
|
440
|
-
# as far as API is concerned these are the same -- contact.rb spec test
|
441
|
-
# may distinguish between them
|
442
|
-
alt_media = media.merge('sms' => '04987654321')
|
443
|
-
alt_media_intervals = media_intervals.merge('sms' => '200')
|
444
|
-
alt_media_rollup_thresholds = media_rollup_thresholds.merge('sms' => '5')
|
445
|
-
|
446
|
-
expect(contact).to receive(:set_address_for_media).with('sms', '04987654321')
|
447
|
-
expect(contact).to receive(:set_interval_for_media).with('sms', '200')
|
448
|
-
expect(contact).to receive(:set_rollup_threshold_for_media).with('sms', '5')
|
449
|
-
expect(contact).to receive(:media).and_return(alt_media)
|
450
|
-
expect(contact).to receive(:media_intervals).and_return(alt_media_intervals)
|
451
|
-
expect(contact).to receive(:media_rollup_thresholds).and_return(alt_media_rollup_thresholds)
|
452
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
453
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
454
|
-
|
455
|
-
result = {'address' => alt_media['sms'],
|
456
|
-
'interval' => alt_media_intervals['sms'],
|
457
|
-
'rollup_threshold' => alt_media_rollup_thresholds['sms']}
|
458
|
-
|
459
|
-
aput "/contacts/#{contact.id}/media/sms", :address => '04987654321',
|
460
|
-
:interval => '200', :rollup_threshold => '5'
|
461
|
-
expect(last_response).to be_ok
|
462
|
-
expect(last_response.body).to eq(result.to_json)
|
463
|
-
end
|
464
|
-
|
465
|
-
it "updates a contact's pagerduty media credentials" do
|
466
|
-
result = {'service_key' => "flapjacktest@conference.jabber.sausage.net",
|
467
|
-
'subdomain' => "sausage.pagerduty.com",
|
468
|
-
'username' => "sausage@example.com",
|
469
|
-
'password' => "sausage"}
|
470
|
-
|
471
|
-
expect(contact).to receive(:set_pagerduty_credentials).with(result)
|
472
|
-
expect(contact).to receive(:pagerduty_credentials).and_return(result)
|
473
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
474
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
475
|
-
|
476
|
-
aput "/contacts/#{contact.id}/media/pagerduty", :service_key => result['service_key'],
|
477
|
-
:subdomain => result['subdomain'], :username => result['username'],
|
478
|
-
:password => result['password']
|
479
|
-
|
480
|
-
expect(last_response).to be_ok
|
481
|
-
expect(last_response.body).to eq(result.to_json)
|
482
|
-
end
|
483
|
-
|
484
|
-
it "does not create a media of a contact that's not present" do
|
485
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
486
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
487
|
-
|
488
|
-
aput "/contacts/#{contact.id}/media/sms", :address => '04987654321', :interval => '200'
|
489
|
-
expect(last_response).to be_forbidden
|
490
|
-
end
|
491
|
-
|
492
|
-
it "does not create a media of a contact if no address is provided" do
|
493
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
494
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
495
|
-
|
496
|
-
aput "/contacts/#{contact.id}/media/sms", :interval => '200'
|
497
|
-
expect(last_response).to be_forbidden
|
498
|
-
end
|
499
|
-
|
500
|
-
it "creates a media of a contact even if no interval is provided" do
|
501
|
-
alt_media = media.merge('sms' => '04987654321')
|
502
|
-
alt_media_intervals = media_intervals.merge('sms' => nil)
|
503
|
-
alt_media_rollup_thresholds = media_rollup_thresholds.merge('sms' => nil)
|
504
|
-
|
505
|
-
expect(contact).to receive(:set_address_for_media).with('sms', '04987654321')
|
506
|
-
expect(contact).to receive(:set_interval_for_media).with('sms', nil)
|
507
|
-
expect(contact).to receive(:set_rollup_threshold_for_media).with("sms", nil)
|
508
|
-
expect(contact).to receive(:media).and_return(alt_media)
|
509
|
-
expect(contact).to receive(:media_intervals).and_return(alt_media_intervals)
|
510
|
-
expect(contact).to receive(:media_rollup_thresholds).and_return(alt_media_rollup_thresholds)
|
511
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
512
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
513
|
-
|
514
|
-
aput "/contacts/#{contact.id}/media/sms", :address => '04987654321'
|
515
|
-
expect(last_response).to be_ok
|
516
|
-
end
|
517
|
-
|
518
|
-
it "deletes a media of a contact" do
|
519
|
-
expect(contact).to receive(:remove_media).with('sms')
|
520
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
521
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
522
|
-
|
523
|
-
adelete "/contacts/#{contact.id}/media/sms"
|
524
|
-
expect(last_response.status).to eq(204)
|
525
|
-
end
|
526
|
-
|
527
|
-
it "does not delete a media of a contact that's not present" do
|
528
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
529
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
530
|
-
|
531
|
-
adelete "/contacts/#{contact.id}/media/sms"
|
532
|
-
expect(last_response).to be_forbidden
|
533
|
-
end
|
534
|
-
|
535
|
-
# GET /contacts/CONTACT_ID/timezone
|
536
|
-
it "returns the timezone of a contact" do
|
537
|
-
expect(contact).to receive(:timezone).and_return(::ActiveSupport::TimeZone.new('Australia/Sydney'))
|
538
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
539
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
540
|
-
|
541
|
-
aget "/contacts/#{contact.id}/timezone"
|
542
|
-
expect(last_response).to be_ok
|
543
|
-
expect(last_response.body).to eq('"Australia/Sydney"')
|
544
|
-
end
|
545
|
-
|
546
|
-
it "doesn't get the timezone of a contact that doesn't exist" do
|
547
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
548
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
549
|
-
|
550
|
-
aget "/contacts/#{contact.id}/timezone"
|
551
|
-
expect(last_response).to be_forbidden
|
552
|
-
end
|
553
|
-
|
554
|
-
# PUT /contacts/CONTACT_ID/timezone
|
555
|
-
it "sets the timezone of a contact" do
|
556
|
-
expect(contact).to receive(:timezone=).with('Australia/Perth')
|
557
|
-
expect(contact).to receive(:timezone).and_return(ActiveSupport::TimeZone.new('Australia/Perth'))
|
558
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
559
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
560
|
-
|
561
|
-
aput "/contacts/#{contact.id}/timezone", {:timezone => 'Australia/Perth'}
|
562
|
-
expect(last_response).to be_ok
|
563
|
-
end
|
564
|
-
|
565
|
-
it "doesn't set the timezone of a contact who can't be found" do
|
566
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
567
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
568
|
-
|
569
|
-
aput "/contacts/#{contact.id}/timezone", {:timezone => 'Australia/Perth'}
|
570
|
-
expect(last_response).to be_forbidden
|
571
|
-
end
|
572
|
-
|
573
|
-
# DELETE /contacts/CONTACT_ID/timezone
|
574
|
-
it "deletes the timezone of a contact" do
|
575
|
-
expect(contact).to receive(:timezone=).with(nil)
|
576
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
577
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
578
|
-
|
579
|
-
adelete "/contacts/#{contact.id}/timezone"
|
580
|
-
expect(last_response.status).to eq(204)
|
581
|
-
end
|
582
|
-
|
583
|
-
it "does not delete the timezone of a contact that's not present" do
|
584
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
585
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
586
|
-
|
587
|
-
adelete "/contacts/#{contact.id}/timezone"
|
588
|
-
expect(last_response).to be_forbidden
|
589
|
-
end
|
590
|
-
|
591
|
-
it "sets a single tag on a contact and returns current tags" do
|
592
|
-
expect(contact).to receive(:add_tags).with('web')
|
593
|
-
expect(contact).to receive(:tags).and_return(['web'])
|
594
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
595
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
596
|
-
|
597
|
-
apost "contacts/#{contact.id}/tags", :tag => 'web'
|
598
|
-
expect(last_response).to be_ok
|
599
|
-
expect(last_response.body).to eq(['web'].to_json)
|
600
|
-
end
|
601
|
-
|
602
|
-
it "does not set a single tag on a contact that's not found" do
|
603
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
604
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
605
|
-
|
606
|
-
apost "contacts/#{contact.id}/tags", :tag => 'web'
|
607
|
-
expect(last_response).to be_forbidden
|
608
|
-
end
|
609
|
-
|
610
|
-
it "sets multiple tags on a contact and returns current tags" do
|
611
|
-
expect(contact).to receive(:add_tags).with('web', 'app')
|
612
|
-
expect(contact).to receive(:tags).and_return(['web', 'app'])
|
613
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
614
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
615
|
-
|
616
|
-
apost "contacts/#{contact.id}/tags", :tag => ['web', 'app']
|
617
|
-
expect(last_response).to be_ok
|
618
|
-
expect(last_response.body).to eq(['web', 'app'].to_json)
|
619
|
-
end
|
620
|
-
|
621
|
-
it "does not set multiple tags on a contact that's not found" do
|
622
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
623
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
624
|
-
|
625
|
-
apost "contacts/#{contact.id}/tags", :tag => ['web', 'app']
|
626
|
-
expect(last_response).to be_forbidden
|
627
|
-
end
|
628
|
-
|
629
|
-
it "removes a single tag from a contact" do
|
630
|
-
expect(contact).to receive(:delete_tags).with('web')
|
631
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
632
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
633
|
-
|
634
|
-
adelete "contacts/#{contact.id}/tags", :tag => 'web'
|
635
|
-
expect(last_response.status).to eq(204)
|
636
|
-
end
|
637
|
-
|
638
|
-
it "does not remove a single tag from a contact that's not found" do
|
639
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
640
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
641
|
-
|
642
|
-
adelete "contacts/#{contact.id}/tags", :tag => 'web'
|
643
|
-
expect(last_response).to be_forbidden
|
644
|
-
end
|
645
|
-
|
646
|
-
it "removes multiple tags from a contact" do
|
647
|
-
expect(contact).to receive(:delete_tags).with('web', 'app')
|
648
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
649
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
650
|
-
|
651
|
-
adelete "contacts/#{contact.id}/tags", :tag => ['web', 'app']
|
652
|
-
expect(last_response.status).to eq(204)
|
653
|
-
end
|
654
|
-
|
655
|
-
it "does not remove multiple tags from a contact that's not found" do
|
656
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
657
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
658
|
-
|
659
|
-
adelete "contacts/#{contact.id}/tags", :tag => ['web', 'app']
|
660
|
-
expect(last_response).to be_forbidden
|
661
|
-
end
|
662
|
-
|
663
|
-
it "gets all tags on a contact" do
|
664
|
-
expect(contact).to receive(:tags).and_return(['web', 'app'])
|
665
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
666
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
667
|
-
|
668
|
-
aget "contacts/#{contact.id}/tags"
|
669
|
-
expect(last_response).to be_ok
|
670
|
-
expect(last_response.body).to eq(['web', 'app'].to_json)
|
671
|
-
end
|
672
|
-
|
673
|
-
it "does not get all tags on a contact that's not found" do
|
674
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
675
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
676
|
-
|
677
|
-
aget "contacts/#{contact.id}/tags"
|
678
|
-
expect(last_response).to be_forbidden
|
679
|
-
end
|
680
|
-
|
681
|
-
it "gets all entity tags for a contact" do
|
682
|
-
entity_1 = double(Flapjack::Data::Entity)
|
683
|
-
expect(entity_1).to receive(:name).and_return('entity_1')
|
684
|
-
entity_2 = double(Flapjack::Data::Entity)
|
685
|
-
expect(entity_2).to receive(:name).and_return('entity_2')
|
686
|
-
tag_data = [{:entity => entity_1, :tags => ['web']},
|
687
|
-
{:entity => entity_2, :tags => ['app']}]
|
688
|
-
expect(contact).to receive(:entities).with(:tags => true).
|
689
|
-
and_return(tag_data)
|
690
|
-
|
691
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
692
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
693
|
-
|
694
|
-
aget "contacts/#{contact.id}/entity_tags"
|
695
|
-
expect(last_response).to be_ok
|
696
|
-
tag_response = {'entity_1' => ['web'],
|
697
|
-
'entity_2' => ['app']}
|
698
|
-
expect(last_response.body).to eq(tag_response.to_json)
|
699
|
-
end
|
700
|
-
|
701
|
-
it "does not get all entity tags for a contact that's not found" do
|
702
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
703
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
704
|
-
|
705
|
-
aget "contacts/#{contact.id}/entity_tags"
|
706
|
-
expect(last_response).to be_forbidden
|
707
|
-
end
|
708
|
-
|
709
|
-
it "adds tags to multiple entities for a contact" do
|
710
|
-
entity_1 = double(Flapjack::Data::Entity)
|
711
|
-
expect(entity_1).to receive(:name).twice.and_return('entity_1')
|
712
|
-
expect(entity_1).to receive(:add_tags).with('web')
|
713
|
-
entity_2 = double(Flapjack::Data::Entity)
|
714
|
-
expect(entity_2).to receive(:name).twice.and_return('entity_2')
|
715
|
-
expect(entity_2).to receive(:add_tags).with('app')
|
716
|
-
|
717
|
-
entities = [{:entity => entity_1}, {:entity => entity_2}]
|
718
|
-
expect(contact).to receive(:entities).and_return(entities)
|
719
|
-
tag_data = [{:entity => entity_1, :tags => ['web']},
|
720
|
-
{:entity => entity_2, :tags => ['app']}]
|
721
|
-
expect(contact).to receive(:entities).with(:tags => true).and_return(tag_data)
|
722
|
-
|
723
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
724
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
725
|
-
|
726
|
-
apost "contacts/#{contact.id}/entity_tags",
|
727
|
-
:entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
|
728
|
-
expect(last_response).to be_ok
|
729
|
-
tag_response = {'entity_1' => ['web'],
|
730
|
-
'entity_2' => ['app']}
|
731
|
-
expect(last_response.body).to eq(tag_response.to_json)
|
732
|
-
end
|
733
|
-
|
734
|
-
it "does not add tags to multiple entities for a contact that's not found" do
|
735
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
736
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
737
|
-
|
738
|
-
apost "contacts/#{contact.id}/entity_tags",
|
739
|
-
:entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
|
740
|
-
expect(last_response).to be_forbidden
|
741
|
-
end
|
742
|
-
|
743
|
-
it "deletes tags from multiple entities for a contact" do
|
744
|
-
entity_1 = double(Flapjack::Data::Entity)
|
745
|
-
expect(entity_1).to receive(:name).and_return('entity_1')
|
746
|
-
expect(entity_1).to receive(:delete_tags).with('web')
|
747
|
-
entity_2 = double(Flapjack::Data::Entity)
|
748
|
-
expect(entity_2).to receive(:name).and_return('entity_2')
|
749
|
-
expect(entity_2).to receive(:delete_tags).with('app')
|
750
|
-
|
751
|
-
entities = [{:entity => entity_1}, {:entity => entity_2}]
|
752
|
-
expect(contact).to receive(:entities).and_return(entities)
|
753
|
-
|
754
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
755
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
756
|
-
|
757
|
-
adelete "contacts/#{contact.id}/entity_tags",
|
758
|
-
:entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
|
759
|
-
expect(last_response.status).to eq(204)
|
760
|
-
end
|
761
|
-
|
762
|
-
it "does not delete tags from multiple entities for a contact that's not found" do
|
763
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
764
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
765
|
-
|
766
|
-
adelete "contacts/#{contact.id}/entity_tags",
|
767
|
-
:entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
|
768
|
-
expect(last_response).to be_forbidden
|
769
|
-
end
|
770
|
-
|
771
|
-
|
772
|
-
end
|