8
8
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants' ;
9
9
import { RoleCredentials } from '@kbn/ftr-common-functional-services' ;
10
10
import expect from '@kbn/expect' ;
11
- import { PrivateLocation } from '@kbn/synthetics-plugin/common/runtime_types' ;
12
- import { syntheticsMonitorSavedObjectType } from '@kbn/synthetics-plugin/common/types/saved_objects' ;
13
- import { DeploymentAgnosticFtrProviderContext } from '../../ftr_provider_context' ;
11
+ import type { PrivateLocation } from '@kbn/synthetics-plugin/common/runtime_types' ;
12
+ import {
13
+ legacySyntheticsMonitorTypeSingle ,
14
+ syntheticsMonitorSavedObjectType ,
15
+ } from '@kbn/synthetics-plugin/common/types/saved_objects' ;
16
+ import type { DeploymentAgnosticFtrProviderContext } from '../../ftr_provider_context' ;
14
17
import { PrivateLocationTestService } from '../../services/synthetics_private_location' ;
18
+ import { addMonitorAPIHelper } from './create_monitor' ;
15
19
16
20
export default function ( { getService } : DeploymentAgnosticFtrProviderContext ) {
17
21
describe ( 'getMonitorFilters' , function ( ) {
@@ -25,15 +29,23 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
25
29
let privateLocation : PrivateLocation ;
26
30
27
31
after ( async ( ) => {
28
- await kibanaServer . savedObjects . clean ( { types : [ syntheticsMonitorSavedObjectType ] } ) ;
32
+ await kibanaServer . savedObjects . clean ( {
33
+ types : [ syntheticsMonitorSavedObjectType , legacySyntheticsMonitorTypeSingle ] ,
34
+ } ) ;
29
35
} ) ;
30
36
31
37
before ( async ( ) => {
32
- await kibanaServer . savedObjects . clean ( { types : [ syntheticsMonitorSavedObjectType ] } ) ;
38
+ await kibanaServer . savedObjects . clean ( {
39
+ types : [ syntheticsMonitorSavedObjectType , legacySyntheticsMonitorTypeSingle ] ,
40
+ } ) ;
33
41
editorUser = await samlAuth . createM2mApiKeyWithRoleScope ( 'editor' ) ;
34
42
privateLocation = await privateLocationTestService . addTestPrivateLocation ( ) ;
35
43
} ) ;
36
44
45
+ const addMonitor = async ( monitor : any , type ?: string ) => {
46
+ return addMonitorAPIHelper ( supertest , monitor , 200 , editorUser , samlAuth , false , type ) ;
47
+ } ;
48
+
37
49
it ( 'get list of filters' , async ( ) => {
38
50
const apiResponse = await supertest
39
51
. get ( SYNTHETICS_API_URLS . FILTERS )
@@ -59,12 +71,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
59
71
locations : [ privateLocation ] ,
60
72
} ;
61
73
62
- await supertest
63
- . post ( SYNTHETICS_API_URLS . SYNTHETICS_MONITORS )
64
- . set ( editorUser . apiKeyHeader )
65
- . set ( samlAuth . getInternalRequestHeader ( ) )
66
- . send ( newMonitor )
67
- . expect ( 200 ) ;
74
+ await addMonitor ( newMonitor ) ;
68
75
69
76
const apiResponse = await supertest
70
77
. get ( SYNTHETICS_API_URLS . FILTERS )
@@ -83,5 +90,83 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
83
90
schedules : [ { label : '3' , count : 1 } ] ,
84
91
} ) ;
85
92
} ) ;
93
+
94
+ it ( 'get list of filters for legacy saved object type monitor' , async ( ) => {
95
+ // Create a legacy monitor directly via savedObjectsClient
96
+
97
+ // Use the internal savedObjectsClient to create a legacy monitor
98
+ await addMonitor (
99
+ {
100
+ name : 'Legacy Monitor' ,
101
+ type : 'icmp' ,
102
+ host : 'https://legacy.elastic.co' ,
103
+ tags : [ 'legacy' , 'synthetics' ] ,
104
+ locations : [ privateLocation ] ,
105
+ } ,
106
+ legacySyntheticsMonitorTypeSingle
107
+ ) ;
108
+
109
+ const apiResponse = await supertest
110
+ . get ( SYNTHETICS_API_URLS . FILTERS )
111
+ . set ( editorUser . apiKeyHeader )
112
+ . set ( samlAuth . getInternalRequestHeader ( ) )
113
+ . expect ( 200 ) ;
114
+
115
+ expect ( apiResponse . body . monitorTypes ) . to . eql ( [
116
+ { label : 'http' , count : 1 } ,
117
+ { label : 'icmp' , count : 1 } ,
118
+ ] ) ;
119
+ expect ( apiResponse . body . tags ) . to . eql ( [
120
+ { label : 'apm' , count : 1 } ,
121
+ { label : 'synthetics' , count : 2 } ,
122
+ { label : 'legacy' , count : 1 } ,
123
+ ] ) ;
124
+ expect ( apiResponse . body . locations ) . to . eql ( [ { label : privateLocation . id , count : 2 } ] ) ;
125
+ expect ( apiResponse . body . schedules ) . to . eql ( [ { label : '3' , count : 2 } ] ) ;
126
+ } ) ;
127
+
128
+ it ( 'get list of filters with both legacy and modern monitors' , async ( ) => {
129
+ // Create a modern monitor
130
+ const modernMonitor = {
131
+ name : 'Modern Monitor' ,
132
+ type : 'http' ,
133
+ urls : 'https://modern.elastic.co' ,
134
+ tags : [ 'multi-space' , 'synthetics' ] ,
135
+ locations : [ privateLocation ] ,
136
+ } ;
137
+
138
+ await addMonitor ( modernMonitor ) ;
139
+
140
+ await addMonitor (
141
+ {
142
+ name : 'Legacy Monitor 3' ,
143
+ type : 'icmp' ,
144
+ host : 'https://legacy2.elastic.co' ,
145
+ tags : [ 'legacy2' , 'synthetics' ] ,
146
+ locations : [ privateLocation ] ,
147
+ } ,
148
+ legacySyntheticsMonitorTypeSingle
149
+ ) ;
150
+
151
+ const apiResponse = await supertest
152
+ . get ( SYNTHETICS_API_URLS . FILTERS )
153
+ . set ( editorUser . apiKeyHeader )
154
+ . set ( samlAuth . getInternalRequestHeader ( ) )
155
+ . expect ( 200 ) ;
156
+
157
+ expect ( apiResponse . body . monitorTypes ) . to . eql ( [
158
+ { label : 'http' , count : 2 } ,
159
+ { label : 'icmp' , count : 2 } ,
160
+ ] ) ;
161
+ expect ( apiResponse . body . tags ) . to . eql ( [
162
+ { label : 'synthetics' , count : 4 } ,
163
+ { label : 'apm' , count : 1 } ,
164
+ { label : 'multi-space' , count : 1 } ,
165
+ { label : 'legacy' , count : 1 } ,
166
+ { label : 'legacy2' , count : 1 } ,
167
+ ] ) ;
168
+ expect ( apiResponse . body . locations ) . to . eql ( [ { label : privateLocation . id , count : 4 } ] ) ;
169
+ expect ( apiResponse . body . schedules ) . to . eql ( [ { label : '3' , count : 4 } ] ) ;
170
+ } ) ;
86
171
} ) ;
87
172
}
0 commit comments