Fix includeFields function to return root saved object properties (#33847)

* Fix includeFields function to return root saved object properties

* Fix broken tests
This commit is contained in:
Mike Côté 2019-03-27 09:50:50 -04:00 committed by GitHub
parent d3ad8a4b0b
commit 00e1b3ca5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 9 deletions

View file

@ -35,5 +35,8 @@ export function includedFields(type, fields) {
.map(f => `${sourceType}.${f}`)
.concat('namespace')
.concat('type')
.concat('references')
.concat('migrationVersion')
.concat('updated_at')
.concat(fields); // v5 compatibility
}

View file

@ -26,33 +26,51 @@ describe('includedFields', () => {
it('includes type', () => {
const fields = includedFields('config', 'foo');
expect(fields).toHaveLength(4);
expect(fields).toHaveLength(7);
expect(fields).toContain('type');
});
it('includes namespace', () => {
const fields = includedFields('config', 'foo');
expect(fields).toHaveLength(4);
expect(fields).toHaveLength(7);
expect(fields).toContain('namespace');
});
it('includes references', () => {
const fields = includedFields('config', 'foo');
expect(fields).toHaveLength(7);
expect(fields).toContain('references');
});
it('includes migrationVersion', () => {
const fields = includedFields('config', 'foo');
expect(fields).toHaveLength(7);
expect(fields).toContain('migrationVersion');
});
it('includes updated_at', () => {
const fields = includedFields('config', 'foo');
expect(fields).toHaveLength(7);
expect(fields).toContain('updated_at');
});
it('accepts field as string', () => {
const fields = includedFields('config', 'foo');
expect(fields).toHaveLength(4);
expect(fields).toHaveLength(7);
expect(fields).toContain('config.foo');
});
it('accepts fields as an array', () => {
const fields = includedFields('config', ['foo', 'bar']);
expect(fields).toHaveLength(6);
expect(fields).toHaveLength(9);
expect(fields).toContain('config.foo');
expect(fields).toContain('config.bar');
});
it('uses wildcard when type is not provided', () => {
const fields = includedFields(undefined, 'foo');
expect(fields).toHaveLength(4);
expect(fields).toHaveLength(7);
expect(fields).toContain('*.foo');
});
@ -60,7 +78,7 @@ describe('includedFields', () => {
it('includes legacy field path', () => {
const fields = includedFields('config', ['foo', 'bar']);
expect(fields).toHaveLength(6);
expect(fields).toHaveLength(9);
expect(fields).toContain('foo');
expect(fields).toContain('bar');
});

View file

@ -1224,7 +1224,15 @@ describe('SavedObjectsRepository', () => {
expect(callAdminCluster).toHaveBeenCalledWith(
expect.any(String),
expect.objectContaining({
_source: ['foo.title', 'namespace', 'type', 'title'],
_source: [
'foo.title',
'namespace',
'type',
'references',
'migrationVersion',
'updated_at',
'title',
],
})
);

View file

@ -46,7 +46,17 @@ export default function ({ getService }) {
attributes: {
'title': 'Count of requests'
},
references: [],
migrationVersion: {
visualization: '7.0.0',
},
references: [
{
id: '91200a00-9efd-11e7-acb3-3dab96693fab',
name: 'kibanaSavedObjectMeta.searchSourceJSON.index',
type: 'index-pattern',
},
],
updated_at: '2017-09-21T18:51:23.794Z',
}
]
});

View file

@ -68,6 +68,7 @@ export function findTestSuiteFactory(esArchiver: any, supertest: SuperTest<any>)
name: 'My favorite global object',
},
references: [],
updated_at: '2017-09-21T18:59:16.270Z',
},
],
});
@ -100,7 +101,17 @@ export function findTestSuiteFactory(esArchiver: any, supertest: SuperTest<any>)
attributes: {
title: 'Count of requests',
},
references: [],
migrationVersion: {
visualization: '7.0.0',
},
references: [
{
id: `${getIdPrefix(spaceId)}91200a00-9efd-11e7-acb3-3dab96693fab`,
name: 'kibanaSavedObjectMeta.searchSourceJSON.index',
type: 'index-pattern',
},
],
updated_at: '2017-09-21T18:51:23.794Z',
},
],
});