kibana/x-pack/test_serverless/shared/services/data_view_api.ts
Robert Oskamp 851b99fcba
Serverless search tests - recreate default data view (#183135)
## Summary

This PR fixes an issue with serverless search tests when running against
MKI. Due to a different test run order there, the search project default
data view does not necessarily exist anymore when the test runs (as
another test might have cleaned it up already). To fix this, the default
data view is re-created during `before` of the default data view test
suite.

As part of this PR, the `data_view_api` service is moved from the
`api_integration` services to the `shared` services, so it can be used
from functional tests as well.
2024-05-10 14:23:20 +02:00

52 lines
1.5 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { FtrProviderContext } from '../../functional/ftr_provider_context';
export function DataViewApiProvider({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
return {
async create({ id, name, title }: { id: string; name: string; title: string }) {
const { body } = await supertest
.post(`/api/content_management/rpc/create`)
.set('kbn-xsrf', 'foo')
.set('x-elastic-internal-origin', 'foo')
.send({
contentTypeId: 'index-pattern',
data: {
fieldAttrs: '{}',
title,
timeFieldName: '@timestamp',
sourceFilters: '[]',
fields: '[]',
fieldFormatMap: '{}',
typeMeta: '{}',
runtimeFieldMap: '{}',
name,
},
options: { id },
version: 1,
});
return body;
},
async delete({ id }: { id: string }) {
const { body } = await supertest
.post(`/api/content_management/rpc/delete`)
.set('kbn-xsrf', 'foo')
.set('x-elastic-internal-origin', 'foo')
.send({
contentTypeId: 'index-pattern',
id,
options: { force: true },
version: 1,
});
return body;
},
};
}