<commit_before>require 'spec_helper'

describe LifecycleTriggeredSms do
  describe "limit" do
    def generate_phone_numbers(max)
      @account = Factory.create(:account)
      r = Random.new
      random_number = r.rand(5..max)
      phone_numbers = []
      (1..random_number).each do |n|
        p = double(String)
        p.stub(:strip).and_return("1234")
        phone_numbers << p
      end
      
      phone_numbers
    end
    
    it "should limit the amount of outgoing texts to the value of MAX_OUTGOING_SMS_PER_LC_EVENT" do
      phone_numbers = generate_phone_numbers(ENV['MAX_OUTGOING_SMS_PER_LC_EVENT'].to_i)
      Account.any_instance.stub(:object_instances).and_return(phone_numbers)
      ConsumeSms::Consumer.stub(:send_sms)
      ConsumeSms::Consumer.should_receive(:send_sms).at_most(ENV['MAX_OUTGOING_SMS_PER_LC_EVENT'].to_i).times
      LifecycleTriggeredSms::perform({'from' => 'some_number', 'body' => 'hello world'}, @account.id, 'customer', '{{customer.phone_number}}')
    end
    
    it "should only send texts to the list of phone numbers found" do<commit_msg>Tweak spec test<commit_after>require 'spec_helper'

describe LifecycleTriggeredSms do
  describe "limit" do
    def generate_phone_numbers(max)
      @account = Factory.create(:account)
      r = Random.new
      max = 5 if max < 5
      random_number = r.rand(5..max)
      phone_numbers = []
      (1..random_number).each do |n|
        p = double(String)
        p.stub(:strip).and_return("1234")
        phone_numbers << p
      end
      
      phone_numbers
    end
    
    it "should limit the amount of outgoing texts to the value of MAX_OUTGOING_SMS_PER_LC_EVENT" do
      phone_numbers = generate_phone_numbers(ENV['MAX_OUTGOING_SMS_PER_LC_EVENT'].to_i)
      Account.any_instance.stub(:object_instances).and_return(phone_numbers)
      ConsumeSms::Consumer.stub(:send_sms)
      ConsumeSms::Consumer.should_receive(:send_sms).at_most(ENV['MAX_OUTGOING_SMS_PER_LC_EVENT'].to_i).times
      LifecycleTriggeredSms::perform({'from' => 'some_number', 'body' => 'hello world'}, @account.id, 'customer', '{{customer.phone_number}}')
    end
    
    it "should only send texts to the list of phone numbers found" do
{'fraction_non_alphanumeric': 0.11025756891098057, 'fraction_numerical': 0.0063262539539087215, 'mean_word_length': 3.5555555555555554, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2484464', 'n_tokens_mistral': 751, 'n_tokens_neox': 728, 'n_words': 144}