Skip to content
Snippets Groups Projects
Commit 76c81868 authored by Ryan Senior's avatar Ryan Senior
Browse files

Fix bug causing test email pulses to fail

When test pulses are sent out their channel_types are strings not
keywords which caused the multimethod lookup in the pulse code to
fail. This commit adds a unit test that covers our pulse test
capability and ensures channel_type fields are keywords before
invoking the multimethod.

Fixes #6465
parent 4b2bd4a2
No related branches found
No related tags found
No related merge requests found
......@@ -143,7 +143,7 @@
"Polymorphoic function for creating notifications. This logic is different for pulse type (i.e. alert vs. pulse) and
channel_type (i.e. email vs. slack)"
(fn [pulse _ {:keys [channel_type] :as channel}]
[(alert-or-pulse pulse) channel_type]))
[(alert-or-pulse pulse) (keyword channel_type)]))
(defmethod create-notification [:pulse :email]
[{:keys [id name] :as pulse} results {:keys [recipients] :as channel}]
......@@ -185,6 +185,11 @@
:message (str "Alert: " (first-question-name pulse))
:attachments (create-slack-attachment-data results)})
(defmethod create-notification :default
[_ _ {:keys [channel_type] :as channel}]
(let [^String ex-msg (tru "Unrecognized channel type {0}" (pr-str channel_type))]
(throw (UnsupportedOperationException. ex-msg))))
(defmulti ^:private send-notification!
"Invokes the side-affecty function for sending emails/slacks depending on the notification type"
(fn [{:keys [channel-id] :as notification}]
......
......@@ -2,6 +2,7 @@
"Tests for /api/pulse endpoints."
(:require [expectations :refer :all]
[metabase
[email-test :as et]
[http-client :as http]
[middleware :as middleware]
[util :as u]]
......@@ -13,9 +14,13 @@
[pulse :as pulse :refer [Pulse]]
[pulse-card :refer [PulseCard]]
[table :refer [Table]]]
[metabase.test.data.users :refer :all]
[metabase.test
[data :as data]
[util :as tu]]
[metabase.test.data
[dataset-definitions :as defs]
[users :refer :all]]
[metabase.test.mock.util :refer [pulse-channel-defaults]]
[metabase.test.util :as tu]
[toucan.db :as db]
[toucan.util.test :as tt]))
......@@ -232,3 +237,28 @@
(tt/expect-with-temp [Pulse [{pulse-id :id} {:alert_condition "rows"}]]
"Not found."
((user->client :rasta) :get 404 (str "pulse/" pulse-id)))
;; ## POST /api/pulse/test
(expect
[{:ok true}
(et/email-to :rasta {:subject "Pulse: Daily Sad Toucans"
:body {"Daily Sad Toucans" true}})]
(tu/with-model-cleanup [Pulse]
(et/with-fake-inbox
(data/with-db (data/get-or-create-database! defs/sad-toucan-incidents)
(tt/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Card [{card-id :id} {:dataset_query {:database database-id
:type "query"
:query {:source-table table-id,
:aggregation {:aggregation-type "count"}}}}]]
[((user->client :rasta) :post 200 "pulse/test" {:name "Daily Sad Toucans"
:cards [{:id card-id}]
:channels [{:enabled true
:channel_type "email"
:schedule_type "daily"
:schedule_hour 12
:schedule_day nil
:recipients [(fetch-user :rasta)]}]
:skip_if_empty false})
(et/regex-email-bodies #"Daily Sad Toucans")])))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment