Skip to content

Commit

Permalink
Allow getAsSavedObjectBody to return non-scripted fields when allowNo…
Browse files Browse the repository at this point in the history
…Index is true

(cherry picked from commit 69b93da)
  • Loading branch information
jen-huang committed Mar 16, 2021
1 parent 76dd02b commit afc91ce
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { stubbedSavedObjectIndexPattern } from './fixtures/stubbed_saved_object_
import { IndexPatternField } from '../fields';

import { fieldFormatsMock } from '../../field_formats/mocks';
import { FieldFormat } from '../..';
import { FieldFormat, IndexPatternSpec } from '../..';
import { RuntimeField } from '../types';

class MockFieldFormatter {}
Expand All @@ -42,7 +42,7 @@ const runtimeField = {
fieldFormatsMock.getInstance = jest.fn().mockImplementation(() => new MockFieldFormatter()) as any;

// helper function to create index patterns
function create(id: string) {
function create(id: string, spec?: Partial<IndexPatternSpec>) {
const {
type,
version,
Expand All @@ -58,6 +58,7 @@ function create(id: string) {
fields: { ...fields, runtime_field: runtimeField },
title,
runtimeFieldMap,
...(spec || {}),
},
fieldFormats: fieldFormatsMock,
shortDotsEnable: false,
Expand Down Expand Up @@ -314,4 +315,15 @@ describe('IndexPattern', () => {
expect(restoredPattern.fields.length).toEqual(indexPattern.fields.length);
});
});

describe('getAsSavedObjectBody', () => {
test('should match snapshot', () => {
expect(indexPattern.getAsSavedObjectBody()).toMatchSnapshot();
});

test('allowNoIndex perserves all fields', () => {
const allowNoIndexIndexPattern = create('test-no-index-pattern', { allowNoIndex: true });
expect(allowNoIndexIndexPattern.getAsSavedObjectBody()).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ export class IndexPattern implements IIndexPattern {
intervalName: this.intervalName,
sourceFilters: this.sourceFilters ? JSON.stringify(this.sourceFilters) : undefined,
fields: this.fields
? JSON.stringify(this.fields.filter((field) => field.scripted))
? JSON.stringify(
this.allowNoIndex ? this.fields : this.fields.filter((field) => field.scripted)
)
: undefined,
fieldFormatMap,
type: this.type,
Expand Down

0 comments on commit afc91ce

Please sign in to comment.