-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathvis_builder_migration.test.ts
More file actions
107 lines (96 loc) · 2.63 KB
/
vis_builder_migration.test.ts
File metadata and controls
107 lines (96 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { SavedObjectMigrationFn, SavedObjectMigrationContext } from '../../../../core/server';
import { visBuilderSavedObjectTypeMigrations } from './vis_builder_migration';
const savedObjectMigrationContext = (null as unknown) as SavedObjectMigrationContext;
describe('2.3.0', () => {
const migrate = (doc: any) =>
visBuilderSavedObjectTypeMigrations['2.3.0'](
doc as Parameters<SavedObjectMigrationFn>[0],
savedObjectMigrationContext
);
it('should return original doc if visualizationState is not found', () => {
const migratedDoc = migrate({
type: 'wizard',
attributes: {},
});
expect(migratedDoc).toEqual({
type: 'wizard',
attributes: {},
});
});
it('should return original doc if indexPattern is not found within visualizationState', () => {
const migratedDoc = migrate({
type: 'wizard',
attributes: {
visualizationState: {
searchSource: '',
activeVisualization: {},
},
},
});
expect(migratedDoc).toEqual({
type: 'wizard',
attributes: {
visualizationState: {
searchSource: '',
activeVisualization: {},
},
},
});
});
it('should return original doc if references is not an array', () => {
const migratedDoc = migrate({
type: 'wizard',
attributes: {
visualizationState: {},
},
references: {},
});
expect(migratedDoc).toEqual({
type: 'wizard',
attributes: {
visualizationState: {},
},
references: {},
});
});
it('should migrate the old version visBuilder saved object to new version VisBuilder saved object', () => {
const migratedDoc = migrate({
type: 'wizard',
attributes: {
visualizationState: JSON.stringify({
searchFields: {},
activeVisualization: {},
indexPattern: 'indexPatternId',
}),
version: 1,
},
references: [],
});
expect(migratedDoc).toEqual({
type: 'wizard',
attributes: {
visualizationState: JSON.stringify({
searchFields: {},
activeVisualization: {},
}),
version: 2,
kibanaSavedObjectMeta: {
searchSourceJSON: JSON.stringify({
indexRefName: 'kibanaSavedObjectMeta.searchSourceJSON.index',
}),
},
},
references: [
{
name: 'kibanaSavedObjectMeta.searchSourceJSON.index',
type: 'index-pattern',
id: 'indexPatternId',
},
],
});
});
});