3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
5
6
- import { VisLayerExpressionFn , VisLayerTypes } from '../types' ;
6
+ import { VisLayerTypes } from '../types' ;
7
+ import { VisLayerExpressionFn } from '../expressions' ;
7
8
import {
8
9
createSavedAugmentVisLoader ,
9
10
SavedObjectOpenSearchDashboardsServicesWithAugmentVis ,
10
11
} from './saved_augment_vis' ;
11
12
import { generateAugmentVisSavedObject , getMockAugmentVisSavedObjectClient } from './utils' ;
13
+ import { ISavedPluginResource } from './types' ;
12
14
13
15
describe ( 'SavedObjectLoaderAugmentVis' , ( ) => {
14
16
const fn = {
@@ -18,22 +20,74 @@ describe('SavedObjectLoaderAugmentVis', () => {
18
20
testArg : 'test-value' ,
19
21
} ,
20
22
} as VisLayerExpressionFn ;
21
- const validObj1 = generateAugmentVisSavedObject ( 'valid-obj-id-1' , fn , 'test-vis-id' ) ;
22
- const validObj2 = generateAugmentVisSavedObject ( 'valid-obj-id-2' , fn , 'test-vis-id' ) ;
23
+ const originPlugin = 'test-plugin' ;
24
+ const pluginResource = {
25
+ type : 'test-plugin' ,
26
+ id : 'test-plugin-resource-id' ,
27
+ } ;
28
+ const validObj1 = generateAugmentVisSavedObject (
29
+ 'valid-obj-id-1' ,
30
+ fn ,
31
+ 'test-vis-id' ,
32
+ originPlugin ,
33
+ pluginResource
34
+ ) ;
35
+ const validObj2 = generateAugmentVisSavedObject (
36
+ 'valid-obj-id-2' ,
37
+ fn ,
38
+ 'test-vis-id' ,
39
+ originPlugin ,
40
+ pluginResource
41
+ ) ;
23
42
const invalidFnTypeObj = generateAugmentVisSavedObject (
24
43
'invalid-fn-obj-id-1' ,
25
44
{
26
45
...fn ,
27
46
// @ts -ignore
28
47
type : 'invalid-type' ,
29
48
} ,
30
- 'test-vis-id'
49
+ 'test-vis-id' ,
50
+ originPlugin ,
51
+ pluginResource
31
52
) ;
32
53
33
54
const missingFnObj = generateAugmentVisSavedObject (
34
55
'missing-fn-obj-id-1' ,
35
56
{ } as VisLayerExpressionFn ,
36
- 'test-vis-id'
57
+ 'test-vis-id' ,
58
+ originPlugin ,
59
+ pluginResource
60
+ ) ;
61
+
62
+ const missingOriginPluginObj = generateAugmentVisSavedObject (
63
+ 'missing-origin-plugin-obj-id-1' ,
64
+ fn ,
65
+ 'test-vis-id' ,
66
+ // @ts -ignore
67
+ undefined ,
68
+ pluginResource
69
+ ) ;
70
+
71
+ const missingPluginResourceTypeObj = generateAugmentVisSavedObject (
72
+ 'missing-plugin-resource-type-obj-id-1' ,
73
+ fn ,
74
+ 'test-vis-id' ,
75
+ // @ts -ignore
76
+ originPlugin ,
77
+ {
78
+ id : pluginResource . id ,
79
+ } as ISavedPluginResource
80
+ ) ;
81
+
82
+ const missingPluginResourceIdObj = generateAugmentVisSavedObject (
83
+ 'missing-plugin-resource-id-obj-id-1' ,
84
+ fn ,
85
+ 'test-vis-id' ,
86
+ // @ts -ignore
87
+ originPlugin ,
88
+ {
89
+ type : pluginResource . type ,
90
+ } as ISavedPluginResource
37
91
) ;
38
92
39
93
it ( 'find returns single saved obj' , async ( ) => {
@@ -105,4 +159,36 @@ describe('SavedObjectLoaderAugmentVis', () => {
105
159
expect ( resp . hits [ 0 ] . id ) . toEqual ( 'valid-obj-id-1' ) ;
106
160
expect ( resp . hits [ 0 ] . error ) . toEqual ( 'visReference is missing in augment-vis saved object' ) ;
107
161
} ) ;
162
+
163
+ it ( 'findAll returns obj with missing originPlugin' , async ( ) => {
164
+ const loader = createSavedAugmentVisLoader ( {
165
+ savedObjectsClient : getMockAugmentVisSavedObjectClient ( [ missingOriginPluginObj ] ) ,
166
+ } as SavedObjectOpenSearchDashboardsServicesWithAugmentVis ) ;
167
+ const resp = await loader . findAll ( ) ;
168
+ expect ( resp . hits . length ) . toEqual ( 1 ) ;
169
+ expect ( resp . hits [ 0 ] . id ) . toEqual ( 'missing-origin-plugin-obj-id-1' ) ;
170
+ expect ( resp . hits [ 0 ] . error ) . toEqual ( 'originPlugin is missing in augment-vis saved object' ) ;
171
+ } ) ;
172
+
173
+ it ( 'findAll returns obj with missing plugin resource type' , async ( ) => {
174
+ const loader = createSavedAugmentVisLoader ( {
175
+ savedObjectsClient : getMockAugmentVisSavedObjectClient ( [ missingPluginResourceTypeObj ] ) ,
176
+ } as SavedObjectOpenSearchDashboardsServicesWithAugmentVis ) ;
177
+ const resp = await loader . findAll ( ) ;
178
+ expect ( resp . hits . length ) . toEqual ( 1 ) ;
179
+ expect ( resp . hits [ 0 ] . id ) . toEqual ( 'missing-plugin-resource-type-obj-id-1' ) ;
180
+ expect ( resp . hits [ 0 ] . error ) . toEqual (
181
+ 'pluginResource.type is missing in augment-vis saved object'
182
+ ) ;
183
+ } ) ;
184
+
185
+ it ( 'findAll returns obj with missing plugin resource id' , async ( ) => {
186
+ const loader = createSavedAugmentVisLoader ( {
187
+ savedObjectsClient : getMockAugmentVisSavedObjectClient ( [ missingPluginResourceIdObj ] ) ,
188
+ } as SavedObjectOpenSearchDashboardsServicesWithAugmentVis ) ;
189
+ const resp = await loader . findAll ( ) ;
190
+ expect ( resp . hits . length ) . toEqual ( 1 ) ;
191
+ expect ( resp . hits [ 0 ] . id ) . toEqual ( 'missing-plugin-resource-id-obj-id-1' ) ;
192
+ expect ( resp . hits [ 0 ] . error ) . toEqual ( 'pluginResource.id is missing in augment-vis saved object' ) ;
193
+ } ) ;
108
194
} ) ;
0 commit comments