@@ -15,6 +15,7 @@ import {
1515 ObjectRemover ,
1616} from '../../../../../common/lib' ;
1717import { createEsDocuments } from './create_test_data' ;
18+ import { getAlertType } from '../../../../../../../plugins/triggers_actions_ui/public/application/components/builtin_alert_types/threshold/' ;
1819
1920const ALERT_TYPE_ID = '.index-threshold' ;
2021const ACTION_TYPE_ID = '.index' ;
@@ -26,6 +27,8 @@ const ALERT_INTERVALS_TO_WRITE = 5;
2627const ALERT_INTERVAL_SECONDS = 3 ;
2728const ALERT_INTERVAL_MILLIS = ALERT_INTERVAL_SECONDS * 1000 ;
2829
30+ const DefaultActionMessage = getAlertType ( ) . defaultActionMessage ;
31+
2932// eslint-disable-next-line import/no-default-export
3033export default function alertTests ( { getService } : FtrProviderContext ) {
3134 const supertest = getService ( 'supertest' ) ;
@@ -62,6 +65,10 @@ export default function alertTests({ getService }: FtrProviderContext) {
6265 await esTestIndexToolOutput . destroy ( ) ;
6366 } ) ;
6467
68+ it ( 'has a default action message' , ( ) => {
69+ expect ( DefaultActionMessage ) . to . be . ok ( ) ;
70+ } ) ;
71+
6572 // The tests below create two alerts, one that will fire, one that will
6673 // never fire; the tests ensure the ones that should fire, do fire, and
6774 // those that shouldn't fire, do not fire.
@@ -85,17 +92,16 @@ export default function alertTests({ getService }: FtrProviderContext) {
8592 const docs = await waitForDocs ( 2 ) ;
8693 for ( const doc of docs ) {
8794 const { group } = doc . _source ;
88- const { name, value , title, message } = doc . _source . params ;
95+ const { name, title, message } = doc . _source . params ;
8996
9097 expect ( name ) . to . be ( 'always fire' ) ;
9198 expect ( group ) . to . be ( 'all documents' ) ;
9299
93100 // we'll check title and message in this test, but not subsequent ones
94101 expect ( title ) . to . be ( 'alert always fire group all documents exceeded threshold' ) ;
95102
96- const expectedPrefix = `alert always fire group all documents value ${ value } exceeded threshold count > -1 over` ;
97- const messagePrefix = message . substr ( 0 , expectedPrefix . length ) ;
98- expect ( messagePrefix ) . to . be ( expectedPrefix ) ;
103+ const messagePattern = / a l e r t a l w a y s f i r e g r o u p a l l d o c u m e n t s v a l u e \d + e x c e e d e d t h r e s h o l d c o u n t & g t ; - 1 o v e r 1 5 s o n \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } : \d { 2 } : \d { 2 } .\d { 3 } Z / ;
104+ expect ( message ) . to . match ( messagePattern ) ;
99105 }
100106 } ) ;
101107
@@ -128,10 +134,13 @@ export default function alertTests({ getService }: FtrProviderContext) {
128134
129135 for ( const doc of docs ) {
130136 const { group } = doc . _source ;
131- const { name } = doc . _source . params ;
137+ const { name, message } = doc . _source . params ;
132138
133139 expect ( name ) . to . be ( 'always fire' ) ;
134140 if ( group === 'group-0' ) inGroup0 ++ ;
141+
142+ const messagePattern = / a l e r t a l w a y s f i r e g r o u p g r o u p - \d v a l u e \d + e x c e e d e d t h r e s h o l d c o u n t .+ o v e r 1 5 s o n \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } : \d { 2 } : \d { 2 } .\d { 3 } Z / ;
143+ expect ( message ) . to . match ( messagePattern ) ;
135144 }
136145
137146 // there should be 2 docs in group-0, rando split between others
@@ -163,9 +172,12 @@ export default function alertTests({ getService }: FtrProviderContext) {
163172
164173 const docs = await waitForDocs ( 2 ) ;
165174 for ( const doc of docs ) {
166- const { name } = doc . _source . params ;
175+ const { name, message } = doc . _source . params ;
167176
168177 expect ( name ) . to . be ( 'always fire' ) ;
178+
179+ const messagePattern = / a l e r t a l w a y s f i r e g r o u p a l l d o c u m e n t s v a l u e \d + e x c e e d e d t h r e s h o l d s u m \( t e s t e d V a l u e \) b e t w e e n 0 , 1 0 0 0 0 0 0 o v e r 1 5 s o n \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } : \d { 2 } : \d { 2 } .\d { 3 } Z / ;
180+ expect ( message ) . to . match ( messagePattern ) ;
169181 }
170182 } ) ;
171183
@@ -195,9 +207,12 @@ export default function alertTests({ getService }: FtrProviderContext) {
195207
196208 const docs = await waitForDocs ( 4 ) ;
197209 for ( const doc of docs ) {
198- const { name } = doc . _source . params ;
210+ const { name, message } = doc . _source . params ;
199211
200212 expect ( name ) . to . be ( 'always fire' ) ;
213+
214+ const messagePattern = / a l e r t a l w a y s f i r e g r o u p a l l d o c u m e n t s v a l u e .+ e x c e e d e d t h r e s h o l d a v g \( t e s t e d V a l u e \) .+ 0 o v e r 1 5 s o n \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } : \d { 2 } : \d { 2 } .\d { 3 } Z / ;
215+ expect ( message ) . to . match ( messagePattern ) ;
201216 }
202217 } ) ;
203218
@@ -232,10 +247,13 @@ export default function alertTests({ getService }: FtrProviderContext) {
232247
233248 for ( const doc of docs ) {
234249 const { group } = doc . _source ;
235- const { name } = doc . _source . params ;
250+ const { name, message } = doc . _source . params ;
236251
237252 expect ( name ) . to . be ( 'always fire' ) ;
238253 if ( group === 'group-2' ) inGroup2 ++ ;
254+
255+ const messagePattern = / a l e r t a l w a y s f i r e g r o u p g r o u p - . v a l u e \d + e x c e e d e d t h r e s h o l d m a x \( t e s t e d V a l u e \) .* 0 o v e r 1 5 s o n \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } : \d { 2 } : \d { 2 } .\d { 3 } Z / ;
256+ expect ( message ) . to . match ( messagePattern ) ;
239257 }
240258
241259 // there should be 2 docs in group-2, rando split between others
@@ -274,10 +292,13 @@ export default function alertTests({ getService }: FtrProviderContext) {
274292
275293 for ( const doc of docs ) {
276294 const { group } = doc . _source ;
277- const { name } = doc . _source . params ;
295+ const { name, message } = doc . _source . params ;
278296
279297 expect ( name ) . to . be ( 'always fire' ) ;
280298 if ( group === 'group-0' ) inGroup0 ++ ;
299+
300+ const messagePattern = / a l e r t a l w a y s f i r e g r o u p g r o u p - . v a l u e \d + e x c e e d e d t h r e s h o l d m i n \( t e s t e d V a l u e \) .* 0 o v e r 1 5 s o n \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } : \d { 2 } : \d { 2 } .\d { 3 } Z / ;
301+ expect ( message ) . to . match ( messagePattern ) ;
281302 }
282303
283304 // there should be 2 docs in group-0, rando split between others
@@ -329,7 +350,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
329350 name : '{{{alertName}}}' ,
330351 value : '{{{context.value}}}' ,
331352 title : '{{{context.title}}}' ,
332- message : '{{{context.message}}}' ,
353+ message : DefaultActionMessage ,
333354 } ,
334355 date : '{{{context.date}}}' ,
335356 // TODO: I wanted to write the alert value here, but how?
0 commit comments