spec/lib/flapjack/data/contact_spec.rb in flapjack-0.7.27 vs spec/lib/flapjack/data/contact_spec.rb in flapjack-0.7.28
- old
+ new
@@ -12,53 +12,62 @@
let(:notification_rule_data) {
{:tags => ["database","physical"],
:entities => ["foo-app-01.example.com"],
:time_restrictions => [],
+ :unknown_media => [],
:warning_media => ["email"],
:critical_media => ["sms", "email"],
+ :unknown_blackhole => false,
:warning_blackhole => false,
:critical_blackhole => false
}
}
let(:general_notification_rule_data) {
{:entities => [],
:tags => Flapjack::Data::TagSet.new([]),
:time_restrictions => [],
+ :unknown_media => [],
:warning_media => ['email', 'sms', 'jabber', 'pagerduty'],
:critical_media => ['email', 'sms', 'jabber', 'pagerduty'],
+ :unknown_blackhole => false,
:warning_blackhole => false,
:critical_blackhole => false}
}
before(:each) do
- Flapjack::Data::Contact.add({'id' => '362',
- 'first_name' => 'John',
- 'last_name' => 'Johnson',
- 'email' => 'johnj@example.com',
- 'media' => {
- 'pagerduty' => {
- 'service_key' => '123456789012345678901234',
- 'subdomain' => 'flpjck',
- 'username' => 'flapjack',
- 'password' => 'very_secure'
- }
- }},
- :redis => @redis)
+ Flapjack::Data::Contact.add( {
+ 'id' => '362',
+ 'first_name' => 'John',
+ 'last_name' => 'Johnson',
+ 'email' => 'johnj@example.com',
+ 'media' => {
+ 'pagerduty' => {
+ 'service_key' => '123456789012345678901234',
+ 'subdomain' => 'flpjck',
+ 'username' => 'flapjack',
+ 'password' => 'very_secure'
+ },
+ },
+ },
+ :redis => @redis)
- Flapjack::Data::Contact.add({'id' => '363',
- 'first_name' => 'Jane',
- 'last_name' => 'Janeley',
- 'email' => 'janej@example.com',
- 'media' => {
- 'email' => {
- 'address' => 'janej@example.com',
- 'interval' => 60
- }
- }},
- :redis => @redis)
+ Flapjack::Data::Contact.add( {
+ 'id' => '363',
+ 'first_name' => 'Jane',
+ 'last_name' => 'Janeley',
+ 'email' => 'janej@example.com',
+ 'media' => {
+ 'email' => {
+ 'address' => 'janej@example.com',
+ 'interval' => 60,
+ 'rollup_threshold' => 5,
+ },
+ },
+ },
+ :redis => @redis)
end
it "returns a list of all contacts" do
contacts = Flapjack::Data::Contact.all(:redis => @redis)
contacts.should_not be_nil
@@ -236,8 +245,74 @@
credentials.should be_a(Hash)
credentials.should == {'service_key' => '123456789012345678901234',
'subdomain' => 'flpjck',
'username' => 'flapjack',
'password' => 'very_secure'}
+ end
+
+ it "sets the interval for a contact's media" do
+ contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
+ contact.set_interval_for_media('email', 42)
+ email_interval_raw = @redis.hget("contact_media_intervals:#{contact.id}", 'email')
+ email_interval_raw.should == '42'
+ end
+
+ it "returns the interval for a contact's media" do
+ contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
+ email_interval = contact.interval_for_media('email')
+ email_interval.should == 60
+ end
+
+ it "returns default 15 mins for interval for a contact's media that has no set interval" do
+ contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
+ email_interval = contact.interval_for_media('email')
+ email_interval.should == 900
+ end
+
+ it "removes the interval for a contact's media" do
+ contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
+ contact.set_interval_for_media('email', nil)
+ email_interval_raw = @redis.hget("contact_media_intervals:#{contact.id}", 'email')
+ email_interval_raw.should be_nil
+ end
+
+ it "sets the rollup threshold for a contact's media" do
+ contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
+ email_rollup_threshold = contact.set_rollup_threshold_for_media('email', 3)
+ email_rollup_threshold_raw = @redis.hget("contact_media_rollup_thresholds:#{contact.id}", 'email')
+ email_rollup_threshold_raw.should == '3'
+ end
+
+ it "returns the rollup threshold for a contact's media" do
+ contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
+ email_rollup_threshold = contact.rollup_threshold_for_media('email')
+ email_rollup_threshold.should_not be_nil
+ email_rollup_threshold.should be_a(Integer)
+ email_rollup_threshold.should == 5
+ end
+
+ it "removes the rollup threshold for a contact's media" do
+ contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
+ email_rollup_threshold = contact.set_rollup_threshold_for_media('email', nil)
+ email_rollup_threshold_raw = @redis.hget("contact_media_rollup_thresholds:#{contact.id}", 'email')
+ email_rollup_threshold_raw.should be_nil
+ end
+
+ it "sets the address for a contact's media" do
+ contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
+ contact.set_address_for_media('email', 'spongebob@example.com')
+ email_address_raw = @redis.hget("contact_media:#{contact.id}", 'email')
+ email_address_raw.should == 'spongebob@example.com'
+ end
+
+ it "removes a contact's media" do
+ contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
+ contact.remove_media('email')
+ email_address_raw = @redis.hget("contac_media:#{contact.id}", 'email')
+ email_address_raw.should be_nil
+ email_rollup_threshold_raw = @redis.hget("contact_media_rollup_thresholds:#{contact.id}", 'email')
+ email_rollup_threshold_raw.should be_nil
+ email_interval_raw = @redis.hget("contact_media_intervals:#{contact.id}", 'email')
+ email_interval_raw.should be_nil
end
end