module BotHelpers::Tests

Public Class Methods

all_args_included?(args) click to toggle source
# File lib/mail_runner/bot_helpers/tests.rb, line 4
def self.all_args_included?(args)
    if args[:mailbox].nil? or args[:webhook].nil?
            raise ArgumentError, 'You must include mailbox & webhook minimum. Archive argument is optional. Add -h to see help.' 
            end
    end
soft_test_webhook(url) click to toggle source
# File lib/mail_runner/bot_helpers/tests.rb, line 28
def self.soft_test_webhook(url) 
  begin
    response = RestClient.head url
    MailRunner.manager_bot.update_webhook_status("live")
    $logger.info("ManagerBot") {"webhook status: live"}
  rescue 
  end
end
test_archive(a_set) click to toggle source
# File lib/mail_runner/bot_helpers/tests.rb, line 37
def self.test_archive(a_set)
  if a_set[:destination] == 'local'
    test_local_archive(a_set)
  elsif a_set[:destination] == 'cloud'
    test_cloud_archive_connection(a_set)
  else
    raise ArgumentError, "ERROR: Archive destination setting invalid."
  end
end
test_cloud_archive_connection(a_set) click to toggle source
# File lib/mail_runner/bot_helpers/tests.rb, line 53
def self.test_cloud_archive_connection(a_set)
  a_set = JSON.parse(a_set.to_json) #Must parse as json, similar to redis queues. Stringifies symbol keys.
  begin
    response = MailRunner::ArchivistBot.establish_archive_link(a_set)
  rescue => e
   raise ArgumentError, "ERROR: Archive connection failed. Check your archive config options or disable."
  end
end
test_local_archive(a_set) click to toggle source
# File lib/mail_runner/bot_helpers/tests.rb, line 47
def self.test_local_archive(a_set)
  unless File.directory?(a_set[:local_archive])
    raise ArgumentError, "ERROR: Invalid local archive path."
  end
end
test_mailbox(path) click to toggle source
# File lib/mail_runner/bot_helpers/tests.rb, line 10
    def self.test_mailbox        (path)
    unless File.file?(path)
            raise ArgumentError, 'ERROR: Mailbox not valid' 
    end
end
test_webhook(url) click to toggle source
# File lib/mail_runner/bot_helpers/tests.rb, line 16
def self.test_webhook(url) 
    begin
            response = RestClient.head url
    MailRunner.manager_bot.update_webhook_status("live")
    rescue  
            raise ArgumentError, "ERROR: \nMake sure the server is running and the webhook exists.\nNOTE:  Server must respond to http HEAD method.\nSee README.md for proper setup.\n"
    end
    unless response.code == 200
            raise ArgumentError, "ERROR: Invalid Webhook. NOTE, Must respond to http HEAD method."
    end
end