Module: BotHelpers::Tests

Defined in:
lib/mail_runner/bot_helpers/tests.rb

Overview

series of initial command validation tests on launch.

Class Method Summary collapse

Class Method Details

.all_args_included?(args) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
# 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) ⇒ Object



28
29
30
31
32
33
34
35
# 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) ⇒ Object



37
38
39
40
41
42
43
44
45
# 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) ⇒ Object



53
54
55
56
57
58
59
60
# 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) ⇒ Object



47
48
49
50
51
# 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) ⇒ Object



10
11
12
13
14
# 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) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# 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