features/steps/notifications_steps.rb in flapjack-1.2.2 vs features/steps/notifications_steps.rb in flapjack-1.3.0rc1

- old
+ new

@@ -24,10 +24,22 @@ 'name' => entity, 'contacts' => ["0999"]}, :redis => @notifier_redis ) end +Given /^the user wants to receive Nexmo SMS notifications for entity '([\w\.\-]+)'$/ do |entity| + add_contact( 'id' => '0999', + 'first_name' => 'John', + 'last_name' => 'Smith', + 'email' => 'johns@example.dom', + 'media' => {'sms_nexmo' => '+61888888888'} ) + Flapjack::Data::Entity.add({'id' => '5000', + 'name' => entity, + 'contacts' => ["0999"]}, + :redis => @notifier_redis ) +end + Given /^the user wants to receive SNS notifications for entity '([\w\.\-]+)'$/ do |entity| add_contact( 'id' => '0999', 'first_name' => 'John', 'last_name' => 'Smith', 'email' => 'johns@example.dom', @@ -97,10 +109,15 @@ Then /^an SMS notification for entity '([\w\.\-]+)' should be queued for the user$/ do |entity| queue = redis_peek('sms_notifications') expect(queue.select {|n| n['event_id'] =~ /#{entity}:ping/ }).not_to be_empty end +Then /^a Nexmo SMS notification for entity '([\w\.\-]+)' should be queued for the user$/ do |entity| + queue = redis_peek('sms_nexmo_notifications') + expect(queue.select {|n| n['event_id'] =~ /#{entity}:ping/ }).not_to be_empty +end + Then /^an SNS notification for entity '([\w\.\-]+)' should be queued for the user$/ do |entity| queue = redis_peek('sns_notifications') expect(queue.select {|n| n['event_id'] =~ /#{entity}:ping/ }).not_to be_empty end @@ -112,10 +129,15 @@ Then /^an SMS notification for entity '([\w\.\-]+)' should not be queued for the user$/ do |entity| queue = redis_peek('sms_notifications') expect(queue.select {|n| n['event_id'] =~ /#{entity}:ping/ }).to be_empty end +Then /^an Nexmo SMS notification for entity '([\w\.\-]+)' should not be queued for the user$/ do |entity| + queue = redis_peek('sms_nexmo_notifications') + expect(queue.select {|n| n['event_id'] =~ /#{entity}:ping/ }).to be_empty +end + Then /^an email notification for entity '([\w\.\-]+)' should not be queued for the user$/ do |entity| queue = redis_peek('email_notifications') expect(queue.select {|n| n['event_id'] =~ /#{entity}:ping/ }).to be_empty end @@ -137,10 +159,30 @@ Flapjack::Data::Alert.add('sms_notifications', @sms_notification, :redis => @notifier_redis) end +Given /^a user Nexmo SMS notification has been queued for entity '([\w\.\-]+)'$/ do |entity| + Flapjack::Data::Entity.add({'id' => '5000', + 'name' => entity}, + :redis => @redis ) + @sms_nexmo_notification = {'notification_type' => 'problem', + 'contact_first_name' => 'John', + 'contact_last_name' => 'Smith', + 'state' => 'critical', + 'summary' => 'Socket timeout after 10 seconds', + 'time' => Time.now.to_i, + 'event_id' => "#{entity}:ping", + 'address' => '+61412345678', + 'id' => 1, + 'state_duration' => 30, + 'duration' => 45} + + Flapjack::Data::Alert.add('sms_nexmo_notifications', @sms_nexmo_notification, + :redis => @notifier_redis) +end + Given /^a user SNS notification has been queued for entity '([\w\.\-]+)'$/ do |entity| Flapjack::Data::Entity.add({'id' => '5000', 'name' => entity}, :redis => @redis ) @sns_notification = {'notification_type' => 'problem', @@ -187,10 +229,23 @@ }, :redis_config => @redis_opts, :logger => @logger) drain_alerts('sms_notifications', @sms_messagenet) end +When /^the Nexmo SMS notification handler runs successfully$/ do + # poor man's stubbing + Nexmo::Client.class_eval { + def send_message(args = {}) + end + } + @sms_nexmo = Flapjack::Gateways::SmsNexmo.new(:config => { + 'api_key' => 'THEAPIKEY', 'secret' => 'secret', 'from' => 'someone', + }, :redis_config => @redis_opts, :logger => @logger) + + drain_alerts('sms_nexmo_notifications', @sms_nexmo) +end + When /^the SNS notification handler runs successfully$/ do @request = stub_request(:post, /amazonaws\.com/) @aws_sns = Flapjack::Gateways::AwsSns.new(:config => { 'access_key' => "AKIAIOSFODNN7EXAMPLE", @@ -260,9 +315,13 @@ end Then /^the user should( not)? receive an SMS notification$/ do |negativity| expect(@request).to have_been_requested expect(@sms_messagenet.instance_variable_get('@sent')).to eq(negativity.nil? ? 1 : 0) +end + +Then /^the user should( not)? receive an Nexmo SMS notification$/ do |negativity| + expect(@sms_nexmo.instance_variable_get('@sent')).to eq(negativity.nil? ? 1 : 0) end Then /^the user should( not)? receive an SNS notification$/ do |negativity| expect(@request).to have_been_requested expect(@aws_sns.instance_variable_get('@sent')).to eq(negativity.nil? ? 1 : 0)