flapjack 0.7.35 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -1
- data/Gemfile +3 -4
- data/Guardfile +1 -1
- data/README.md +38 -19
- data/Rakefile +1 -3
- data/etc/flapjack_config.yaml.example +11 -1
- data/features/steps/cli_steps.rb +3 -3
- data/features/steps/events_steps.rb +7 -6
- data/features/steps/flapjack-netsaint-parser_steps.rb +8 -8
- data/features/steps/notifications_steps.rb +10 -10
- data/features/steps/packaging-lintian_steps.rb +5 -9
- data/features/steps/time_travel_steps.rb +1 -1
- data/flapjack.gemspec +4 -3
- data/lib/flapjack/data/contact.rb +78 -6
- data/lib/flapjack/data/entity.rb +11 -2
- data/lib/flapjack/data/notification_rule.rb +67 -59
- data/lib/flapjack/data/semaphore.rb +44 -0
- data/lib/flapjack/gateways/api.rb +24 -28
- data/lib/flapjack/gateways/api/contact_methods.rb +1 -2
- data/lib/flapjack/gateways/api/entity_methods.rb +3 -3
- data/lib/flapjack/gateways/jsonapi.rb +249 -0
- data/lib/flapjack/gateways/jsonapi/contact_methods.rb +544 -0
- data/lib/flapjack/gateways/jsonapi/entity_check_presenter.rb +217 -0
- data/lib/flapjack/gateways/jsonapi/entity_methods.rb +350 -0
- data/lib/flapjack/gateways/jsonapi/entity_presenter.rb +75 -0
- data/lib/flapjack/gateways/jsonapi/rack/json_params_parser.rb +32 -0
- data/lib/flapjack/gateways/web.rb +78 -12
- data/lib/flapjack/gateways/web/public/css/bootstrap-theme.css +397 -0
- data/lib/flapjack/gateways/web/public/css/bootstrap-theme.min.css +7 -0
- data/lib/flapjack/gateways/web/public/css/bootstrap.css +7118 -0
- data/lib/flapjack/gateways/web/public/css/bootstrap.min.css +6 -8
- data/lib/flapjack/gateways/web/public/css/font-awesome.css +1338 -0
- data/lib/flapjack/gateways/web/public/css/font-awesome.min.css +4 -0
- data/lib/flapjack/gateways/web/public/css/screen.css +80 -0
- data/lib/flapjack/gateways/web/public/css/select2-bootstrap.css +87 -0
- data/lib/flapjack/gateways/web/public/css/select2.css +615 -0
- data/lib/flapjack/gateways/web/public/fonts/FontAwesome.otf +0 -0
- data/lib/flapjack/gateways/web/public/fonts/fontawesome-webfont.eot +0 -0
- data/lib/flapjack/gateways/web/public/fonts/fontawesome-webfont.svg +414 -0
- data/lib/flapjack/gateways/web/public/fonts/fontawesome-webfont.ttf +0 -0
- data/lib/flapjack/gateways/web/public/fonts/fontawesome-webfont.woff +0 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.eot +0 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.svg +229 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.woff +0 -0
- data/lib/flapjack/gateways/web/public/img/flapjack-2013-notext-transparent-300-300.png +0 -0
- data/lib/flapjack/gateways/web/public/img/select2.png +0 -0
- data/lib/flapjack/gateways/web/public/img/select2x2.png +0 -0
- data/lib/flapjack/gateways/web/public/js/backbone-min.js +2 -0
- data/lib/flapjack/gateways/web/public/js/backbone.js +1581 -0
- data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +75 -0
- data/lib/flapjack/gateways/web/public/js/bootstrap.js +2276 -0
- data/lib/flapjack/gateways/web/public/js/contacts.js +225 -0
- data/lib/flapjack/gateways/web/public/js/jquery-1.10.2.js +9789 -0
- data/lib/flapjack/gateways/web/public/js/jquery-1.10.2.min.js +6 -0
- data/lib/flapjack/gateways/web/public/js/select2.js +3255 -0
- data/lib/flapjack/gateways/web/public/js/select2.min.js +22 -0
- data/lib/flapjack/gateways/web/public/js/underscore-min.js +6 -0
- data/lib/flapjack/gateways/web/public/js/underscore.js +1276 -0
- data/lib/flapjack/gateways/web/views/check.html.erb +423 -193
- data/lib/flapjack/gateways/web/views/checks.html.erb +51 -71
- data/lib/flapjack/gateways/web/views/contact.html.erb +142 -164
- data/lib/flapjack/gateways/web/views/contacts.html.erb +20 -40
- data/lib/flapjack/gateways/web/views/edit_contacts.html.erb +83 -0
- data/lib/flapjack/gateways/web/views/entities.html.erb +18 -37
- data/lib/flapjack/gateways/web/views/entity.html.erb +46 -65
- data/lib/flapjack/gateways/web/views/index.html.erb +6 -27
- data/lib/flapjack/gateways/web/views/layout.erb +95 -0
- data/lib/flapjack/gateways/web/views/self_stats.html.erb +100 -114
- data/lib/flapjack/pikelet.rb +4 -2
- data/lib/flapjack/version.rb +1 -1
- data/spec/lib/flapjack/coordinator_spec.rb +120 -120
- data/spec/lib/flapjack/data/contact_spec.rb +66 -58
- data/spec/lib/flapjack/data/entity_check_spec.rb +179 -179
- data/spec/lib/flapjack/data/entity_spec.rb +71 -71
- data/spec/lib/flapjack/data/event_spec.rb +34 -30
- data/spec/lib/flapjack/data/message_spec.rb +6 -6
- data/spec/lib/flapjack/data/notification_rule_spec.rb +24 -24
- data/spec/lib/flapjack/data/notification_spec.rb +19 -19
- data/spec/lib/flapjack/data/semaphore_spec.rb +24 -0
- data/spec/lib/flapjack/data/tag_spec.rb +11 -10
- data/spec/lib/flapjack/gateways/api/contact_methods_spec.rb +201 -201
- data/spec/lib/flapjack/gateways/api/entity_check_presenter_spec.rb +55 -55
- data/spec/lib/flapjack/gateways/api/entity_methods_spec.rb +257 -257
- data/spec/lib/flapjack/gateways/api/entity_presenter_spec.rb +26 -26
- data/spec/lib/flapjack/gateways/api_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/email_spec.rb +4 -4
- data/spec/lib/flapjack/gateways/jabber_spec.rb +77 -77
- data/spec/lib/flapjack/gateways/jsonapi/contact_methods_spec.rb +830 -0
- data/spec/lib/flapjack/gateways/jsonapi/entity_check_presenter_spec.rb +211 -0
- data/spec/lib/flapjack/gateways/jsonapi/entity_methods_spec.rb +863 -0
- data/spec/lib/flapjack/gateways/jsonapi/entity_presenter_spec.rb +108 -0
- data/spec/lib/flapjack/gateways/jsonapi_spec.rb +8 -0
- data/spec/lib/flapjack/gateways/oobetet_spec.rb +35 -35
- data/spec/lib/flapjack/gateways/pagerduty_spec.rb +40 -40
- data/spec/lib/flapjack/gateways/sms_messagenet_spec.rb +3 -3
- data/spec/lib/flapjack/gateways/web/views/check.html.erb_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/web/views/contact.html.erb_spec.rb +5 -5
- data/spec/lib/flapjack/gateways/web/views/index.html.erb_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/web_spec.rb +73 -74
- data/spec/lib/flapjack/logger_spec.rb +13 -13
- data/spec/lib/flapjack/pikelet_spec.rb +33 -33
- data/spec/lib/flapjack/processor_spec.rb +22 -22
- data/spec/lib/flapjack/redis_pool_spec.rb +1 -1
- data/spec/lib/flapjack/utility_spec.rb +12 -12
- data/spec/spec_helper.rb +9 -9
- data/spec/support/erb_view_helper.rb +4 -0
- metadata +107 -96
- data/lib/flapjack/gateways/web/public/css/flapjack.css +0 -49
- data/lib/flapjack/gateways/web/views/_css.html.erb +0 -42
- data/lib/flapjack/gateways/web/views/_foot.html.erb +0 -3
- data/lib/flapjack/gateways/web/views/_head.html.erb +0 -5
- data/lib/flapjack/gateways/web/views/_nav.html.erb +0 -10
|
@@ -23,31 +23,31 @@ describe Flapjack::Data::Notification, :redis => true, :logger => true do
|
|
|
23
23
|
# in message.notification_contents
|
|
24
24
|
notification = Flapjack::Data::Notification.new
|
|
25
25
|
|
|
26
|
-
contact.
|
|
27
|
-
contact.
|
|
28
|
-
contact.
|
|
26
|
+
expect(contact).to receive(:id).and_return('23')
|
|
27
|
+
expect(contact).to receive(:notification_rules).and_return([])
|
|
28
|
+
expect(contact).to receive(:media).and_return('email' => 'example@example.com',
|
|
29
29
|
'sms' => '0123456789')
|
|
30
|
-
contact.
|
|
31
|
-
contact.
|
|
32
|
-
contact.
|
|
33
|
-
contact.
|
|
34
|
-
contact.
|
|
35
|
-
contact.
|
|
36
|
-
contact.
|
|
37
|
-
contact.
|
|
30
|
+
expect(contact).to receive(:add_alerting_check_for_media).with("email", nil)
|
|
31
|
+
expect(contact).to receive(:add_alerting_check_for_media).with("sms", nil)
|
|
32
|
+
expect(contact).to receive(:clean_alerting_checks_for_media).with("email").and_return(0)
|
|
33
|
+
expect(contact).to receive(:clean_alerting_checks_for_media).with("sms").and_return(0)
|
|
34
|
+
expect(contact).to receive(:count_alerting_checks_for_media).with("email").and_return(0)
|
|
35
|
+
expect(contact).to receive(:count_alerting_checks_for_media).with("sms").and_return(0)
|
|
36
|
+
expect(contact).to receive(:rollup_threshold_for_media).with("email").and_return(nil)
|
|
37
|
+
expect(contact).to receive(:rollup_threshold_for_media).with("sms").and_return(nil)
|
|
38
38
|
|
|
39
39
|
messages = notification.messages([contact], :default_timezone => timezone,
|
|
40
40
|
:logger => @logger)
|
|
41
|
-
messages.
|
|
42
|
-
messages.
|
|
41
|
+
expect(messages).not_to be_nil
|
|
42
|
+
expect(messages.size).to eq(2)
|
|
43
43
|
|
|
44
|
-
messages.first.contact.
|
|
45
|
-
messages.first.medium.
|
|
46
|
-
messages.first.address.
|
|
44
|
+
expect(messages.first.contact).to eq(contact)
|
|
45
|
+
expect(messages.first.medium).to eq('email')
|
|
46
|
+
expect(messages.first.address).to eq('example@example.com')
|
|
47
47
|
|
|
48
|
-
messages.last.contact.
|
|
49
|
-
messages.last.medium.
|
|
50
|
-
messages.last.address.
|
|
48
|
+
expect(messages.last.contact).to eq(contact)
|
|
49
|
+
expect(messages.last.medium).to eq('sms')
|
|
50
|
+
expect(messages.last.address).to eq('0123456789')
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'flapjack/data/semaphore'
|
|
3
|
+
|
|
4
|
+
describe 'Flapjack::Data::Semaphore', :redis => true do
|
|
5
|
+
|
|
6
|
+
it "obtains a lock that locks" do
|
|
7
|
+
options = {:redis => @redis, :expiry => 60}
|
|
8
|
+
lock_1 = Flapjack::Data::Semaphore.new('fooey', options)
|
|
9
|
+
expect(lock_1.class).to eq(Flapjack::Data::Semaphore)
|
|
10
|
+
expect{Flapjack::Data::Semaphore.new('fooey', options)}.to raise_error(Flapjack::Data::Semaphore::ResourceLocked)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "releases a lock" do
|
|
14
|
+
options = {:redis => @redis, :expiry => 60}
|
|
15
|
+
lock_1 = Flapjack::Data::Semaphore.new('fooey', options)
|
|
16
|
+
expect(lock_1.class).to eq(Flapjack::Data::Semaphore)
|
|
17
|
+
lock_1.release
|
|
18
|
+
|
|
19
|
+
lock_2 = Flapjack::Data::Semaphore.new('fooey', options)
|
|
20
|
+
expect(lock_2.class).to eq(Flapjack::Data::Semaphore)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
@@ -1,35 +1,36 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
+
require 'flapjack/data/tag'
|
|
2
3
|
|
|
3
4
|
describe Flapjack::Data::Tag, :redis => true do
|
|
4
5
|
|
|
5
6
|
it "adds references to tags" do
|
|
6
7
|
tags = Flapjack::Data::Tag.create('special', ['apple', 'button', 'carbon'], :redis => @redis)
|
|
7
8
|
|
|
8
|
-
tags.
|
|
9
|
-
tags.
|
|
9
|
+
expect(tags).to include('carbon')
|
|
10
|
+
expect(tags).not_to include('chocolate')
|
|
10
11
|
|
|
11
12
|
tags.add('chocolate')
|
|
12
|
-
tags.
|
|
13
|
+
expect(tags).to include('chocolate')
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
it "deletes references from tags" do
|
|
16
17
|
tags = Flapjack::Data::Tag.create('special', ['apple', 'button', 'carbon'], :redis => @redis)
|
|
17
18
|
|
|
18
|
-
tags.
|
|
19
|
-
tags.
|
|
19
|
+
expect(tags).to include('apple')
|
|
20
|
+
expect(tags).to include('button')
|
|
20
21
|
|
|
21
22
|
tags.delete('button')
|
|
22
|
-
tags.
|
|
23
|
-
tags.
|
|
23
|
+
expect(tags).to include('apple')
|
|
24
|
+
expect(tags).not_to include('button')
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
it "lists references contained in a tag" do
|
|
27
28
|
t1 = Flapjack::Data::Tag.create('special', ['apple', 'button', 'carbon'], :redis => @redis)
|
|
28
29
|
|
|
29
30
|
t2 = Flapjack::Data::Tag.find('special', :redis => @redis)
|
|
30
|
-
t2.
|
|
31
|
-
t2.
|
|
32
|
-
t2.
|
|
31
|
+
expect(t2).to include('apple')
|
|
32
|
+
expect(t2).to include('carbon')
|
|
33
|
+
expect(t2).not_to include('chocolate')
|
|
33
34
|
end
|
|
34
35
|
|
|
35
36
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
require 'flapjack/gateways/api'
|
|
3
3
|
|
|
4
|
-
describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger => true
|
|
4
|
+
describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger => true do
|
|
5
5
|
|
|
6
6
|
def app
|
|
7
7
|
Flapjack::Gateways::API
|
|
@@ -60,7 +60,7 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
before(:each) do
|
|
63
|
-
Flapjack::RedisPool.
|
|
63
|
+
expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
|
|
64
64
|
Flapjack::Gateways::API.instance_variable_set('@config', {})
|
|
65
65
|
Flapjack::Gateways::API.instance_variable_set('@logger', @logger)
|
|
66
66
|
Flapjack::Gateways::API.start
|
|
@@ -82,19 +82,19 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
|
82
82
|
]
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
Flapjack::Data::Contact.
|
|
86
|
-
Flapjack::Data::Contact.
|
|
85
|
+
expect(Flapjack::Data::Contact).to receive(:all).with(:redis => redis).and_return([])
|
|
86
|
+
expect(Flapjack::Data::Contact).to receive(:add).twice
|
|
87
87
|
|
|
88
88
|
apost "/contacts", contacts.to_json, {'CONTENT_TYPE' => 'application/json'}
|
|
89
|
-
last_response.status.
|
|
89
|
+
expect(last_response.status).to eq(204)
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
it "does not create contacts if the data is improperly formatted" do
|
|
93
|
-
Flapjack::Data::Contact.
|
|
93
|
+
expect(Flapjack::Data::Contact).not_to receive(:add)
|
|
94
94
|
|
|
95
95
|
apost "/contacts", {'contacts' => ["Hello", "again"]}.to_json,
|
|
96
96
|
{'CONTENT_TYPE' => 'application/json'}
|
|
97
|
-
last_response.status.
|
|
97
|
+
expect(last_response.status).to eq(403)
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
it "does not create contacts if they don't contain an id" do
|
|
@@ -112,11 +112,11 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
|
112
112
|
]
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
Flapjack::Data::Contact.
|
|
116
|
-
Flapjack::Data::Contact.
|
|
115
|
+
expect(Flapjack::Data::Contact).to receive(:all).with(:redis => redis).and_return([])
|
|
116
|
+
expect(Flapjack::Data::Contact).to receive(:add)
|
|
117
117
|
|
|
118
118
|
apost "/contacts", contacts.to_json, {'CONTENT_TYPE' => 'application/json'}
|
|
119
|
-
last_response.status.
|
|
119
|
+
expect(last_response.status).to eq(204)
|
|
120
120
|
end
|
|
121
121
|
|
|
122
122
|
it "updates a contact if it is already present" do
|
|
@@ -136,14 +136,14 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
existing = double(Flapjack::Data::Contact)
|
|
139
|
-
existing.
|
|
140
|
-
existing.
|
|
139
|
+
expect(existing).to receive(:id).and_return("0363")
|
|
140
|
+
expect(existing).to receive(:update).with(contacts['contacts'][1])
|
|
141
141
|
|
|
142
|
-
Flapjack::Data::Contact.
|
|
143
|
-
Flapjack::Data::Contact.
|
|
142
|
+
expect(Flapjack::Data::Contact).to receive(:all).with(:redis => redis).and_return([existing])
|
|
143
|
+
expect(Flapjack::Data::Contact).to receive(:add).with(contacts['contacts'][0], :redis => redis)
|
|
144
144
|
|
|
145
145
|
apost "/contacts", contacts.to_json, {'CONTENT_TYPE' => 'application/json'}
|
|
146
|
-
last_response.status.
|
|
146
|
+
expect(last_response.status).to eq(204)
|
|
147
147
|
end
|
|
148
148
|
|
|
149
149
|
it "deletes a contact not found in a bulk update list" do
|
|
@@ -157,91 +157,91 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
existing = double(Flapjack::Data::Contact)
|
|
160
|
-
existing.
|
|
161
|
-
existing.
|
|
160
|
+
expect(existing).to receive(:id).twice.and_return("0362")
|
|
161
|
+
expect(existing).to receive(:delete!)
|
|
162
162
|
|
|
163
|
-
Flapjack::Data::Contact.
|
|
164
|
-
Flapjack::Data::Contact.
|
|
163
|
+
expect(Flapjack::Data::Contact).to receive(:all).with(:redis => redis).and_return([existing])
|
|
164
|
+
expect(Flapjack::Data::Contact).to receive(:add).with(contacts['contacts'][0], :redis => redis)
|
|
165
165
|
|
|
166
166
|
apost "/contacts", contacts.to_json, {'CONTENT_TYPE' => 'application/json'}
|
|
167
|
-
last_response.status.
|
|
167
|
+
expect(last_response.status).to eq(204)
|
|
168
168
|
end
|
|
169
169
|
|
|
170
170
|
it "returns all the contacts" do
|
|
171
|
-
contact.
|
|
172
|
-
Flapjack::Data::Contact.
|
|
171
|
+
expect(contact).to receive(:to_json).and_return(contact_core.to_json)
|
|
172
|
+
expect(Flapjack::Data::Contact).to receive(:all).with(:redis => redis).
|
|
173
173
|
and_return([contact])
|
|
174
174
|
|
|
175
175
|
aget '/contacts'
|
|
176
|
-
last_response.
|
|
177
|
-
last_response.body.
|
|
176
|
+
expect(last_response).to be_ok
|
|
177
|
+
expect(last_response.body).to eq([contact_core].to_json)
|
|
178
178
|
end
|
|
179
179
|
|
|
180
180
|
it "returns the core information of a specified contact" do
|
|
181
|
-
contact.
|
|
182
|
-
Flapjack::Data::Contact.
|
|
181
|
+
expect(contact).to receive(:to_json).and_return(contact_core.to_json)
|
|
182
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
183
183
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
184
184
|
|
|
185
185
|
aget "/contacts/#{contact.id}"
|
|
186
|
-
last_response.
|
|
187
|
-
last_response.body.
|
|
186
|
+
expect(last_response).to be_ok
|
|
187
|
+
expect(last_response.body).to eq(contact_core.to_json)
|
|
188
188
|
end
|
|
189
189
|
|
|
190
190
|
it "does not return information for a contact that does not exist" do
|
|
191
|
-
Flapjack::Data::Contact.
|
|
191
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
192
192
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
193
193
|
|
|
194
194
|
aget "/contacts/#{contact.id}"
|
|
195
|
-
last_response.
|
|
195
|
+
expect(last_response).to be_forbidden
|
|
196
196
|
end
|
|
197
197
|
|
|
198
198
|
it "lists a contact's notification rules" do
|
|
199
199
|
notification_rule_2 = double(Flapjack::Data::NotificationRule, :id => '2', :contact_id => '21')
|
|
200
|
-
notification_rule.
|
|
201
|
-
notification_rule_2.
|
|
200
|
+
expect(notification_rule).to receive(:to_json).and_return('"rule_1"')
|
|
201
|
+
expect(notification_rule_2).to receive(:to_json).and_return('"rule_2"')
|
|
202
202
|
notification_rules = [ notification_rule, notification_rule_2 ]
|
|
203
203
|
|
|
204
|
-
contact.
|
|
205
|
-
Flapjack::Data::Contact.
|
|
204
|
+
expect(contact).to receive(:notification_rules).and_return(notification_rules)
|
|
205
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
206
206
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
207
207
|
|
|
208
208
|
aget "/contacts/#{contact.id}/notification_rules"
|
|
209
|
-
last_response.
|
|
210
|
-
last_response.body.
|
|
209
|
+
expect(last_response).to be_ok
|
|
210
|
+
expect(last_response.body).to eq('["rule_1","rule_2"]')
|
|
211
211
|
end
|
|
212
212
|
|
|
213
213
|
it "does not list notification rules for a contact that does not exist" do
|
|
214
|
-
Flapjack::Data::Contact.
|
|
214
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
215
215
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
216
216
|
|
|
217
217
|
aget "/contacts/#{contact.id}/notification_rules"
|
|
218
|
-
last_response.
|
|
218
|
+
expect(last_response).to be_forbidden
|
|
219
219
|
end
|
|
220
220
|
|
|
221
221
|
it "returns a specified notification rule" do
|
|
222
|
-
notification_rule.
|
|
223
|
-
Flapjack::Data::NotificationRule.
|
|
222
|
+
expect(notification_rule).to receive(:to_json).and_return('"rule_1"')
|
|
223
|
+
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
|
224
224
|
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
|
|
225
225
|
|
|
226
226
|
aget "/notification_rules/#{notification_rule.id}"
|
|
227
|
-
last_response.
|
|
228
|
-
last_response.body.
|
|
227
|
+
expect(last_response).to be_ok
|
|
228
|
+
expect(last_response.body).to eq('"rule_1"')
|
|
229
229
|
end
|
|
230
230
|
|
|
231
231
|
it "does not return a notification rule that does not exist" do
|
|
232
|
-
Flapjack::Data::NotificationRule.
|
|
232
|
+
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
|
233
233
|
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
234
234
|
|
|
235
235
|
aget "/notification_rules/#{notification_rule.id}"
|
|
236
|
-
last_response.
|
|
236
|
+
expect(last_response).to be_forbidden
|
|
237
237
|
end
|
|
238
238
|
|
|
239
239
|
# POST /notification_rules
|
|
240
240
|
it "creates a new notification rule" do
|
|
241
|
-
Flapjack::Data::Contact.
|
|
241
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
242
242
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
243
|
-
notification_rule.
|
|
244
|
-
notification_rule.
|
|
243
|
+
expect(notification_rule).to receive(:respond_to?).with(:critical_media).and_return(true)
|
|
244
|
+
expect(notification_rule).to receive(:to_json).and_return('"rule_1"')
|
|
245
245
|
|
|
246
246
|
# symbolize the keys
|
|
247
247
|
notification_rule_data_sym = notification_rule_data.inject({}){|memo,(k,v)|
|
|
@@ -249,38 +249,38 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
|
249
249
|
}
|
|
250
250
|
notification_rule_data_sym.delete(:contact_id)
|
|
251
251
|
|
|
252
|
-
contact.
|
|
252
|
+
expect(contact).to receive(:add_notification_rule).
|
|
253
253
|
with(notification_rule_data_sym, :logger => @logger).and_return(notification_rule)
|
|
254
254
|
|
|
255
255
|
apost "/notification_rules", notification_rule_data.to_json,
|
|
256
256
|
{'CONTENT_TYPE' => 'application/json'}
|
|
257
|
-
last_response.
|
|
258
|
-
last_response.body.
|
|
257
|
+
expect(last_response).to be_ok
|
|
258
|
+
expect(last_response.body).to eq('"rule_1"')
|
|
259
259
|
end
|
|
260
260
|
|
|
261
261
|
it "does not create a notification_rule for a contact that's not present" do
|
|
262
|
-
Flapjack::Data::Contact.
|
|
262
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
263
263
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
264
264
|
|
|
265
265
|
apost "/notification_rules", notification_rule_data.to_json,
|
|
266
266
|
{'CONTENT_TYPE' => 'application/json'}
|
|
267
|
-
last_response.
|
|
267
|
+
expect(last_response).to be_forbidden
|
|
268
268
|
end
|
|
269
269
|
|
|
270
270
|
it "does not create a notification_rule if a rule id is provided" do
|
|
271
|
-
contact.
|
|
271
|
+
expect(contact).not_to receive(:add_notification_rule)
|
|
272
272
|
|
|
273
273
|
apost "/notification_rules", notification_rule_data.merge(:id => 1).to_json,
|
|
274
274
|
{'CONTENT_TYPE' => 'application/json'}
|
|
275
|
-
last_response.status.
|
|
275
|
+
expect(last_response.status).to eq(403)
|
|
276
276
|
end
|
|
277
277
|
|
|
278
278
|
# PUT /notification_rules/RULE_ID
|
|
279
279
|
it "updates a notification rule" do
|
|
280
|
-
Flapjack::Data::Contact.
|
|
280
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
281
281
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
282
|
-
notification_rule.
|
|
283
|
-
Flapjack::Data::NotificationRule.
|
|
282
|
+
expect(notification_rule).to receive(:to_json).and_return('"rule_1"')
|
|
283
|
+
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
|
284
284
|
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
|
|
285
285
|
|
|
286
286
|
# symbolize the keys
|
|
@@ -289,71 +289,71 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
|
289
289
|
}
|
|
290
290
|
notification_rule_data_sym.delete(:contact_id)
|
|
291
291
|
|
|
292
|
-
notification_rule.
|
|
292
|
+
expect(notification_rule).to receive(:update).with(notification_rule_data_sym, :logger => @logger).and_return(nil)
|
|
293
293
|
|
|
294
294
|
aput "/notification_rules/#{notification_rule.id}", notification_rule_data.to_json,
|
|
295
295
|
{'CONTENT_TYPE' => 'application/json'}
|
|
296
|
-
last_response.
|
|
297
|
-
last_response.body.
|
|
296
|
+
expect(last_response).to be_ok
|
|
297
|
+
expect(last_response.body).to eq('"rule_1"')
|
|
298
298
|
end
|
|
299
299
|
|
|
300
300
|
it "does not update a notification rule that's not present" do
|
|
301
|
-
Flapjack::Data::NotificationRule.
|
|
301
|
+
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
|
302
302
|
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
303
303
|
|
|
304
304
|
aput "/notification_rules/#{notification_rule.id}", notification_rule_data
|
|
305
|
-
last_response.
|
|
305
|
+
expect(last_response).to be_forbidden
|
|
306
306
|
end
|
|
307
307
|
|
|
308
308
|
it "does not update a notification_rule for a contact that's not present" do
|
|
309
|
-
Flapjack::Data::NotificationRule.
|
|
309
|
+
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
|
310
310
|
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
|
|
311
|
-
Flapjack::Data::Contact.
|
|
311
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
312
312
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
313
313
|
|
|
314
314
|
aput "/notification_rules/#{notification_rule.id}", notification_rule_data.to_json,
|
|
315
315
|
{'CONTENT_TYPE' => 'application/json'}
|
|
316
|
-
last_response.
|
|
316
|
+
expect(last_response).to be_forbidden
|
|
317
317
|
end
|
|
318
318
|
|
|
319
319
|
# DELETE /notification_rules/RULE_ID
|
|
320
320
|
it "deletes a notification rule" do
|
|
321
|
-
notification_rule.
|
|
322
|
-
Flapjack::Data::NotificationRule.
|
|
321
|
+
expect(notification_rule).to receive(:contact_id).and_return(contact.id)
|
|
322
|
+
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
|
323
323
|
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
|
|
324
|
-
contact.
|
|
325
|
-
Flapjack::Data::Contact.
|
|
324
|
+
expect(contact).to receive(:delete_notification_rule).with(notification_rule)
|
|
325
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
326
326
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
327
327
|
|
|
328
328
|
adelete "/notification_rules/#{notification_rule.id}"
|
|
329
|
-
last_response.status.
|
|
329
|
+
expect(last_response.status).to eq(204)
|
|
330
330
|
end
|
|
331
331
|
|
|
332
332
|
it "does not delete a notification rule that's not present" do
|
|
333
|
-
Flapjack::Data::NotificationRule.
|
|
333
|
+
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
|
334
334
|
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
335
335
|
|
|
336
336
|
adelete "/notification_rules/#{notification_rule.id}"
|
|
337
|
-
last_response.
|
|
337
|
+
expect(last_response).to be_forbidden
|
|
338
338
|
end
|
|
339
339
|
|
|
340
340
|
it "does not delete a notification rule if the contact is not present" do
|
|
341
|
-
notification_rule.
|
|
342
|
-
Flapjack::Data::NotificationRule.
|
|
341
|
+
expect(notification_rule).to receive(:contact_id).and_return(contact.id)
|
|
342
|
+
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
|
343
343
|
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
|
|
344
|
-
Flapjack::Data::Contact.
|
|
344
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
345
345
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
346
346
|
|
|
347
347
|
adelete "/notification_rules/#{notification_rule.id}"
|
|
348
|
-
last_response.
|
|
348
|
+
expect(last_response).to be_forbidden
|
|
349
349
|
end
|
|
350
350
|
|
|
351
351
|
# GET /contacts/CONTACT_ID/media
|
|
352
352
|
it "returns the media of a contact" do
|
|
353
|
-
contact.
|
|
354
|
-
contact.
|
|
355
|
-
contact.
|
|
356
|
-
Flapjack::Data::Contact.
|
|
353
|
+
expect(contact).to receive(:media).and_return(media)
|
|
354
|
+
expect(contact).to receive(:media_intervals).and_return(media_intervals)
|
|
355
|
+
expect(contact).to receive(:media_rollup_thresholds).and_return(media_rollup_thresholds)
|
|
356
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
357
357
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
358
358
|
result = Hash[ *(media.keys.collect {|m|
|
|
359
359
|
[m, {'address' => media[m],
|
|
@@ -362,24 +362,24 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
|
362
362
|
}).flatten(1)].to_json
|
|
363
363
|
|
|
364
364
|
aget "/contacts/#{contact.id}/media"
|
|
365
|
-
last_response.
|
|
366
|
-
last_response.body.
|
|
365
|
+
expect(last_response).to be_ok
|
|
366
|
+
expect(last_response.body).to eq(result)
|
|
367
367
|
end
|
|
368
368
|
|
|
369
369
|
it "does not return the media of a contact if the contact is not present" do
|
|
370
|
-
Flapjack::Data::Contact.
|
|
370
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
371
371
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
372
372
|
|
|
373
373
|
aget "/contacts/#{contact.id}/media"
|
|
374
|
-
last_response.
|
|
374
|
+
expect(last_response).to be_forbidden
|
|
375
375
|
end
|
|
376
376
|
|
|
377
377
|
# GET /contacts/CONTACT_ID/media/MEDIA
|
|
378
378
|
it "returns the specified media of a contact" do
|
|
379
|
-
contact.
|
|
380
|
-
contact.
|
|
381
|
-
contact.
|
|
382
|
-
Flapjack::Data::Contact.
|
|
379
|
+
expect(contact).to receive(:media).and_return(media)
|
|
380
|
+
expect(contact).to receive(:media_intervals).and_return(media_intervals)
|
|
381
|
+
expect(contact).to receive(:media_rollup_thresholds).and_return(media_rollup_thresholds)
|
|
382
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
383
383
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
384
384
|
|
|
385
385
|
result = {
|
|
@@ -389,25 +389,25 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
|
389
389
|
}
|
|
390
390
|
|
|
391
391
|
aget "/contacts/#{contact.id}/media/sms"
|
|
392
|
-
last_response.
|
|
393
|
-
last_response.body.
|
|
392
|
+
expect(last_response).to be_ok
|
|
393
|
+
expect(last_response.body).to eq(result.to_json)
|
|
394
394
|
end
|
|
395
395
|
|
|
396
396
|
it "does not return the media of a contact if the contact is not present" do
|
|
397
|
-
Flapjack::Data::Contact.
|
|
397
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
398
398
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
399
399
|
|
|
400
400
|
aget "/contacts/#{contact.id}/media/sms"
|
|
401
|
-
last_response.
|
|
401
|
+
expect(last_response).to be_forbidden
|
|
402
402
|
end
|
|
403
403
|
|
|
404
404
|
it "does not return the media of a contact if the media is not present" do
|
|
405
|
-
contact.
|
|
406
|
-
Flapjack::Data::Contact.
|
|
405
|
+
expect(contact).to receive(:media).and_return(media)
|
|
406
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
407
407
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
408
408
|
|
|
409
409
|
aget "/contacts/#{contact.id}/media/telepathy"
|
|
410
|
-
last_response.
|
|
410
|
+
expect(last_response).to be_forbidden
|
|
411
411
|
end
|
|
412
412
|
|
|
413
413
|
# PUT, DELETE /contacts/CONTACT_ID/media/MEDIA
|
|
@@ -418,13 +418,13 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
|
418
418
|
alt_media_intervals = media_intervals.merge('sms' => '200')
|
|
419
419
|
alt_media_rollup_thresholds = media_rollup_thresholds.merge('sms' => '5')
|
|
420
420
|
|
|
421
|
-
contact.
|
|
422
|
-
contact.
|
|
423
|
-
contact.
|
|
424
|
-
contact.
|
|
425
|
-
contact.
|
|
426
|
-
contact.
|
|
427
|
-
Flapjack::Data::Contact.
|
|
421
|
+
expect(contact).to receive(:set_address_for_media).with('sms', '04987654321')
|
|
422
|
+
expect(contact).to receive(:set_interval_for_media).with('sms', '200')
|
|
423
|
+
expect(contact).to receive(:set_rollup_threshold_for_media).with('sms', '5')
|
|
424
|
+
expect(contact).to receive(:media).and_return(alt_media)
|
|
425
|
+
expect(contact).to receive(:media_intervals).and_return(alt_media_intervals)
|
|
426
|
+
expect(contact).to receive(:media_rollup_thresholds).and_return(alt_media_rollup_thresholds)
|
|
427
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
428
428
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
429
429
|
|
|
430
430
|
result = {'address' => alt_media['sms'],
|
|
@@ -433,8 +433,8 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
|
433
433
|
|
|
434
434
|
aput "/contacts/#{contact.id}/media/sms", :address => '04987654321',
|
|
435
435
|
:interval => '200', :rollup_threshold => '5'
|
|
436
|
-
last_response.
|
|
437
|
-
last_response.body.
|
|
436
|
+
expect(last_response).to be_ok
|
|
437
|
+
expect(last_response.body).to eq(result.to_json)
|
|
438
438
|
end
|
|
439
439
|
|
|
440
440
|
it "updates a contact's pagerduty media credentials" do
|
|
@@ -443,33 +443,33 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
|
443
443
|
'username' => "sausage@example.com",
|
|
444
444
|
'password' => "sausage"}
|
|
445
445
|
|
|
446
|
-
contact.
|
|
447
|
-
contact.
|
|
448
|
-
Flapjack::Data::Contact.
|
|
446
|
+
expect(contact).to receive(:set_pagerduty_credentials).with(result)
|
|
447
|
+
expect(contact).to receive(:pagerduty_credentials).and_return(result)
|
|
448
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
449
449
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
450
450
|
|
|
451
451
|
aput "/contacts/#{contact.id}/media/pagerduty", :service_key => result['service_key'],
|
|
452
452
|
:subdomain => result['subdomain'], :username => result['username'],
|
|
453
453
|
:password => result['password']
|
|
454
454
|
|
|
455
|
-
last_response.
|
|
456
|
-
last_response.body.
|
|
455
|
+
expect(last_response).to be_ok
|
|
456
|
+
expect(last_response.body).to eq(result.to_json)
|
|
457
457
|
end
|
|
458
458
|
|
|
459
459
|
it "does not create a media of a contact that's not present" do
|
|
460
|
-
Flapjack::Data::Contact.
|
|
460
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
461
461
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
462
462
|
|
|
463
463
|
aput "/contacts/#{contact.id}/media/sms", :address => '04987654321', :interval => '200'
|
|
464
|
-
last_response.
|
|
464
|
+
expect(last_response).to be_forbidden
|
|
465
465
|
end
|
|
466
466
|
|
|
467
467
|
it "does not create a media of a contact if no address is provided" do
|
|
468
|
-
Flapjack::Data::Contact.
|
|
468
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
469
469
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
470
470
|
|
|
471
471
|
aput "/contacts/#{contact.id}/media/sms", :interval => '200'
|
|
472
|
-
last_response.
|
|
472
|
+
expect(last_response).to be_forbidden
|
|
473
473
|
end
|
|
474
474
|
|
|
475
475
|
it "creates a media of a contact even if no interval is provided" do
|
|
@@ -477,270 +477,270 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
|
477
477
|
alt_media_intervals = media_intervals.merge('sms' => nil)
|
|
478
478
|
alt_media_rollup_thresholds = media_rollup_thresholds.merge('sms' => nil)
|
|
479
479
|
|
|
480
|
-
contact.
|
|
481
|
-
contact.
|
|
482
|
-
contact.
|
|
483
|
-
contact.
|
|
484
|
-
contact.
|
|
485
|
-
contact.
|
|
486
|
-
Flapjack::Data::Contact.
|
|
480
|
+
expect(contact).to receive(:set_address_for_media).with('sms', '04987654321')
|
|
481
|
+
expect(contact).to receive(:set_interval_for_media).with('sms', nil)
|
|
482
|
+
expect(contact).to receive(:set_rollup_threshold_for_media).with("sms", nil)
|
|
483
|
+
expect(contact).to receive(:media).and_return(alt_media)
|
|
484
|
+
expect(contact).to receive(:media_intervals).and_return(alt_media_intervals)
|
|
485
|
+
expect(contact).to receive(:media_rollup_thresholds).and_return(alt_media_rollup_thresholds)
|
|
486
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
487
487
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
488
488
|
|
|
489
489
|
aput "/contacts/#{contact.id}/media/sms", :address => '04987654321'
|
|
490
|
-
last_response.
|
|
490
|
+
expect(last_response).to be_ok
|
|
491
491
|
end
|
|
492
492
|
|
|
493
493
|
it "deletes a media of a contact" do
|
|
494
|
-
contact.
|
|
495
|
-
Flapjack::Data::Contact.
|
|
494
|
+
expect(contact).to receive(:remove_media).with('sms')
|
|
495
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
496
496
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
497
497
|
|
|
498
498
|
adelete "/contacts/#{contact.id}/media/sms"
|
|
499
|
-
last_response.status.
|
|
499
|
+
expect(last_response.status).to eq(204)
|
|
500
500
|
end
|
|
501
501
|
|
|
502
502
|
it "does not delete a media of a contact that's not present" do
|
|
503
|
-
Flapjack::Data::Contact.
|
|
503
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
504
504
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
505
505
|
|
|
506
506
|
adelete "/contacts/#{contact.id}/media/sms"
|
|
507
|
-
last_response.
|
|
507
|
+
expect(last_response).to be_forbidden
|
|
508
508
|
end
|
|
509
509
|
|
|
510
510
|
# GET /contacts/CONTACT_ID/timezone
|
|
511
511
|
it "returns the timezone of a contact" do
|
|
512
|
-
contact.
|
|
513
|
-
Flapjack::Data::Contact.
|
|
512
|
+
expect(contact).to receive(:timezone).and_return(::ActiveSupport::TimeZone.new('Australia/Sydney'))
|
|
513
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
514
514
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
515
515
|
|
|
516
516
|
aget "/contacts/#{contact.id}/timezone"
|
|
517
|
-
last_response.
|
|
518
|
-
last_response.body.
|
|
517
|
+
expect(last_response).to be_ok
|
|
518
|
+
expect(last_response.body).to eq('"Australia/Sydney"')
|
|
519
519
|
end
|
|
520
520
|
|
|
521
521
|
it "doesn't get the timezone of a contact that doesn't exist" do
|
|
522
|
-
Flapjack::Data::Contact.
|
|
522
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
523
523
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
524
524
|
|
|
525
525
|
aget "/contacts/#{contact.id}/timezone"
|
|
526
|
-
last_response.
|
|
526
|
+
expect(last_response).to be_forbidden
|
|
527
527
|
end
|
|
528
528
|
|
|
529
529
|
# PUT /contacts/CONTACT_ID/timezone
|
|
530
530
|
it "sets the timezone of a contact" do
|
|
531
|
-
contact.
|
|
532
|
-
contact.
|
|
533
|
-
Flapjack::Data::Contact.
|
|
531
|
+
expect(contact).to receive(:timezone=).with('Australia/Perth')
|
|
532
|
+
expect(contact).to receive(:timezone).and_return(ActiveSupport::TimeZone.new('Australia/Perth'))
|
|
533
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
534
534
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
535
535
|
|
|
536
536
|
aput "/contacts/#{contact.id}/timezone", {:timezone => 'Australia/Perth'}
|
|
537
|
-
last_response.
|
|
537
|
+
expect(last_response).to be_ok
|
|
538
538
|
end
|
|
539
539
|
|
|
540
540
|
it "doesn't set the timezone of a contact who can't be found" do
|
|
541
|
-
Flapjack::Data::Contact.
|
|
541
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
542
542
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
543
543
|
|
|
544
544
|
aput "/contacts/#{contact.id}/timezone", {:timezone => 'Australia/Perth'}
|
|
545
|
-
last_response.
|
|
545
|
+
expect(last_response).to be_forbidden
|
|
546
546
|
end
|
|
547
547
|
|
|
548
548
|
# DELETE /contacts/CONTACT_ID/timezone
|
|
549
549
|
it "deletes the timezone of a contact" do
|
|
550
|
-
contact.
|
|
551
|
-
Flapjack::Data::Contact.
|
|
550
|
+
expect(contact).to receive(:timezone=).with(nil)
|
|
551
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
552
552
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
553
553
|
|
|
554
554
|
adelete "/contacts/#{contact.id}/timezone"
|
|
555
|
-
last_response.status.
|
|
555
|
+
expect(last_response.status).to eq(204)
|
|
556
556
|
end
|
|
557
557
|
|
|
558
558
|
it "does not delete the timezone of a contact that's not present" do
|
|
559
|
-
Flapjack::Data::Contact.
|
|
559
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
560
560
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
561
561
|
|
|
562
562
|
adelete "/contacts/#{contact.id}/timezone"
|
|
563
|
-
last_response.
|
|
563
|
+
expect(last_response).to be_forbidden
|
|
564
564
|
end
|
|
565
565
|
|
|
566
566
|
it "sets a single tag on a contact and returns current tags" do
|
|
567
|
-
contact.
|
|
568
|
-
contact.
|
|
569
|
-
Flapjack::Data::Contact.
|
|
567
|
+
expect(contact).to receive(:add_tags).with('web')
|
|
568
|
+
expect(contact).to receive(:tags).and_return(['web'])
|
|
569
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
570
570
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
571
571
|
|
|
572
572
|
apost "contacts/#{contact.id}/tags", :tag => 'web'
|
|
573
|
-
last_response.
|
|
574
|
-
last_response.body.
|
|
573
|
+
expect(last_response).to be_ok
|
|
574
|
+
expect(last_response.body).to eq(['web'].to_json)
|
|
575
575
|
end
|
|
576
576
|
|
|
577
577
|
it "does not set a single tag on a contact that's not found" do
|
|
578
|
-
Flapjack::Data::Contact.
|
|
578
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
579
579
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
580
580
|
|
|
581
581
|
apost "contacts/#{contact.id}/tags", :tag => 'web'
|
|
582
|
-
last_response.
|
|
582
|
+
expect(last_response).to be_forbidden
|
|
583
583
|
end
|
|
584
584
|
|
|
585
585
|
it "sets multiple tags on a contact and returns current tags" do
|
|
586
|
-
contact.
|
|
587
|
-
contact.
|
|
588
|
-
Flapjack::Data::Contact.
|
|
586
|
+
expect(contact).to receive(:add_tags).with('web', 'app')
|
|
587
|
+
expect(contact).to receive(:tags).and_return(['web', 'app'])
|
|
588
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
589
589
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
590
590
|
|
|
591
591
|
apost "contacts/#{contact.id}/tags", :tag => ['web', 'app']
|
|
592
|
-
last_response.
|
|
593
|
-
last_response.body.
|
|
592
|
+
expect(last_response).to be_ok
|
|
593
|
+
expect(last_response.body).to eq(['web', 'app'].to_json)
|
|
594
594
|
end
|
|
595
595
|
|
|
596
596
|
it "does not set multiple tags on a contact that's not found" do
|
|
597
|
-
Flapjack::Data::Contact.
|
|
597
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
598
598
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
599
599
|
|
|
600
600
|
apost "contacts/#{contact.id}/tags", :tag => ['web', 'app']
|
|
601
|
-
last_response.
|
|
601
|
+
expect(last_response).to be_forbidden
|
|
602
602
|
end
|
|
603
603
|
|
|
604
604
|
it "removes a single tag from a contact" do
|
|
605
|
-
contact.
|
|
606
|
-
Flapjack::Data::Contact.
|
|
605
|
+
expect(contact).to receive(:delete_tags).with('web')
|
|
606
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
607
607
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
608
608
|
|
|
609
609
|
adelete "contacts/#{contact.id}/tags", :tag => 'web'
|
|
610
|
-
last_response.status.
|
|
610
|
+
expect(last_response.status).to eq(204)
|
|
611
611
|
end
|
|
612
612
|
|
|
613
613
|
it "does not remove a single tag from a contact that's not found" do
|
|
614
|
-
Flapjack::Data::Contact.
|
|
614
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
615
615
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
616
616
|
|
|
617
617
|
adelete "contacts/#{contact.id}/tags", :tag => 'web'
|
|
618
|
-
last_response.
|
|
618
|
+
expect(last_response).to be_forbidden
|
|
619
619
|
end
|
|
620
620
|
|
|
621
621
|
it "removes multiple tags from a contact" do
|
|
622
|
-
contact.
|
|
623
|
-
Flapjack::Data::Contact.
|
|
622
|
+
expect(contact).to receive(:delete_tags).with('web', 'app')
|
|
623
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
624
624
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
625
625
|
|
|
626
626
|
adelete "contacts/#{contact.id}/tags", :tag => ['web', 'app']
|
|
627
|
-
last_response.status.
|
|
627
|
+
expect(last_response.status).to eq(204)
|
|
628
628
|
end
|
|
629
629
|
|
|
630
630
|
it "does not remove multiple tags from a contact that's not found" do
|
|
631
|
-
Flapjack::Data::Contact.
|
|
631
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
632
632
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
633
633
|
|
|
634
634
|
adelete "contacts/#{contact.id}/tags", :tag => ['web', 'app']
|
|
635
|
-
last_response.
|
|
635
|
+
expect(last_response).to be_forbidden
|
|
636
636
|
end
|
|
637
637
|
|
|
638
638
|
it "gets all tags on a contact" do
|
|
639
|
-
contact.
|
|
640
|
-
Flapjack::Data::Contact.
|
|
639
|
+
expect(contact).to receive(:tags).and_return(['web', 'app'])
|
|
640
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
641
641
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
642
642
|
|
|
643
643
|
aget "contacts/#{contact.id}/tags"
|
|
644
|
-
last_response.
|
|
645
|
-
last_response.body.
|
|
644
|
+
expect(last_response).to be_ok
|
|
645
|
+
expect(last_response.body).to eq(['web', 'app'].to_json)
|
|
646
646
|
end
|
|
647
647
|
|
|
648
648
|
it "does not get all tags on a contact that's not found" do
|
|
649
|
-
Flapjack::Data::Contact.
|
|
649
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
650
650
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
651
651
|
|
|
652
652
|
aget "contacts/#{contact.id}/tags"
|
|
653
|
-
last_response.
|
|
653
|
+
expect(last_response).to be_forbidden
|
|
654
654
|
end
|
|
655
655
|
|
|
656
656
|
it "gets all entity tags for a contact" do
|
|
657
657
|
entity_1 = double(Flapjack::Data::Entity)
|
|
658
|
-
entity_1.
|
|
658
|
+
expect(entity_1).to receive(:name).and_return('entity_1')
|
|
659
659
|
entity_2 = double(Flapjack::Data::Entity)
|
|
660
|
-
entity_2.
|
|
660
|
+
expect(entity_2).to receive(:name).and_return('entity_2')
|
|
661
661
|
tag_data = [{:entity => entity_1, :tags => ['web']},
|
|
662
662
|
{:entity => entity_2, :tags => ['app']}]
|
|
663
|
-
contact.
|
|
663
|
+
expect(contact).to receive(:entities).with(:tags => true).
|
|
664
664
|
and_return(tag_data)
|
|
665
665
|
|
|
666
|
-
Flapjack::Data::Contact.
|
|
666
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
667
667
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
668
668
|
|
|
669
669
|
aget "contacts/#{contact.id}/entity_tags"
|
|
670
|
-
last_response.
|
|
670
|
+
expect(last_response).to be_ok
|
|
671
671
|
tag_response = {'entity_1' => ['web'],
|
|
672
672
|
'entity_2' => ['app']}
|
|
673
|
-
last_response.body.
|
|
673
|
+
expect(last_response.body).to eq(tag_response.to_json)
|
|
674
674
|
end
|
|
675
675
|
|
|
676
676
|
it "does not get all entity tags for a contact that's not found" do
|
|
677
|
-
Flapjack::Data::Contact.
|
|
677
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
678
678
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
679
679
|
|
|
680
680
|
aget "contacts/#{contact.id}/entity_tags"
|
|
681
|
-
last_response.
|
|
681
|
+
expect(last_response).to be_forbidden
|
|
682
682
|
end
|
|
683
683
|
|
|
684
684
|
it "adds tags to multiple entities for a contact" do
|
|
685
685
|
entity_1 = double(Flapjack::Data::Entity)
|
|
686
|
-
entity_1.
|
|
687
|
-
entity_1.
|
|
686
|
+
expect(entity_1).to receive(:name).twice.and_return('entity_1')
|
|
687
|
+
expect(entity_1).to receive(:add_tags).with('web')
|
|
688
688
|
entity_2 = double(Flapjack::Data::Entity)
|
|
689
|
-
entity_2.
|
|
690
|
-
entity_2.
|
|
689
|
+
expect(entity_2).to receive(:name).twice.and_return('entity_2')
|
|
690
|
+
expect(entity_2).to receive(:add_tags).with('app')
|
|
691
691
|
|
|
692
692
|
entities = [{:entity => entity_1}, {:entity => entity_2}]
|
|
693
|
-
contact.
|
|
693
|
+
expect(contact).to receive(:entities).and_return(entities)
|
|
694
694
|
tag_data = [{:entity => entity_1, :tags => ['web']},
|
|
695
695
|
{:entity => entity_2, :tags => ['app']}]
|
|
696
|
-
contact.
|
|
696
|
+
expect(contact).to receive(:entities).with(:tags => true).and_return(tag_data)
|
|
697
697
|
|
|
698
|
-
Flapjack::Data::Contact.
|
|
698
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
699
699
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
700
700
|
|
|
701
701
|
apost "contacts/#{contact.id}/entity_tags",
|
|
702
702
|
:entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
|
|
703
|
-
last_response.
|
|
703
|
+
expect(last_response).to be_ok
|
|
704
704
|
tag_response = {'entity_1' => ['web'],
|
|
705
705
|
'entity_2' => ['app']}
|
|
706
|
-
last_response.body.
|
|
706
|
+
expect(last_response.body).to eq(tag_response.to_json)
|
|
707
707
|
end
|
|
708
708
|
|
|
709
709
|
it "does not add tags to multiple entities for a contact that's not found" do
|
|
710
|
-
Flapjack::Data::Contact.
|
|
710
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
711
711
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
712
712
|
|
|
713
713
|
apost "contacts/#{contact.id}/entity_tags",
|
|
714
714
|
:entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
|
|
715
|
-
last_response.
|
|
715
|
+
expect(last_response).to be_forbidden
|
|
716
716
|
end
|
|
717
717
|
|
|
718
718
|
it "deletes tags from multiple entities for a contact" do
|
|
719
719
|
entity_1 = double(Flapjack::Data::Entity)
|
|
720
|
-
entity_1.
|
|
721
|
-
entity_1.
|
|
720
|
+
expect(entity_1).to receive(:name).and_return('entity_1')
|
|
721
|
+
expect(entity_1).to receive(:delete_tags).with('web')
|
|
722
722
|
entity_2 = double(Flapjack::Data::Entity)
|
|
723
|
-
entity_2.
|
|
724
|
-
entity_2.
|
|
723
|
+
expect(entity_2).to receive(:name).and_return('entity_2')
|
|
724
|
+
expect(entity_2).to receive(:delete_tags).with('app')
|
|
725
725
|
|
|
726
726
|
entities = [{:entity => entity_1}, {:entity => entity_2}]
|
|
727
|
-
contact.
|
|
727
|
+
expect(contact).to receive(:entities).and_return(entities)
|
|
728
728
|
|
|
729
|
-
Flapjack::Data::Contact.
|
|
729
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
730
730
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
|
731
731
|
|
|
732
732
|
adelete "contacts/#{contact.id}/entity_tags",
|
|
733
733
|
:entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
|
|
734
|
-
last_response.status.
|
|
734
|
+
expect(last_response.status).to eq(204)
|
|
735
735
|
end
|
|
736
736
|
|
|
737
737
|
it "does not delete tags from multiple entities for a contact that's not found" do
|
|
738
|
-
Flapjack::Data::Contact.
|
|
738
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
|
739
739
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
|
740
740
|
|
|
741
741
|
adelete "contacts/#{contact.id}/entity_tags",
|
|
742
742
|
:entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
|
|
743
|
-
last_response.
|
|
743
|
+
expect(last_response).to be_forbidden
|
|
744
744
|
end
|
|
745
745
|
|
|
746
746
|
|