lita-statuspage 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,26 +1,25 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-statuspage'
3
- spec.version = '0.2.0'
3
+ spec.version = '0.3.0'
4
4
  spec.authors = ['Eric Sigler']
5
5
  spec.email = ['me@esigler.com']
6
- spec.description = %q{A Lita handler to interact with Statuspage.io}
7
- spec.summary = %q{A Lita handler to interact with Statuspage.io}
6
+ spec.description = 'A Statuspage.io plugin for Lita'
7
+ spec.summary = spec.description
8
8
  spec.homepage = 'https://github.com/esigler/lita-statuspage'
9
9
  spec.license = 'MIT'
10
10
  spec.metadata = { 'lita_plugin_type' => 'handler' }
11
11
 
12
- spec.files = `git ls-files`.split($/)
12
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
13
13
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
14
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
15
  spec.require_paths = ['lib']
16
16
 
17
- spec.add_runtime_dependency 'lita', '>= 3.0'
18
- spec.add_runtime_dependency 'multi_json'
17
+ spec.add_runtime_dependency 'lita'
19
18
 
20
- spec.add_development_dependency 'bundler', '~> 1.3'
21
- spec.add_development_dependency 'rake'
22
- spec.add_development_dependency 'rspec', '>= 3.0.0.beta2'
23
- spec.add_development_dependency 'simplecov'
19
+ spec.add_development_dependency 'bundler'
24
20
  spec.add_development_dependency 'coveralls'
21
+ spec.add_development_dependency 'rake'
22
+ spec.add_development_dependency 'rspec'
25
23
  spec.add_development_dependency 'rubocop'
24
+ spec.add_development_dependency 'simplecov'
26
25
  end
@@ -2,3 +2,47 @@ en:
2
2
  lita:
3
3
  handlers:
4
4
  statuspage:
5
+ component:
6
+ updated: "Component %{id} updated"
7
+ not_found: Component not found
8
+ none: No components
9
+ invalid_status: Invalid status to use in updates
10
+ need_identifier: Need an identifier for the component
11
+ error:
12
+ invalid_arguments: "Error: invalid arguments"
13
+ api_request: Error making API request
14
+ help:
15
+ incident:
16
+ new:
17
+ syntax: sp incident new name:"<name>" status:<status> message:"<message>" twitter:<state> impact:<state>
18
+ desc: Create a new realtime incident'
19
+ update:
20
+ syntax: sp incident update id:ABC123 (...)
21
+ desc: Update an incident (takes same arguments as new)
22
+ list_all:
23
+ syntax: sp incident list all
24
+ desc: List all incidents
25
+ list_sch:
26
+ syntax: sp incident list scheduled
27
+ desc: List scheduled incidents
28
+ list_unr:
29
+ syntax: sp incident list unresolved
30
+ desc: List unresolved incidents
31
+ delete_l:
32
+ syntax: sp incident delete latest
33
+ desc: Delete latest incident
34
+ delete_i:
35
+ syntax: sp incident delete id:<id>
36
+ desc: Delete a specific incident
37
+ component:
38
+ list:
39
+ syntax: sp component list
40
+ desc: Lists all components
41
+ update:
42
+ syntax: sp component update
43
+ desc: Updates the component
44
+ incident:
45
+ created: "Incident %{id} created"
46
+ deleted: "Incident %{id} deleted"
47
+ updated: "Incident %{id} updated"
48
+ not_found: Incident not found
@@ -2,369 +2,357 @@ require 'spec_helper'
2
2
 
3
3
  describe Lita::Handlers::Statuspage, lita_handler: true do
4
4
  let(:incidents) do
5
- File.read('spec/files/incidents.json')
5
+ double('Faraday::Response',
6
+ status: 200,
7
+ body: File.read('spec/files/incidents.json'))
6
8
  end
7
9
 
8
10
  let(:incidents_empty) do
9
- '[]'
11
+ double('Faraday::Response',
12
+ status: 200,
13
+ body: '[]')
10
14
  end
11
15
 
12
16
  let(:incidents_scheduled) do
13
- File.read('spec/files/incidents_scheduled.json')
17
+ double('Faraday::Response',
18
+ status: 200,
19
+ body: File.read('spec/files/incidents_scheduled.json'))
14
20
  end
15
21
 
16
22
  let(:incidents_unresolved) do
17
- File.read('spec/files/incidents_unresolved.json')
23
+ double('Faraday::Response',
24
+ status: 200,
25
+ body: File.read('spec/files/incidents_unresolved.json'))
18
26
  end
19
27
 
20
28
  let(:incidents_updated) do
21
- File.read('spec/files/incidents_update.json')
29
+ double('Faraday::Response',
30
+ status: 200,
31
+ body: File.read('spec/files/incidents_update.json'))
22
32
  end
23
33
 
24
34
  let(:incident_new) do
25
- File.read('spec/files/incident_new.json')
35
+ double('Faraday::Response',
36
+ status: 201,
37
+ body: File.read('spec/files/incident_new.json'))
26
38
  end
27
39
 
28
40
  let(:incident_deleted) do
29
- File.read('spec/files/incident_deleted.json')
41
+ double('Faraday::Response',
42
+ status: 200,
43
+ body: File.read('spec/files/incident_deleted.json'))
30
44
  end
31
45
 
32
46
  let(:incident_updated) do
33
- File.read('spec/files/incident_updated.json')
47
+ double('Faraday::Response',
48
+ status: 200,
49
+ body: File.read('spec/files/incident_updated.json'))
34
50
  end
35
51
 
36
52
  let(:components) do
37
- File.read('spec/files/components.json')
53
+ double('Faraday::Response',
54
+ status: 200,
55
+ body: File.read('spec/files/components.json'))
38
56
  end
39
57
 
40
58
  let(:components_empty) do
41
- '[]'
59
+ double('Faraday::Response',
60
+ status: 200,
61
+ body: '[]')
42
62
  end
43
63
 
44
64
  let(:component_update) do
45
- File.read('spec/files/component_update.json')
65
+ double('Faraday::Response',
66
+ status: 200,
67
+ body: File.read('spec/files/component_update.json'))
46
68
  end
47
69
 
48
- it { routes_command('statuspage incident new name:"foo"').to(:incident_new) }
49
- it { routes_command('statuspage incident update latest').to(:incident_update) }
50
- it { routes_command('statuspage incident list').to(:incident_list_all) }
51
- it { routes_command('statuspage incident list all').to(:incident_list_all) }
52
- it { routes_command('statuspage incident list scheduled').to(:incident_list_scheduled) }
53
- it { routes_command('statuspage incident list unresolved').to(:incident_list_unresolved) }
54
- it { routes_command('statuspage incident delete latest').to(:incident_delete_latest) }
55
- it { routes_command('statuspage incident delete id:omgwtfbbq').to(:incident_delete) }
56
- it { routes_command('statuspage component list').to(:component_list) }
57
- it { routes_command('statuspage component list all').to(:component_list) }
58
- it { routes_command('statuspage component update latest').to(:component_update) }
59
-
60
- it { routes_command('sp incident new name:"foo"').to(:incident_new) }
61
- it { routes_command('sp incident update latest').to(:incident_update) }
62
- it { routes_command('sp incident list').to(:incident_list_all) }
63
- it { routes_command('sp incident list all').to(:incident_list_all) }
64
- it { routes_command('sp incident list scheduled').to(:incident_list_scheduled) }
65
- it { routes_command('sp incident list unresolved').to(:incident_list_unresolved) }
66
- it { routes_command('sp incident delete latest').to(:incident_delete_latest) }
67
- it { routes_command('sp incident delete id:omgwtfbbq').to(:incident_delete) }
68
- it { routes_command('sp component list').to(:component_list) }
69
- it { routes_command('sp component list all').to(:component_list) }
70
- it { routes_command('sp component update latest').to(:component_update) }
71
-
72
- describe '.default_config' do
73
- it 'sets api_key to nil' do
74
- expect(Lita.config.handlers.statuspage.api_key).to be_nil
75
- end
76
-
77
- it 'sets page_id to nil' do
78
- expect(Lita.config.handlers.statuspage.page_id).to be_nil
70
+ let(:generic_error) do
71
+ double('Faraday::Response',
72
+ status: 500,
73
+ body: '')
74
+ end
75
+
76
+ let(:generic_missing) do
77
+ double('Faraday::Response',
78
+ status: 404,
79
+ body: '')
80
+ end
81
+
82
+ def catch(symbol, result)
83
+ allow_any_instance_of(Faraday::Connection).to receive(symbol)
84
+ .and_return(result)
85
+ end
86
+
87
+ %w(statuspage sp).each do |name|
88
+ it do
89
+ is_expected.to route_command("#{name} incident new name:\"foo\"")
90
+ .to(:incident_new)
91
+ is_expected.to route_command("#{name} incident update latest")
92
+ .to(:incident_update)
93
+ is_expected.to route_command("#{name} incident list")
94
+ .to(:incident_list_all)
95
+ is_expected.to route_command("#{name} incident list all")
96
+ .to(:incident_list_all)
97
+ is_expected.to route_command("#{name} incident list scheduled")
98
+ .to(:incident_list_scheduled)
99
+ is_expected.to route_command("#{name} incident list unresolved")
100
+ .to(:incident_list_unresolved)
101
+ is_expected.to route_command("#{name} incident delete latest")
102
+ .to(:incident_delete_latest)
103
+ is_expected.to route_command("#{name} incident delete id:omgwtfbbq")
104
+ .to(:incident_delete)
105
+ is_expected.to route_command("#{name} component list")
106
+ .to(:component_list)
107
+ is_expected.to route_command("#{name} component list all")
108
+ .to(:component_list)
109
+ is_expected.to route_command("#{name} component update latest")
110
+ .to(:component_update)
111
+ end
112
+ end
113
+
114
+ before do
115
+ Lita.config.handlers.statuspage.api_key = 'foo'
116
+ Lita.config.handlers.statuspage.page_id = 'bar'
117
+ end
118
+
119
+ describe '#incident_new' do
120
+ it 'shows an ack when the incident is created' do
121
+ catch(:post, incident_new)
122
+ send_command('statuspage incident new name:"lp0 on fire"')
123
+ expect(replies.last).to eq('Incident b0m7dz4tzpl3 created')
124
+ end
125
+
126
+ it 'shows a warning if the incident does not have a required name' do
127
+ send_command('sp incident new status:investigating')
128
+ expect(replies.last).to eq('Error: invalid arguments')
129
+ end
130
+
131
+ it 'shows a warning if the incident status is not valid' do
132
+ send_command('sp incident new name:"It dun broke" status:ignoring')
133
+ expect(replies.last).to eq('Error: invalid arguments')
134
+ end
135
+
136
+ it 'shows a warning if the twitter status is not valid' do
137
+ send_command('sp incident new name:"It dun broke" twitter:lavender')
138
+ expect(replies.last).to eq('Error: invalid arguments')
139
+ end
140
+
141
+ it 'shows a warning if the impact value is not valid' do
142
+ send_command('sp incident new name:"It dun broke" impact:apocalypse')
143
+ expect(replies.last).to eq('Error: invalid arguments')
144
+ end
145
+
146
+ it 'shows an error if there was an issue creating the incident' do
147
+ catch(:get, generic_error)
148
+ send_command('statuspage incident new name:"It dun broke"')
149
+ expect(replies.last).to eq('Error making API request')
79
150
  end
80
151
  end
81
152
 
82
- describe 'without valid config' do
83
- it 'should error out on any command' do
84
- expect { send_command('statuspage incident list all') }.to raise_error('Missing config')
153
+ describe '#incident_update' do
154
+ it 'shows an ack when the incident is updated' do
155
+ catch(:get, incidents_updated)
156
+ catch(:patch, incident_updated)
157
+ send_command('statuspage incident update id:b0m7dz4tzpl3 ' \
158
+ 'message:"Howdy"')
159
+ expect(replies.last).to eq('Incident b0m7dz4tzpl3 updated')
160
+ end
161
+
162
+ it 'shows a warning if the incident does not exist' do
163
+ catch(:get, incidents)
164
+ send_command('sp incident update id:b0m7dz4tzpl3 message:"Howdy"')
165
+ expect(replies.last).to eq('Incident not found')
166
+ end
167
+
168
+ it 'shows a warning if the incident does not have an id' do
169
+ send_command('sp incident update status:investigating')
170
+ expect(replies.last).to eq('Error: invalid arguments')
171
+ end
172
+
173
+ it 'shows a warning if the incident status is not valid' do
174
+ send_command('sp incident update id:b0m7dz4tzpl3 status:running_away')
175
+ expect(replies.last).to eq('Error: invalid arguments')
176
+ end
177
+
178
+ it 'shows a warning if the twitter status is not valid' do
179
+ send_command('sp incident update id:b0m7dz4tzpl3 twitter:magenta')
180
+ expect(replies.last).to eq('Error: invalid arguments')
181
+ end
182
+
183
+ it 'shows a warning if the impact value is not valid' do
184
+ send_command('sp incident update id:b0m7dz4tzpl3 impact:ragnarok')
185
+ expect(replies.last).to eq('Error: invalid arguments')
186
+ end
187
+
188
+ it 'shows an error if there was an issue updating the incident' do
189
+ catch(:get, incidents_updated)
190
+ catch(:patch, generic_error)
191
+ send_command('sp incident update id:b0m7dz4tzpl3 message:"Howdy"')
192
+ expect(replies.last).to eq('Error making API request')
193
+ end
194
+ end
195
+
196
+ describe '#incident_list_all' do
197
+ it 'shows a list of incidents if there are any' do
198
+ catch(:get, incidents)
199
+ send_command('sp incident list all')
200
+ expect(replies.last).to eq('Test Incident (created: 2014-03-24, ' \
201
+ 'status: resolved, id:td9ftgzcyz4m)')
202
+ end
203
+
204
+ it 'shows a warning if there arent any' do
205
+ catch(:get, incidents_empty)
206
+ send_command('sp incident list all')
207
+ expect(replies.last).to eq('No incidents to list')
208
+ end
209
+
210
+ it 'shows an error if there was an issue fetching the incidents' do
211
+ catch(:get, generic_error)
212
+ send_command('sp incident list all')
213
+ expect(replies.last).to eq('Error making API request')
85
214
  end
86
215
  end
87
216
 
88
- describe 'with valid config' do
89
- before do
90
- Lita.config.handlers.statuspage.api_key = 'foo'
91
- Lita.config.handlers.statuspage.page_id = 'bar'
92
- end
93
-
94
- describe '#incident_new' do
95
- it 'shows an ack when the incident is created' do
96
- response = double('Faraday::Response', status: 201, body: incident_new)
97
- allow_any_instance_of(Faraday::Connection).to receive(:post).and_return(response)
98
- send_command('statuspage incident new name:"lp0 on fire"')
99
- expect(replies.last).to eq('Incident b0m7dz4tzpl3 created')
100
- end
101
-
102
- it 'shows a warning if the incident does not have a required name' do
103
- send_command('statuspage incident new status:investigating')
104
- expect(replies.last).to eq('Can\'t create incident, missing incident name')
105
- end
106
-
107
- it 'shows a warning if the incident status is not valid' do
108
- send_command('statuspage incident new name:"It dun broke" status:ignoring')
109
- expect(replies.last).to eq('Can\'t create incident, invalid incident state')
110
- end
111
-
112
- it 'shows a warning if the twitter status is not valid' do
113
- send_command('statuspage incident new name:"It dun broke" twitter:lavender')
114
- expect(replies.last).to eq('Can\'t create incident, invalid twitter state')
115
- end
116
-
117
- it 'shows a warning if the impact value is not valid' do
118
- send_command('statuspage incident new name:"It dun broke" impact:apocalypse')
119
- expect(replies.last).to eq('Can\'t create incident, invalid impact value')
120
- end
121
-
122
- it 'shows an error if there was an issue creating the incident' do
123
- response = double('Faraday::Response', status: 500, body: '')
124
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
125
- send_command('statuspage incident new name:"It dun broke"')
126
- expect(replies.last).to eq('Error creating incident')
127
- end
128
- end
129
-
130
- describe '#incident_update' do
131
- it 'shows an ack when the incident is updated' do
132
- get_response = double('Faraday::Response', status: 200, body: incidents_updated)
133
- patch_response = double('Faraday::Response', status: 200, body: incident_updated)
134
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(get_response)
135
- allow_any_instance_of(Faraday::Connection).to receive(:patch).and_return(patch_response)
136
- send_command('statuspage incident update id:b0m7dz4tzpl3 message:"Howdy"')
137
- expect(replies.last).to eq('Incident b0m7dz4tzpl3 updated')
138
- end
139
-
140
- it 'shows a warning if the incident does not exist' do
141
- response = double('Faraday::Response', status: 200, body: incidents)
142
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
143
- send_command('statuspage incident update id:b0m7dz4tzpl3 message:"Howdy"')
144
- expect(replies.last).to eq('Can\'t update incident, does not exist')
145
- end
146
-
147
- it 'shows a warning if there is nothing to update' do
148
- send_command('statuspage incident update id:b0m7dz4tzpl3')
149
- expect(replies.last).to eq('Can\'t update incident, nothing to update')
150
- end
151
-
152
- it 'shows a warning if the incident does not have an id' do
153
- send_command('statuspage incident update status:investigating')
154
- expect(replies.last).to eq('Can\'t update incident, missing incident ID')
155
- end
156
-
157
- it 'shows a warning if the incident status is not valid' do
158
- send_command('statuspage incident update id:b0m7dz4tzpl3 status:running_away')
159
- expect(replies.last).to eq('Can\'t update incident, invalid incident state')
160
- end
161
-
162
- it 'shows a warning if the twitter status is not valid' do
163
- send_command('statuspage incident update id:b0m7dz4tzpl3 twitter:magenta')
164
- expect(replies.last).to eq('Can\'t update incident, invalid twitter state')
165
- end
166
-
167
- it 'shows a warning if the impact value is not valid' do
168
- send_command('statuspage incident update id:b0m7dz4tzpl3 impact:ragnarok')
169
- expect(replies.last).to eq('Can\'t update incident, invalid impact value')
170
- end
171
-
172
- it 'shows an error if there was an issue updating the incident' do
173
- get_response = double('Faraday::Response', status: 200, body: incidents_updated)
174
- patch_response = double('Faraday::Response', status: 500, body: '')
175
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(get_response)
176
- allow_any_instance_of(Faraday::Connection).to receive(:patch).and_return(patch_response)
177
- send_command('statuspage incident update id:b0m7dz4tzpl3 message:"Howdy"')
178
- expect(replies.last).to eq('Error updating incident')
179
- end
180
- end
181
-
182
- describe '#incident_list_all' do
183
- it 'shows a list of incidents if there are any' do
184
- response = double('Faraday::Response', status: 200, body: incidents)
185
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
186
- send_command('statuspage incident list all')
187
- expect(replies.last).to eq('Test Incident (created: 2014-03-24, ' \
188
- 'status: resolved, id:td9ftgzcyz4m)')
189
- end
190
-
191
- it 'shows a warning if there arent any' do
192
- response = double('Faraday::Response', status: 200, body: incidents_empty)
193
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
194
- send_command('statuspage incident list all')
195
- expect(replies.last).to eq('No incidents to list')
196
- end
197
-
198
- it 'shows an error if there was an issue fetching the incidents' do
199
- response = double('Faraday::Response', status: 500, body: '')
200
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
201
- send_command('statuspage incident list all')
202
- expect(replies.last).to eq('Error fetching incidents')
203
- end
204
- end
205
-
206
- describe '#incident_list_scheduled' do
207
- it 'shows a list of incidents if there are any' do
208
- response = double('Faraday::Response', status: 200, body: incidents_scheduled)
209
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
210
- send_command('statuspage incident list scheduled')
211
- expect(replies.last).to eq('Test Maintenance (created: 2014-03-30, ' \
212
- 'status: scheduled, id:3tzsm37ryws0)')
213
- end
214
-
215
- it 'shows a warning if there arent any' do
216
- response = double('Faraday::Response', status: 200, body: incidents_empty)
217
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
218
- send_command('statuspage incident list scheduled')
219
- expect(replies.last).to eq('No incidents to list')
220
- end
221
-
222
- it 'shows an error if there was an issue fetching the incidents' do
223
- response = double('Faraday::Response', status: 500, body: '')
224
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
225
- send_command('statuspage incident list scheduled')
226
- expect(replies.last).to eq('Error fetching incidents')
227
- end
228
- end
229
-
230
- describe '#incident_list_unresolved' do
231
- it 'shows a list of incidents if there are any' do
232
- response = double('Faraday::Response', status: 200, body: incidents_unresolved)
233
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
234
- send_command('statuspage incident list unresolved')
235
- expect(replies.last).to eq('Unresolved incident (created: 2014-03-30, ' \
236
- 'status: investigating, id:2ttv50n0n8zj)')
237
- end
238
-
239
- it 'shows a warning if there arent any' do
240
- response = double('Faraday::Response', status: 200, body: incidents_empty)
241
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
242
- send_command('statuspage incident list scheduled')
243
- expect(replies.last).to eq('No incidents to list')
244
- end
245
-
246
- it 'shows an error if there was an issue fetching the incidents' do
247
- response = double('Faraday::Response', status: 500, body: '')
248
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
249
- send_command('statuspage incident list scheduled')
250
- expect(replies.last).to eq('Error fetching incidents')
251
- end
252
- end
253
-
254
- describe '#incident_delete_latest' do
255
- it 'shows an ack if the incident was deleted' do
256
- get_response = double('Faraday::Response', status: 200, body: incidents_unresolved)
257
- delete_response = double('Faraday::Response', status: 200, body: incident_deleted)
258
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(get_response)
259
- allow_any_instance_of(Faraday::Connection).to receive(:delete).and_return(delete_response)
260
- send_command('statuspage incident delete latest')
261
- expect(replies.last).to eq('Incident 2ttv50n0n8zj deleted')
262
- end
263
-
264
- it 'shows a warning if there wasnt an incident to delete' do
265
- response = double('Faraday::Response', status: 404, body: '')
266
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
267
- send_command('statuspage incident delete latest')
268
- expect(replies.last).to eq('No latest incident found')
269
- end
270
-
271
- it 'shows an error if there was an issue deleting the incident' do
272
- get_response = double('Faraday::Response', status: 200, body: incidents_unresolved)
273
- delete_response = double('Faraday::Response', status: 500, body: '')
274
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(get_response)
275
- allow_any_instance_of(Faraday::Connection).to receive(:delete).and_return(delete_response)
276
- send_command('statuspage incident delete latest')
277
- expect(replies.last).to eq('Error deleting incident')
278
- end
279
- end
280
-
281
- describe '#incident_delete' do
282
- it 'shows an ack if the incident was deleted' do
283
- get_response = double('Faraday::Response', status: 200, body: incidents_unresolved)
284
- delete_response = double('Faraday::Response', status: 200, body: incident_deleted)
285
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(get_response)
286
- allow_any_instance_of(Faraday::Connection).to receive(:delete).and_return(delete_response)
287
- send_command('statuspage incident delete id:2ttv50n0n8zj')
288
- expect(replies.last).to eq('Incident 2ttv50n0n8zj deleted')
289
- end
290
-
291
- it 'shows a warning if there wasnt an incident to delete' do
292
- response = double('Faraday::Response', status: 404, body: '')
293
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
294
- send_command('statuspage incident delete id:2ttv50n0n8zj')
295
- expect(replies.last).to eq('Incident not found')
296
- end
297
-
298
- it 'shows an error if there was an issue deleting the incident' do
299
- get_response = double('Faraday::Response', status: 200, body: incidents_unresolved)
300
- delete_response = double('Faraday::Response', status: 500, body: '')
301
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(get_response)
302
- allow_any_instance_of(Faraday::Connection).to receive(:delete).and_return(delete_response)
303
- send_command('statuspage incident delete id:2ttv50n0n8zj')
304
- expect(replies.last).to eq('Error deleting incident')
305
- end
306
- end
307
-
308
- describe '#component_list' do
309
- it 'shows a list of components if there are any' do
310
- response = double('Faraday::Response', status: 200, body: components)
311
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
312
- send_command('statuspage component list')
313
- expect(replies.last).to eq('Management Portal (example) (status: operational, id:v6z6tpldcw85)')
314
- end
315
-
316
- it 'shows a warning if there arent any' do
317
- response = double('Faraday::Response', status: 200, body: components_empty)
318
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
319
- send_command('statuspage component list')
320
- expect(replies.last).to eq('No components to list')
321
- end
322
-
323
- it 'shows an error if there was an issue fetching the components' do
324
- response = double('Faraday::Response', status: 500, body: '')
325
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
326
- send_command('statuspage component list')
327
- expect(replies.last).to eq('Error fetching components')
328
- end
329
- end
330
-
331
- describe '#component_update' do
332
- it 'shows an ack if the component is updated via id' do
333
- get_response = double('Faraday::Response', status: 200, body: components)
334
- patch_response = double('Faraday::Response', status: 200, body: component_update)
335
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(get_response)
336
- allow_any_instance_of(Faraday::Connection).to receive(:patch).and_return(patch_response)
337
- send_command('statuspage component update id:v6z6tpldcw85 status:major_outage')
338
- expect(replies.last).to eq('Component v6z6tpldcw85 updated')
339
- end
340
-
341
- it 'shows an ack if the component is updated via name' do
342
- get_response = double('Faraday::Response', status: 200, body: components)
343
- patch_response = double('Faraday::Response', status: 200, body: component_update)
344
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(get_response)
345
- allow_any_instance_of(Faraday::Connection).to receive(:patch).and_return(patch_response)
346
- send_command('statuspage component update name:"Management Portal (example)" status:major_outage')
347
- expect(replies.last).to eq('Component v6z6tpldcw85 updated')
348
- end
349
-
350
- it 'shows a warning if there is no identifier to the component' do
351
- send_command('statuspage component update status:major_outage')
352
- expect(replies.last).to eq('Need an identifier for the component')
353
- end
354
-
355
- it 'shows a warning if the status is invalid' do
356
- send_command('statuspage component update id:v6z6tpldcw85 status:big_problem')
357
- expect(replies.last).to eq('Invalid status to use in updates')
358
- end
359
-
360
- it 'shows an error if there was an issue updating the component' do
361
- get_response = double('Faraday::Response', status: 200, body: components)
362
- patch_response = double('Faraday::Response', status: 500, body: '')
363
- allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(get_response)
364
- allow_any_instance_of(Faraday::Connection).to receive(:patch).and_return(patch_response)
365
- send_command('statuspage component update id:v6z6tpldcw85 status:major_outage')
366
- expect(replies.last).to eq('Error updating component')
367
- end
217
+ describe '#incident_list_scheduled' do
218
+ it 'shows a list of incidents if there are any' do
219
+ catch(:get, incidents_scheduled)
220
+ send_command('sp incident list scheduled')
221
+ expect(replies.last).to eq('Test Maintenance (created: 2014-03-30, ' \
222
+ 'status: scheduled, id:3tzsm37ryws0)')
223
+ end
224
+
225
+ it 'shows a warning if there arent any' do
226
+ catch(:get, incidents_empty)
227
+ send_command('sp incident list scheduled')
228
+ expect(replies.last).to eq('No incidents to list')
229
+ end
230
+
231
+ it 'shows an error if there was an issue fetching the incidents' do
232
+ catch(:get, generic_error)
233
+ send_command('sp incident list scheduled')
234
+ expect(replies.last).to eq('Error making API request')
235
+ end
236
+ end
237
+
238
+ describe '#incident_list_unresolved' do
239
+ it 'shows a list of incidents if there are any' do
240
+ catch(:get, incidents_unresolved)
241
+ send_command('statuspage incident list unresolved')
242
+ expect(replies.last).to eq('Unresolved incident (created: ' \
243
+ '2014-03-30, status: investigating, ' \
244
+ 'id:2ttv50n0n8zj)')
245
+ end
246
+
247
+ it 'shows a warning if there arent any' do
248
+ catch(:get, incidents_empty)
249
+ send_command('statuspage incident list scheduled')
250
+ expect(replies.last).to eq('No incidents to list')
251
+ end
252
+
253
+ it 'shows an error if there was an issue fetching the incidents' do
254
+ catch(:get, generic_error)
255
+ send_command('statuspage incident list scheduled')
256
+ expect(replies.last).to eq('Error making API request')
257
+ end
258
+ end
259
+
260
+ describe '#incident_delete_latest' do
261
+ it 'shows an ack if the incident was deleted' do
262
+ catch(:get, incidents_unresolved)
263
+ catch(:delete, incident_deleted)
264
+ send_command('statuspage incident delete latest')
265
+ expect(replies.last).to eq('Incident 2ttv50n0n8zj deleted')
266
+ end
267
+
268
+ it 'shows a warning if there wasnt an incident to delete' do
269
+ catch(:get, generic_missing)
270
+ send_command('statuspage incident delete latest')
271
+ expect(replies.last).to eq('Incident not found')
272
+ end
273
+
274
+ it 'shows an error if there was an issue deleting the incident' do
275
+ catch(:get, incidents_unresolved)
276
+ catch(:delete, generic_error)
277
+ send_command('statuspage incident delete latest')
278
+ expect(replies.last).to eq('Error making API request')
279
+ end
280
+ end
281
+
282
+ describe '#incident_delete' do
283
+ it 'shows an ack if the incident was deleted' do
284
+ catch(:get, incidents_unresolved)
285
+ catch(:delete, incident_deleted)
286
+ send_command('statuspage incident delete id:2ttv50n0n8zj')
287
+ expect(replies.last).to eq('Incident 2ttv50n0n8zj deleted')
288
+ end
289
+
290
+ it 'shows a warning if there wasnt an incident to delete' do
291
+ catch(:get, generic_missing)
292
+ send_command('statuspage incident delete id:2ttv50n0n8zj')
293
+ expect(replies.last).to eq('Incident not found')
294
+ end
295
+
296
+ it 'shows an error if there was an issue deleting the incident' do
297
+ catch(:get, incidents_unresolved)
298
+ catch(:delete, generic_error)
299
+ send_command('statuspage incident delete id:2ttv50n0n8zj')
300
+ expect(replies.last).to eq('Error making API request')
301
+ end
302
+ end
303
+
304
+ describe '#component_list' do
305
+ it 'shows a list of components if there are any' do
306
+ catch(:get, components)
307
+ send_command('statuspage component list')
308
+ expect(replies.last).to eq('Management Portal (example) ' \
309
+ '(status: operational, id:v6z6tpldcw85)')
310
+ end
311
+
312
+ it 'shows a warning if there arent any' do
313
+ catch(:get, components_empty)
314
+ send_command('statuspage component list')
315
+ expect(replies.last).to eq('No components')
316
+ end
317
+
318
+ it 'shows an error if there was an issue fetching the components' do
319
+ catch(:get, generic_error)
320
+ send_command('statuspage component list')
321
+ expect(replies.last).to eq('Error making API request')
322
+ end
323
+ end
324
+
325
+ describe '#component_update' do
326
+ it 'shows an ack if the component is updated via id' do
327
+ catch(:get, components)
328
+ catch(:patch, component_update)
329
+ send_command('sp component update id:v6z6tpldcw85 status:major_outage')
330
+ expect(replies.last).to eq('Component v6z6tpldcw85 updated')
331
+ end
332
+
333
+ it 'shows an ack if the component is updated via name' do
334
+ catch(:get, components)
335
+ catch(:patch, component_update)
336
+ send_command('sp component update name:"Management Portal ' \
337
+ '(example)" status:major_outage')
338
+ expect(replies.last).to eq('Component v6z6tpldcw85 updated')
339
+ end
340
+
341
+ it 'shows a warning if there is no identifier to the component' do
342
+ send_command('sp component update status:major_outage')
343
+ expect(replies.last).to eq('Need an identifier for the component')
344
+ end
345
+
346
+ it 'shows a warning if the status is invalid' do
347
+ send_command('sp component update id:v6z6tpldcw85 status:big_problem')
348
+ expect(replies.last).to eq('Invalid status to use in updates')
349
+ end
350
+
351
+ it 'shows an error if there was an issue updating the component' do
352
+ catch(:get, components)
353
+ catch(:patch, generic_error)
354
+ send_command('sp component update id:v6z6tpldcw85 status:major_outage')
355
+ expect(replies.last).to eq('Error making API request')
368
356
  end
369
357
  end
370
358
  end