Skip to content

Business intelligence made simple

Improved tests

Andrew Kaneee3618dcfc94
diff --git a/test/charts_test.rb b/test/charts_test.rb
new file mode 100644
index 00000000..8212fdd1
--- /dev/null
+++ b/test/charts_test.rb
@@ -0,0 +1,49 @@
+require_relative "test_helper"
+
+class ControllerTest < ActionDispatch::IntegrationTest
+ # TODO fix casting
+ def test_line_chart
+ run_query "SELECT date('now'), 1"
+ # assert_match "LineChart", response.body
+ end
+
+ def test_column_chart
+ run_query "SELECT 'Label', 1"
+ assert_match "ColumnChart", response.body
+ end
+
+ def test_scatter_chart
+ run_query "SELECT 1, 2"
+ assert_match "ScatterChart", response.body
+ end
+
+ def test_pie_chart
+ run_query "SELECT 'Label', 1 AS pie"
+ assert_match "PieChart", response.body
+ end
+
+ def test_map_latitude_longitude
+ run_query "SELECT 1.2 AS latitude, 3.4 AS longitude"
+ assert_match "map", response.body
+ end
+
+ def test_map_lat_lon
+ run_query "SELECT 1.2 AS lat, 3.4 AS lon"
+ assert_match "map", response.body
+ end
+
+ def test_map_lat_lng
+ run_query "SELECT 1.2 AS lat, 3.4 AS lng"
+ assert_match "map", response.body
+ end
+
+ # TODO update
+ def test_target
+ run_query "SELECT date('now'), 1, 2 AS target"
+ end
+
+ def run_query(statement)
+ post blazer.run_queries_path, params: {statement: statement, data_source: "main"}, xhr: true
+ assert_response :success
+ end
+end
diff --git a/test/controller_test.rb b/test/controller_test.rb
index 85c74530..04f4bd78 100644
--- a/test/controller_test.rb
+++ b/test/controller_test.rb
@@ -1,8 +1,35 @@
require_relative "test_helper"
class ControllerTest < ActionDispatch::IntegrationTest
+ def setup
+ Blazer::Audit.delete_all
+ Blazer::Query.delete_all
+ end
+
def test_index
get blazer.root_path
assert_response :success
end
+
+ def test_create_query
+ post blazer.queries_path, params: {query: {name: "Test", statement: "SELECT 1", data_source: "main"}}
+ assert_response :redirect
+
+ query = Blazer::Query.last
+ get blazer.query_path(query)
+ assert_response :success
+
+ post blazer.run_queries_path, params: {statement: query.statement, data_source: query.data_source, query_id: query.id}, xhr: true
+ assert_response :success
+ audit = Blazer::Audit.last
+ assert_equal query.id, audit.query_id
+ assert_equal query.statement, audit.statement
+ assert_equal query.data_source, audit.data_source
+ end
+
+ # TODO switch to postgres and check table names
+ def test_tables
+ get blazer.tables_queries_path(data_source: "main")
+ assert_response :success
+ end
end
diff --git a/test/internal/config/blazer.yml b/test/internal/config/blazer.yml
new file mode 100644
index 00000000..79706fb2
--- /dev/null
+++ b/test/internal/config/blazer.yml
@@ -0,0 +1,79 @@
+# see https://github.com/ankane/blazer for more info
+
+data_sources:
+ main:
+ url: "sqlite3::memory:"
+
+ # statement timeout, in seconds
+ # none by default
+ # timeout: 15
+
+ # caching settings
+ # can greatly improve speed
+ # off by default
+ # cache:
+ # mode: slow # or all
+ # expires_in: 60 # min
+ # slow_threshold: 15 # sec, only used in slow mode
+
+ # wrap queries in a transaction for safety
+ # not necessary if you use a read-only user
+ # true by default
+ # use_transaction: false
+
+ smart_variables:
+ # zone_id: "SELECT id, name FROM zones ORDER BY name ASC"
+ # period: ["day", "week", "month"]
+ # status: {0: "Active", 1: "Archived"}
+
+ linked_columns:
+ # user_id: "/admin/users/{value}"
+
+ smart_columns:
+ # user_id: "SELECT id, name FROM users WHERE id IN {value}"
+
+# create audits
+audit: true
+
+# change the time zone
+# time_zone: "Pacific Time (US & Canada)"
+
+# class name of the user model
+# user_class: User
+
+# method name for the current user
+# user_method: current_user
+
+# method name for the display name
+# user_name: name
+
+# custom before_action to use for auth
+# before_action_method: require_admin
+
+# email to send checks from
+# from_email: [email protected]
+
+# webhook for Slack
+# slack_webhook_url:
+
+check_schedules:
+ - "1 day"
+ - "1 hour"
+ - "5 minutes"
+
+# enable anomaly detection
+# note: with trend, time series are sent to https://trendapi.org
+# anomaly_checks: prophet / trend / r
+
+# enable forecasting
+# note: with trend, time series are sent to https://trendapi.org
+# forecasting: prophet / trend
+
+# enable map
+mapbox_access_token: token
+
+# enable uploads
+# uploads:
+# url:
+# schema: uploads
+# data_source: main