Skip to content

Business intelligence made simple

Improved check tests

Andrew Kane2eac0116431f
diff --git a/Rakefile b/Rakefile
index 21f1938e..07b8e8eb 100644
--- a/Rakefile
+++ b/Rakefile
@@ -5,4 +5,5 @@ task default: :test
Rake::TestTask.new do |t|
t.libs << "test"
t.pattern = "test/*_test.rb"
+ t.warning = false # mail gem
end
diff --git a/test/archive_test.rb b/test/archive_test.rb
index fc541ef8..29197533 100644
--- a/test/archive_test.rb
+++ b/test/archive_test.rb
@@ -18,8 +18,4 @@ class ArchiveTest < ActionDispatch::IntegrationTest
query2.reload
assert_equal "active", query2.status
end
-
- def create_query
- Blazer::Query.create!(statement: "SELECT 1", data_source: "main", status: "active")
- end
end
diff --git a/test/checks_test.rb b/test/checks_test.rb
index 09d1f5f8..86c4917d 100644
--- a/test/checks_test.rb
+++ b/test/checks_test.rb
@@ -1,8 +1,30 @@
require_relative "test_helper"
class ChecksTest < ActionDispatch::IntegrationTest
+ def setup
+ Blazer::Check.delete_all
+ Blazer::Query.delete_all
+ end
+
def test_index
get blazer.checks_path
assert_response :success
end
+
+ def test_run
+ query = create_query
+ check = Blazer::Check.create!(query: query, schedule: "5 minutes", emails: "[email protected]")
+
+ assert_emails 0 do
+ Blazer.send_failing_checks
+ end
+
+ assert_emails 1 do
+ Blazer.run_checks(schedule: "5 minutes")
+ end
+
+ assert_emails 1 do
+ Blazer.send_failing_checks
+ end
+ end
end
diff --git a/test/internal/config/blazer.yml b/test/internal/config/blazer.yml
index d552dbc8..fae61aff 100644
--- a/test/internal/config/blazer.yml
+++ b/test/internal/config/blazer.yml
@@ -55,7 +55,7 @@ audit: true
# before_action_method: require_admin
# email to send checks from
-# from_email: [email protected]
+from_email: [email protected]
# webhook for Slack
# slack_webhook_url:
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 5a8fc8a8..a51885d0 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -7,7 +7,7 @@ require "minitest/pride"
logger = ActiveSupport::Logger.new(ENV["VERBOSE"] ? STDERR : nil)
Combustion.path = "test/internal"
-Combustion.initialize! :active_record, :action_controller, :sprockets do
+Combustion.initialize! :active_record, :action_controller, :action_mailer, :sprockets do
config.action_controller.logger = logger
config.active_record.logger = logger
end
@@ -21,4 +21,8 @@ class ActionDispatch::IntegrationTest
post blazer.run_queries_path, params: {statement: statement, data_source: "main"}.merge(params), xhr: true
assert_response :success
end
+
+ def create_query
+ Blazer::Query.create!(statement: "SELECT 1", data_source: "main", status: "active")
+ end
end