mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
# Conflicts: # src/core/server/ui_settings/saved_objects/migrations.test.ts
This commit is contained in:
parent
fde0fe31df
commit
a78c6d2b3b
2 changed files with 51 additions and 1 deletions
|
@ -44,3 +44,53 @@ describe('ui_settings 7.9.0 migrations', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('ui_settings 7.12.0 migrations', () => {
|
||||
const migration = migrations['7.12.0'];
|
||||
|
||||
test('returns doc on empty object', () => {
|
||||
expect(migration({} as SavedObjectUnsanitizedDoc)).toEqual({
|
||||
references: [],
|
||||
});
|
||||
});
|
||||
test('properly migrates timepicker:quickRanges', () => {
|
||||
const initialQuickRange: any = {
|
||||
from: '123',
|
||||
to: '321',
|
||||
display: 'abc',
|
||||
section: 2,
|
||||
};
|
||||
const { section, ...migratedQuickRange } = initialQuickRange;
|
||||
|
||||
const doc = {
|
||||
type: 'config',
|
||||
id: '8.0.0',
|
||||
attributes: {
|
||||
buildNum: 9007199254740991,
|
||||
'timepicker:quickRanges': JSON.stringify([initialQuickRange]),
|
||||
},
|
||||
references: [],
|
||||
updated_at: '2020-06-09T20:18:20.349Z',
|
||||
migrationVersion: {},
|
||||
};
|
||||
const migrated = migration(doc);
|
||||
expect(JSON.parse(migrated.attributes['timepicker:quickRanges'])).toEqual([migratedQuickRange]);
|
||||
});
|
||||
|
||||
// https://github.com/elastic/kibana/issues/95616
|
||||
test('returns doc when "timepicker:quickRanges" is null', () => {
|
||||
const doc = {
|
||||
type: 'config',
|
||||
id: '8.0.0',
|
||||
attributes: {
|
||||
buildNum: 9007199254740991,
|
||||
'timepicker:quickRanges': null,
|
||||
},
|
||||
references: [],
|
||||
updated_at: '2020-06-09T20:18:20.349Z',
|
||||
migrationVersion: {},
|
||||
};
|
||||
const migrated = migration(doc);
|
||||
expect(migrated).toEqual(doc);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -32,7 +32,7 @@ export const migrations = {
|
|||
...doc,
|
||||
...(doc.attributes && {
|
||||
attributes: Object.keys(doc.attributes).reduce((acc, key) => {
|
||||
if (key === 'timepicker:quickRanges' && doc.attributes[key].indexOf('section') > -1) {
|
||||
if (key === 'timepicker:quickRanges' && doc.attributes[key]?.indexOf('section') > -1) {
|
||||
const ranges = JSON.parse(doc.attributes[key]).map(
|
||||
({ from, to, display }: { from: string; to: string; display: string }) => {
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue