lita-pagerduty 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -1
  3. data/.rubocop.yml +6 -5
  4. data/README.md +11 -9
  5. data/Rakefile +4 -2
  6. data/lib/exceptions.rb +11 -0
  7. data/lib/lita-pagerduty.rb +7 -29
  8. data/lib/lita/commands/ack.rb +15 -0
  9. data/lib/lita/commands/ack_all.rb +21 -0
  10. data/lib/lita/commands/ack_mine.rb +26 -0
  11. data/lib/lita/commands/base.rb +75 -0
  12. data/lib/lita/commands/forget.rb +13 -0
  13. data/lib/lita/commands/identify.rb +13 -0
  14. data/lib/lita/commands/incident.rb +13 -0
  15. data/lib/lita/commands/incidents_all.rb +18 -0
  16. data/lib/lita/commands/incidents_mine.rb +23 -0
  17. data/lib/lita/commands/notes.rb +15 -0
  18. data/lib/lita/commands/on_call_list.rb +13 -0
  19. data/lib/lita/commands/on_call_lookup.rb +41 -0
  20. data/lib/lita/commands/pager_me.rb +48 -0
  21. data/lib/lita/commands/resolve.rb +15 -0
  22. data/lib/lita/commands/resolve_all.rb +21 -0
  23. data/lib/lita/commands/resolve_mine.rb +26 -0
  24. data/lib/lita/handlers/commands.yml +30 -0
  25. data/lib/lita/handlers/pagerduty.rb +57 -0
  26. data/lib/pagerduty.rb +94 -0
  27. data/lib/store.rb +20 -0
  28. data/lita-pagerduty.gemspec +1 -2
  29. data/locales/en.yml +2 -2
  30. data/spec/lita/handlers/ack_all_spec.rb +26 -0
  31. data/spec/lita/handlers/ack_id_spec.rb +23 -0
  32. data/spec/lita/handlers/ack_mine_spec.rb +38 -0
  33. data/spec/lita/handlers/forget_spec.rb +22 -0
  34. data/spec/lita/handlers/identify_email_spec.rb +22 -0
  35. data/spec/lita/handlers/incident_id_spec.rb +23 -0
  36. data/spec/lita/handlers/incidents_all_spec.rb +31 -0
  37. data/spec/lita/handlers/incidents_mine_spec.rb +35 -0
  38. data/spec/lita/handlers/notes_spec.rb +29 -0
  39. data/spec/lita/handlers/on_call_list_spec.rb +21 -0
  40. data/spec/lita/handlers/on_call_lookup_spec.rb +29 -0
  41. data/spec/lita/handlers/pager_me_spec.rb +56 -0
  42. data/spec/lita/handlers/resolve_all_spec.rb +26 -0
  43. data/spec/lita/handlers/resolve_id_spec.rb +21 -0
  44. data/spec/lita/handlers/resolve_mine_spec.rb +38 -0
  45. data/spec/pagerduty_spec.rb +106 -0
  46. data/spec/spec_helper.rb +3 -189
  47. data/templates/.gitkeep +0 -0
  48. metadata +57 -35
  49. data/lib/lita/handlers/pagerduty_ack.rb +0 -77
  50. data/lib/lita/handlers/pagerduty_incident.rb +0 -68
  51. data/lib/lita/handlers/pagerduty_note.rb +0 -50
  52. data/lib/lita/handlers/pagerduty_resolve.rb +0 -77
  53. data/lib/lita/handlers/pagerduty_utility.rb +0 -136
  54. data/lib/pagerduty_helper/incident.rb +0 -64
  55. data/lib/pagerduty_helper/regex.rb +0 -8
  56. data/lib/pagerduty_helper/utility.rb +0 -43
  57. data/spec/lita/handlers/pagerduty_ack_spec.rb +0 -95
  58. data/spec/lita/handlers/pagerduty_incident_spec.rb +0 -103
  59. data/spec/lita/handlers/pagerduty_note_spec.rb +0 -43
  60. data/spec/lita/handlers/pagerduty_resolve_spec.rb +0 -95
  61. data/spec/lita/handlers/pagerduty_utility_spec.rb +0 -59
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::Pagerduty, lita_handler: true do
4
+ context 'pager forget' do
5
+ it do
6
+ is_expected.to route_command('pager forget').to(:forget)
7
+ end
8
+
9
+ it 'existing' do
10
+ user = Lita::User.create(123, name: 'foo')
11
+ send_command('pager identify foo@example.com', as: user)
12
+ send_command('pager forget', as: user)
13
+ expect(replies.last).to eq('Your email has now been forgotten.')
14
+ end
15
+
16
+ it 'non-existing' do
17
+ user = Lita::User.create(123, name: 'foo')
18
+ send_command('pager forget', as: user)
19
+ expect(replies.last).to eq('No email on record for you.')
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::Pagerduty, lita_handler: true do
4
+ context 'pager identify foobar@example.com' do
5
+ it do
6
+ is_expected.to route_command('pager identify foobar@example.com').to(:identify)
7
+ end
8
+
9
+ it 'identify first time' do
10
+ user = Lita::User.create(123, name: 'foo')
11
+ send_command('pager identify foo@example.com', as: user)
12
+ expect(replies.last).to eq('You have now been identified.')
13
+ end
14
+
15
+ it 'identify existing user' do
16
+ user = Lita::User.create(123, name: 'foo')
17
+ send_command('pager identify foo@example.com', as: user)
18
+ send_command('pager identify foo@example.com', as: user)
19
+ expect(replies.last).to eq('You have already been identified!')
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::Pagerduty, lita_handler: true do
4
+ context 'incident ABC123' do
5
+ it do
6
+ is_expected.to route_command('pager incident ABC123').to(:incident)
7
+ end
8
+
9
+ it 'found' do
10
+ expect_any_instance_of(Pagerduty).to receive(:get_incident).and_return({
11
+ id: 'ABC123', title: 'ABC', html_url: 'https://foo.pagerduty.com/incidents/ABC123'
12
+ })
13
+ send_command('pager incident ABC123')
14
+ expect(replies.last).to eq('ABC123: "ABC", assigned to: "none", url: https://foo.pagerduty.com/incidents/ABC123')
15
+ end
16
+
17
+ it 'not found' do
18
+ expect_any_instance_of(Pagerduty).to receive(:get_incident).and_raise(Exceptions::IncidentNotFound)
19
+ send_command('pager incident ABC123')
20
+ expect(replies.last).to eq('ABC123: Incident not found')
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::Pagerduty, lita_handler: true do
4
+ context 'incidents all' do
5
+ it do
6
+ is_expected.to route_command('pager incidents all').to(:incidents_all)
7
+ end
8
+
9
+ it 'empty list' do
10
+ expect_any_instance_of(Pagerduty).to receive(:get_incidents).and_raise(Exceptions::IncidentsEmptyList)
11
+ send_command('pager incidents all')
12
+ expect(replies.last).to eq('No triggered, open, or acknowledged incidents')
13
+ end
14
+
15
+ it 'list of incidents' do
16
+ expect_any_instance_of(Pagerduty).to receive(:get_incidents).and_return([
17
+ { id: 'ABC123', title: 'ABC', html_url: 'https://foo.pagerduty.com/incidents/ABC123' }
18
+ ])
19
+ send_command('pager incidents all')
20
+ expect(replies.last).to eq('ABC123: "ABC", assigned to: "none", url: https://foo.pagerduty.com/incidents/ABC123')
21
+ end
22
+
23
+ it 'list of assigned incidents' do
24
+ expect_any_instance_of(Pagerduty).to receive(:get_incidents).and_return([
25
+ { id: 'ABC123', title: 'ABC', html_url: 'https://foo.pagerduty.com/incidents/ABC123', assignments: [{ assignee: { summary: 'foo' } }] }
26
+ ])
27
+ send_command('pager incidents all')
28
+ expect(replies.last).to eq('ABC123: "ABC", assigned to: "foo", url: https://foo.pagerduty.com/incidents/ABC123')
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::Pagerduty, lita_handler: true do
4
+ context 'incidents mine' do
5
+ it do
6
+ is_expected.to route_command('pager incidents mine').to(:incidents_mine)
7
+ end
8
+
9
+ it 'unknown user' do
10
+ user = Lita::User.create(123, name: 'foo')
11
+ send_command('pager incidents mine', as: user)
12
+ expect(replies.last).to eq('You have no triggered, open, or acknowledged incidents')
13
+ end
14
+
15
+ it 'empty list' do
16
+ user = Lita::User.create(123, name: 'foo')
17
+ send_command('pager identify foo@pagerduty.com', as: user)
18
+ expect_any_instance_of(Pagerduty).to receive(:get_users).and_return([{ id: 'abc123'}])
19
+ expect_any_instance_of(Pagerduty).to receive(:get_incidents).and_raise(Exceptions::IncidentsEmptyList)
20
+ send_command('pager incidents mine', as: user)
21
+ expect(replies.last).to eq('No triggered, open, or acknowledged incidents')
22
+ end
23
+
24
+ it 'list of incidents' do
25
+ user = Lita::User.create(123, name: 'foo')
26
+ send_command('pager identify foo@pagerduty.com', as: user)
27
+ expect_any_instance_of(Pagerduty).to receive(:get_users).and_return([{ id: 'abc123'}])
28
+ expect_any_instance_of(Pagerduty).to receive(:get_incidents).and_return([
29
+ { id: 'ABC123', title: 'ABC', html_url: 'https://foo.pagerduty.com/incidents/ABC123', assignments: [{ assignee: { summary: 'foo' } }] }
30
+ ])
31
+ send_command('pager incidents mine', as: user)
32
+ expect(replies.last).to eq('ABC123: "ABC", assigned to: "foo", url: https://foo.pagerduty.com/incidents/ABC123')
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::Pagerduty, lita_handler: true do
4
+ context 'notes ABC123' do
5
+ it do
6
+ is_expected.to route_command('pager notes ABC123').to(:notes)
7
+ end
8
+
9
+ it 'incident not found' do
10
+ expect_any_instance_of(Pagerduty).to receive(:get_notes_by_incident_id).and_raise(Exceptions::IncidentNotFound)
11
+ send_command('pager notes ABC123')
12
+ expect(replies.last).to eq('ABC123: Incident not found')
13
+ end
14
+
15
+ it 'notes list' do
16
+ expect_any_instance_of(Pagerduty).to receive(:get_notes_by_incident_id).and_return([
17
+ { content: 'Content', user: { summary: 'foo' } }
18
+ ])
19
+ send_command('pager notes ABC123')
20
+ expect(replies.last).to eq('ABC123: Content (foo)')
21
+ end
22
+
23
+ it 'empty notes list' do
24
+ expect_any_instance_of(Pagerduty).to receive(:get_notes_by_incident_id).and_raise(Exceptions::NotesEmptyList)
25
+ send_command('pager notes ABC123')
26
+ expect(replies.last).to eq('ABC123: No notes')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::Pagerduty, lita_handler: true do
4
+ context 'oncall' do
5
+ it do
6
+ is_expected.to route_command('pager oncall').to(:on_call_list)
7
+ end
8
+
9
+ it 'empty list' do
10
+ expect_any_instance_of(Pagerduty).to receive(:get_schedules).and_raise(Exceptions::SchedulesEmptyList)
11
+ send_command('pager oncall')
12
+ expect(replies.last).to eq('No schedules found')
13
+ end
14
+
15
+ it 'list' do
16
+ expect_any_instance_of(Pagerduty).to receive(:get_schedules).and_return([{ name: 'A' }, { name: 'B' }])
17
+ send_command('pager oncall')
18
+ expect(replies.last).to eq("Available schedules:\nA\nB")
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::Pagerduty, lita_handler: true do
4
+ context 'oncall abc' do
5
+ it do
6
+ is_expected.to route_command('pager oncall abc').to(:on_call_lookup)
7
+ end
8
+
9
+ it 'schedule not found' do
10
+ expect_any_instance_of(Pagerduty).to receive(:get_schedules).and_raise(Exceptions::SchedulesEmptyList)
11
+ send_command('pager oncall abc')
12
+ expect(replies.last).to eq('No matching schedules found for \'abc\'')
13
+ end
14
+
15
+ it 'no one on call' do
16
+ expect_any_instance_of(Pagerduty).to receive(:get_schedules).and_return([{ id: 'abc123' }])
17
+ expect_any_instance_of(Pagerduty).to receive(:get_oncall_user).and_raise(Exceptions::NoOncallUser)
18
+ send_command('pager oncall abc')
19
+ expect(replies.last).to eq('No one is currently on call for abc')
20
+ end
21
+
22
+ it 'somebody on call' do
23
+ expect_any_instance_of(Pagerduty).to receive(:get_schedules).and_return([{ id: 'abc123', name: 'abc' }])
24
+ expect_any_instance_of(Pagerduty).to receive(:get_oncall_user).and_return({summary: 'foo', email: 'foo@pagerduty.com'})
25
+ send_command('pager oncall abc')
26
+ expect(replies.last).to eq('foo (foo@pagerduty.com) is currently on call for abc')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::Pagerduty, lita_handler: true do
4
+ context 'pager me abc 1m' do
5
+ it do
6
+ is_expected.to route_command('pager me abc 1m').to(:pager_me)
7
+ end
8
+
9
+ it 'unknown user' do
10
+ expect_any_instance_of(Pagerduty).to receive(:get_schedules).and_return([{ id: 'bcd123'}])
11
+ user = Lita::User.create(123, name: 'foo')
12
+ send_command('pager me abc 1m', as: user)
13
+ expect(replies.last).to eq('You have not identified yourself (use the help command for more info)')
14
+ end
15
+
16
+ it 'unrecognised user' do
17
+ user = Lita::User.create(123, name: 'foo')
18
+ send_command('pager identify foo@pagerduty.com', as: user)
19
+ expect_any_instance_of(Pagerduty).to receive(:get_schedules).and_return([{ id: 'bcd123'}])
20
+ expect_any_instance_of(Pagerduty).to receive(:get_users).and_raise(Exceptions::UsersEmptyList)
21
+ send_command('pager me abc 1m', as: user)
22
+ expect(replies.last).to eq('You have identified yourself with an email address unknown to PagerDuty')
23
+ end
24
+
25
+ it 'unknown schedule' do
26
+ user = Lita::User.create(123, name: 'foo')
27
+ send_command('pager identify foo@pagerduty.com', as: user)
28
+ expect_any_instance_of(Pagerduty).to receive(:get_schedules).and_raise(Exceptions::SchedulesEmptyList)
29
+ send_command('pager me abc 1m', as: user)
30
+ expect(replies.last).to eq('No matching schedules found for \'abc\'')
31
+ end
32
+
33
+ it 'failure' do
34
+ user = Lita::User.create(123, name: 'foo')
35
+ send_command('pager identify foo@pagerduty.com', as: user)
36
+ expect_any_instance_of(Pagerduty).to receive(:get_schedules).and_return([{ id: 'abc123' }])
37
+ expect_any_instance_of(Pagerduty).to receive(:get_users).and_return([{id: 'abc123'}])
38
+ expect_any_instance_of(Pagerduty).to receive(:override).and_raise(Exceptions::OverrideUnsuccess)
39
+ send_command('pager me abc 1m', as: user)
40
+ expect(replies.last).to eq('failed to take the pager')
41
+ end
42
+
43
+ it 'success' do
44
+ user = Lita::User.create(123, name: 'foo')
45
+ send_command('pager identify foo@pagerduty.com', as: user)
46
+ expect_any_instance_of(Pagerduty).to receive(:get_schedules).and_return([{ id: 'abc123' }])
47
+ expect_any_instance_of(Pagerduty).to receive(:get_users).and_return([{id: 'abc123', email: 'foo@pagerduty.com'}])
48
+ expect_any_instance_of(Pagerduty).to receive(:override).and_return({
49
+ user: { summary: 'foo' },
50
+ end: 12345
51
+ })
52
+ send_command('pager me abc 1m', as: user)
53
+ expect(replies.last).to eq('foo (foo@pagerduty.com) is now on call until 12345')
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::Pagerduty, lita_handler: true do
4
+ context 'resolve all' do
5
+ it do
6
+ is_expected.to route_command('pager resolve all').to(:resolve_all)
7
+ end
8
+
9
+ it 'empty list' do
10
+ expect_any_instance_of(Pagerduty).to receive(:get_incidents).and_raise(Exceptions::IncidentsEmptyList)
11
+ send_command('pager resolve all')
12
+ expect(replies.last).to eq('No triggered, open, or acknowledged incidents')
13
+ end
14
+
15
+ it 'list of incidents' do
16
+ expect_any_instance_of(Pagerduty).to receive(:get_incidents).and_return([
17
+ { id: 'ABC123' }, { id: 'ABC124' }
18
+ ])
19
+ expect_any_instance_of(Pagerduty).to receive(:manage_incidents).and_return(
20
+ OpenStruct.new(status: 200)
21
+ )
22
+ send_command('pager resolve all')
23
+ expect(replies.last).to eq('Resolved: ABC123, ABC124')
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::Pagerduty, lita_handler: true do
4
+ context 'resolve ABC123' do
5
+ it do
6
+ is_expected.to route_command('pager resolve ABC123').to(:resolve)
7
+ end
8
+
9
+ it 'not found' do
10
+ expect_any_instance_of(Pagerduty).to receive(:manage_incidents).and_raise(Exceptions::IncidentManageUnsuccess)
11
+ send_command('pager resolve ABC123')
12
+ expect(replies.last).to be_nil
13
+ end
14
+
15
+ it 'found' do
16
+ expect_any_instance_of(Pagerduty).to receive(:manage_incidents)
17
+ send_command('pager resolve ABC123')
18
+ expect(replies.last).to eq 'Resolved: ABC123'
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::Pagerduty, lita_handler: true do
4
+ context 'resolve mine' do
5
+ it do
6
+ is_expected.to route_command('pager resolve mine').to(:resolve_mine)
7
+ end
8
+
9
+ it 'unknown user' do
10
+ user = Lita::User.create(123, name: 'foo')
11
+ send_command('pager resolve mine', as: user)
12
+ expect(replies.last).to eq('You have no triggered, open, or acknowledged incidents')
13
+ end
14
+
15
+ it 'empty list' do
16
+ user = Lita::User.create(123, name: 'foo')
17
+ send_command('pager identify foo@pagerduty.com', as: user)
18
+ expect_any_instance_of(Pagerduty).to receive(:get_users).and_return([{ id: 'abc123' }])
19
+ expect_any_instance_of(Pagerduty).to receive(:get_incidents).and_raise(Exceptions::IncidentsEmptyList)
20
+ send_command('pager resolve mine', as: user)
21
+ expect(replies.last).to eq('You have no triggered, open, or acknowledged incidents')
22
+ end
23
+
24
+ it 'list of incidents' do
25
+ user = Lita::User.create(123, name: 'foo')
26
+ send_command('pager identify foo@pagerduty.com', as: user)
27
+ expect_any_instance_of(Pagerduty).to receive(:get_users).and_return([{ id: 'abc123' }])
28
+ expect_any_instance_of(Pagerduty).to receive(:get_incidents).and_return([
29
+ { id: 'ABC123' }, { id: 'ABC124' }
30
+ ])
31
+ expect_any_instance_of(Pagerduty).to receive(:manage_incidents).and_return(
32
+ OpenStruct.new(status: 200)
33
+ )
34
+ send_command('pager resolve mine', as: user)
35
+ expect(replies.last).to eq('Resolved: ABC123, ABC124')
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pagerduty do
4
+ let(:http) { double }
5
+ let(:pagerduty) { Pagerduty.new(http, 'token', 'email') }
6
+
7
+ before :each do
8
+ expect(http).to receive(:url_prefix=).with('https://api.pagerduty.com/')
9
+ expect(http).to receive(:headers=).with({
10
+ 'Accept' => 'application/vnd.pagerduty+json;version=2',
11
+ 'Authorization' => 'Token token=token',
12
+ 'From' => 'email'
13
+ })
14
+ end
15
+
16
+ it 'get_incidents' do
17
+ expect(http).to receive(:get).with('/incidents', {}).and_return(
18
+ OpenStruct.new(body: { incidents: [{id: 1}]}.to_json)
19
+ )
20
+ expect(pagerduty.get_incidents).to eq([{ id: 1 }])
21
+
22
+ expect(http).to receive(:get).with('/incidents', {}).and_return(
23
+ OpenStruct.new(body: { incidents: []}.to_json)
24
+ )
25
+ expect{ pagerduty.get_incidents }.to raise_exception Exceptions::IncidentsEmptyList
26
+ end
27
+
28
+ it 'get_incident' do
29
+ expect(http).to receive(:get).with('/incidents/ABC123').and_return(
30
+ OpenStruct.new(body: { incident: {}}.to_json)
31
+ )
32
+ pagerduty.get_incident('ABC123')
33
+ end
34
+
35
+ it 'get_users' do
36
+ expect(http).to receive(:get).with('/users', {}).and_return(
37
+ OpenStruct.new(body: { users: [{ id: 1 }]}.to_json)
38
+ )
39
+ expect(pagerduty.get_users).to eq [{ id: 1 }]
40
+
41
+ expect(http).to receive(:get).with('/users', {}).and_return(
42
+ OpenStruct.new(body: { users: []}.to_json)
43
+ )
44
+ expect{ pagerduty.get_users }.to raise_exception Exceptions::UsersEmptyList
45
+ end
46
+
47
+ it 'get_notes_by_incident_id' do
48
+ expect(http).to receive(:get).with('/incidents/ABC123/notes').and_return(
49
+ OpenStruct.new(body: { notes: [{ id: 1 }]}.to_json)
50
+ )
51
+ expect(pagerduty.get_notes_by_incident_id('ABC123')).to eq [{ id: 1 }]
52
+
53
+ expect(http).to receive(:get).with('/incidents/ABC123/notes').and_return(
54
+ OpenStruct.new(body: { notes: []}.to_json)
55
+ )
56
+ expect{ pagerduty.get_notes_by_incident_id('ABC123') }.to raise_exception Exceptions::NotesEmptyList
57
+ end
58
+
59
+ it 'manage_incidents' do
60
+ params = { incidents: [
61
+ { id: 'a', status: 'acknowledged', type: 'incident_reference' },
62
+ { id: 'b', status: 'acknowledged', type: 'incident_reference' }
63
+ ]}
64
+ expect(http).to receive(:put).with('/incidents', params).and_return(
65
+ OpenStruct.new(body: { users: [] }.to_json, status: 200)
66
+ )
67
+ pagerduty.manage_incidents(:acknowledge, ['a', 'b'])
68
+ end
69
+
70
+ it 'get_schedules' do
71
+ expect(http).to receive(:get).with('/schedules', {}).and_return(
72
+ OpenStruct.new(body: { schedules: [{ id: 1 }]}.to_json)
73
+ )
74
+ expect(pagerduty.get_schedules).to eq [{ id: 1 }]
75
+
76
+ expect(http).to receive(:get).with('/schedules', {}).and_return(
77
+ OpenStruct.new(body: { incidents: []}.to_json)
78
+ )
79
+ expect{ pagerduty.get_schedules }.to raise_exception Exceptions::SchedulesEmptyList
80
+ end
81
+
82
+ it 'get_oncall_user' do
83
+ expect(http).to receive(:get).with('/oncalls', {}).and_return(
84
+ OpenStruct.new(body: { oncalls: [{ id: 1, user: 'abc' }]}.to_json)
85
+ )
86
+ expect(pagerduty.get_oncall_user).to eq('abc')
87
+
88
+ expect(http).to receive(:get).with('/oncalls', {}).and_return(
89
+ OpenStruct.new(body: { incidents: []}.to_json)
90
+ )
91
+ expect{ pagerduty.get_oncall_user }.to raise_exception Exceptions::NoOncallUser
92
+ end
93
+
94
+ it 'override' do
95
+ expect(Time).to receive(:now).and_return(Time.new(2000))
96
+ params = { override: {
97
+ end: '2000-01-01T00:01:10Z',
98
+ start: '2000-01-01T00:00:10Z',
99
+ user: { id: 'b', type: 'user_reference' }
100
+ } }
101
+ expect(http).to receive(:post).with('/schedules/a/overrides', params).and_return(
102
+ OpenStruct.new(body: { override: []}.to_json, status: 201)
103
+ )
104
+ pagerduty.override('a', 'b', 1)
105
+ end
106
+ end