spec/lib/flapjack/data/contact_spec.rb in flapjack-0.7.28 vs spec/lib/flapjack/data/contact_spec.rb in flapjack-0.7.29
- old
+ new
@@ -35,11 +35,11 @@
:critical_blackhole => false}
}
before(:each) do
Flapjack::Data::Contact.add( {
- 'id' => '362',
+ 'id' => 'c362',
'first_name' => 'John',
'last_name' => 'Johnson',
'email' => 'johnj@example.com',
'media' => {
'pagerduty' => {
@@ -51,11 +51,11 @@
},
},
:redis => @redis)
Flapjack::Data::Contact.add( {
- 'id' => '363',
+ 'id' => 'c363_a-f@42%*',
'first_name' => 'Jane',
'last_name' => 'Janeley',
'email' => 'janej@example.com',
'media' => {
'email' => {
@@ -76,48 +76,48 @@
contacts[0].name.should == 'Jane Janeley'
contacts[1].name.should == 'John Johnson'
end
it "finds a contact by id" do
- contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
+ contact = Flapjack::Data::Contact.find_by_id('c362', :redis => @redis)
contact.should_not be_nil
contact.name.should == "John Johnson"
end
it "adds a contact with the same id as an existing one, clears notification rules" do
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
contact.should_not be_nil
contact.add_notification_rule(notification_rule_data)
nr = contact.notification_rules
nr.should_not be_nil
nr.should have(2).notification_rules
- Flapjack::Data::Contact.add({'id' => '363',
+ Flapjack::Data::Contact.add({'id' => 'c363_a-f@42%*',
'first_name' => 'Smithy',
'last_name' => 'Smith',
'email' => 'smithys@example.com'},
:redis => @redis)
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
contact.should_not be_nil
contact.name.should == 'Smithy Smith'
rules = contact.notification_rules
rules.should have(1).notification_rule
nr.map(&:id).should_not include(rules.first.id)
end
it "updates a contact and clears their media settings" do
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
contact.update('media' => {})
contact.media.should be_empty
end
it "updates a contact, does not clear notification rules" do
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
contact.should_not be_nil
contact.add_notification_rule(notification_rule_data)
nr1 = contact.notification_rules
@@ -134,36 +134,36 @@
nr2.should have(2).notification_rules
nr1.map(&:id).should == nr2.map(&:id)
end
it "adds a notification rule for a contact" do
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
contact.should_not be_nil
expect {
contact.add_notification_rule(notification_rule_data)
}.to change { contact.notification_rules.size }.from(1).to(2)
end
it "removes a notification rule from a contact" do
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
contact.should_not be_nil
rule = contact.add_notification_rule(notification_rule_data)
expect {
contact.delete_notification_rule(rule)
}.to change { contact.notification_rules.size }.from(2).to(1)
end
it "creates a general notification rule for a pre-existing contact if none exists" do
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
- @redis.smembers("contact_notification_rules:363").each do |rule_id|
- @redis.srem("contact_notification_rules:363", rule_id)
+ @redis.smembers("contact_notification_rules:c363_a-f@42%*").each do |rule_id|
+ @redis.srem("contact_notification_rules:c363_a-f@42%*", rule_id)
end
- @redis.smembers("contact_notification_rules:363").should be_empty
+ @redis.smembers("contact_notification_rules:c363_a-f@42%*").should be_empty
rules = contact.notification_rules
rules.should have(1).rule
rule = rules.first
[:entities, :tags, :time_restrictions,
@@ -172,11 +172,11 @@
rule.send(k).should == general_notification_rule_data[k]
end
end
it "creates a general notification rule for a pre-existing contact if the existing general one was changed" do
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
rules = contact.notification_rules
rules.should have(1).notification_rule
rule = rules.first
rule.update(notification_rule_data)
@@ -185,18 +185,18 @@
rules.should have(2).notification_rules
rules.select {|r| r.is_specific? }.should have(1).rule
end
it "deletes a contact by id, including linked entities, checks, tags and notification rules" do
- contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
+ contact = Flapjack::Data::Contact.find_by_id('c362', :redis => @redis)
contact.add_tags('admin')
entity_name = 'abc-123'
entity = Flapjack::Data::Entity.add({'id' => '5000',
'name' => entity_name,
- 'contacts' => ['362']},
+ 'contacts' => ['c362']},
:redis => @redis)
expect {
expect {
expect {
@@ -211,19 +211,19 @@
it "returns a list of entities and their checks for a contact" do
entity_name = 'abc-123'
Flapjack::Data::Entity.add({'id' => '5000',
'name' => entity_name,
- 'contacts' => ['362']},
+ 'contacts' => ['c362']},
:redis => @redis)
ec = Flapjack::Data::EntityCheck.for_entity_name(entity_name, 'PING', :redis => @redis)
t = Time.now.to_i
ec.update_state('ok', :timestamp => t, :summary => 'a')
ec.last_update = t
- contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
+ contact = Flapjack::Data::Contact.find_by_id('c362', :redis => @redis)
eandcs = contact.entities(:checks => true)
eandcs.should_not be_nil
eandcs.should be_an(Array)
eandcs.should have(1).entity_and_checks
@@ -237,76 +237,91 @@
checks.should have(1).check
checks.should include('PING')
end
it "returns pagerduty credentials for a contact" do
- contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
+ contact = Flapjack::Data::Contact.find_by_id('c362', :redis => @redis)
credentials = contact.pagerduty_credentials
credentials.should_not be_nil
credentials.should be_a(Hash)
credentials.should == {'service_key' => '123456789012345678901234',
'subdomain' => 'flpjck',
'username' => 'flapjack',
'password' => 'very_secure'}
end
+ it "sets pagerduty credentials for a contact" do
+ contact = Flapjack::Data::Contact.find_by_id('c362', :redis => @redis)
+ contact.set_pagerduty_credentials('service_key' => '567890123456789012345678',
+ 'subdomain' => 'eggs',
+ 'username' => 'flapjack',
+ 'password' => 'tomato')
+
+ @redis.hget('contact_media:c362', 'pagerduty').should == '567890123456789012345678'
+ @redis.hgetall('contact_pagerduty:c362').should == {
+ 'subdomain' => 'eggs',
+ 'username' => 'flapjack',
+ 'password' => 'tomato'
+ }
+ end
+
it "sets the interval for a contact's media" do
- contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
+ contact = Flapjack::Data::Contact.find_by_id('c362', :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)
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :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)
+ contact = Flapjack::Data::Contact.find_by_id('c362', :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 = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :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)
+ contact = Flapjack::Data::Contact.find_by_id('c362', :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)
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :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)
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :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 = Flapjack::Data::Contact.find_by_id('c362', :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 = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :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