Skip to content

Commit d325913

Browse files
committed
fix api functional tests
1 parent f49f8cd commit d325913

5 files changed

Lines changed: 42 additions & 12 deletions

File tree

src/plugins/data_views/server/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,9 @@ export type SERVICE_KEY_TYPE = typeof SERVICE_KEY | typeof SERVICE_KEY_LEGACY;
8282
*/
8383

8484
export const INITIAL_REST_VERSION = '2023-10-31';
85+
86+
/**
87+
* Initial REST version internal
88+
*/
89+
90+
export const INITIAL_REST_VERSION_INTERNAL = '1';

src/plugins/data_views/server/rest_api_routes/internal/fields_for.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { estypes } from '@elastic/elasticsearch';
1010
import { schema } from '@kbn/config-schema';
1111
import { IRouter, RequestHandler, StartServicesAccessor } from '@kbn/core/server';
1212
import { FullValidationConfig } from '@kbn/core-http-server';
13+
import { INITIAL_REST_VERSION_INTERNAL as version } from '../../constants';
1314
import { IndexPatternsFetcher } from '../../fetcher';
1415
import type {
1516
DataViewsServerPluginStart,
@@ -38,7 +39,6 @@ export const parseFields = (fields: string | string[]): string[] => {
3839
};
3940

4041
const path = '/api/index_patterns/_fields_for_wildcard';
41-
const version = '1';
4242
const access = 'internal';
4343

4444
type IBody = { index_filter?: estypes.QueryDslQueryContainer } | undefined;

test/api_integration/apis/data_views/data_views_crud/delete_data_view/main.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88

99
import expect from '@kbn/expect';
1010
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
11+
import { INITIAL_REST_VERSION } from '@kbn/data-views-plugin/server/constants';
1112
import { FtrProviderContext } from '../../../../ftr_provider_context';
1213
import { configArray } from '../../constants';
1314

14-
const version = '2023-10-31';
15-
1615
export default function ({ getService }: FtrProviderContext) {
1716
const supertest = getService('supertest');
1817

@@ -23,7 +22,7 @@ export default function ({ getService }: FtrProviderContext) {
2322
const title = `foo-${Date.now()}-${Math.random()}*`;
2423
const response1 = await supertest
2524
.post(config.path)
26-
.set(ELASTIC_HTTP_VERSION_HEADER, version)
25+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION)
2726
.send({
2827
[config.serviceKey]: {
2928
title,
@@ -32,19 +31,19 @@ export default function ({ getService }: FtrProviderContext) {
3231

3332
const response2 = await supertest
3433
.get(`${config.path}/${response1.body[config.serviceKey].id}`)
35-
.set(ELASTIC_HTTP_VERSION_HEADER, version);
34+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION);
3635

3736
expect(response2.status).to.be(200);
3837

3938
const response3 = await supertest
4039
.delete(`${config.path}/${response1.body[config.serviceKey].id}`)
41-
.set(ELASTIC_HTTP_VERSION_HEADER, version);
40+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION);
4241

4342
expect(response3.status).to.be(200);
4443

4544
const response4 = await supertest
4645
.get(`${config.path}/${response1.body[config.serviceKey].id}`)
47-
.set(ELASTIC_HTTP_VERSION_HEADER, version);
46+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION);
4847

4948
expect(response4.status).to.be(404);
5049
});
@@ -55,7 +54,7 @@ export default function ({ getService }: FtrProviderContext) {
5554
const response1 = await supertest
5655

5756
.post(config.path)
58-
.set(ELASTIC_HTTP_VERSION_HEADER, version)
57+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION)
5958
.send({
6059
[config.serviceKey]: {
6160
title,
@@ -65,7 +64,7 @@ export default function ({ getService }: FtrProviderContext) {
6564
await supertest.get(`${config.path}/${response1.body[config.serviceKey].id}`);
6665
const response2 = await supertest
6766
.delete(`${config.path}/${response1.body[config.serviceKey].id}`)
68-
.set(ELASTIC_HTTP_VERSION_HEADER, version);
67+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION);
6968

7069
// verify empty response
7170
expect(Object.keys(response2.body).length).to.be(0);

test/api_integration/apis/data_views/fields_for_wildcard_route/params.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
* Side Public License, v 1.
77
*/
88

9+
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
10+
import { INITIAL_REST_VERSION_INTERNAL } from '@kbn/data-views-plugin/server/constants';
11+
912
export default function ({ getService }) {
1013
const esArchiver = getService('esArchiver');
1114
const supertest = getService('supertest');
@@ -25,6 +28,7 @@ export default function ({ getService }) {
2528
it('accepts include_unmapped param', () =>
2629
supertest
2730
.get('/api/index_patterns/_fields_for_wildcard')
31+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
2832
.query({
2933
pattern: '*',
3034
include_unmapped: true,
@@ -34,6 +38,7 @@ export default function ({ getService }) {
3438
it('rejects unexpected query params', () =>
3539
supertest
3640
.get('/api/index_patterns/_fields_for_wildcard')
41+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
3742
.query({
3843
pattern: randomness.word(),
3944
[randomness.word()]: randomness.word(),
@@ -44,6 +49,7 @@ export default function ({ getService }) {
4449
it('accepts a JSON formatted fields query param', () =>
4550
supertest
4651
.get('/api/index_patterns/_fields_for_wildcard')
52+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
4753
.query({
4854
pattern: '*',
4955
fields: JSON.stringify(['baz']),
@@ -53,6 +59,7 @@ export default function ({ getService }) {
5359
it('accepts meta_fields query param in string array', () =>
5460
supertest
5561
.get('/api/index_patterns/_fields_for_wildcard')
62+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
5663
.query({
5764
pattern: '*',
5865
fields: ['baz', 'foo'],
@@ -62,6 +69,7 @@ export default function ({ getService }) {
6269
it('accepts single array fields query param', () =>
6370
supertest
6471
.get('/api/index_patterns/_fields_for_wildcard')
72+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
6573
.query({
6674
pattern: '*',
6775
fields: ['baz'],
@@ -71,6 +79,7 @@ export default function ({ getService }) {
7179
it('accepts single fields query param', () =>
7280
supertest
7381
.get('/api/index_patterns/_fields_for_wildcard')
82+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
7483
.query({
7584
pattern: '*',
7685
fields: 'baz',
@@ -80,6 +89,7 @@ export default function ({ getService }) {
8089
it('rejects a comma-separated list of fields', () =>
8190
supertest
8291
.get('/api/index_patterns/_fields_for_wildcard')
92+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
8393
.query({
8494
pattern: '*',
8595
fields: 'foo,bar',
@@ -91,6 +101,7 @@ export default function ({ getService }) {
91101
it('accepts a JSON formatted meta_fields query param', () =>
92102
supertest
93103
.get('/api/index_patterns/_fields_for_wildcard')
104+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
94105
.query({
95106
pattern: '*',
96107
meta_fields: JSON.stringify(['meta']),
@@ -100,6 +111,7 @@ export default function ({ getService }) {
100111
it('accepts meta_fields query param in string array', () =>
101112
supertest
102113
.get('/api/index_patterns/_fields_for_wildcard')
114+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
103115
.query({
104116
pattern: '*',
105117
meta_fields: ['_id', 'meta'],
@@ -109,6 +121,7 @@ export default function ({ getService }) {
109121
it('accepts single meta_fields query param', () =>
110122
supertest
111123
.get('/api/index_patterns/_fields_for_wildcard')
124+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
112125
.query({
113126
pattern: '*',
114127
meta_fields: ['_id'],
@@ -118,6 +131,7 @@ export default function ({ getService }) {
118131
it('rejects a comma-separated list of meta_fields', () =>
119132
supertest
120133
.get('/api/index_patterns/_fields_for_wildcard')
134+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
121135
.query({
122136
pattern: '*',
123137
meta_fields: 'foo,bar',

x-pack/test/api_integration/apis/management/rollup/index_patterns_extensions.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* 2.0.
66
*/
77

8+
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
9+
import { INITIAL_REST_VERSION_INTERNAL } from '@kbn/data-views-plugin/server/constants';
810
import expect from '@kbn/expect';
911
import { stringify } from 'query-string';
1012
import { registerHelpers } from './rollup.test_helpers';
@@ -27,7 +29,10 @@ export default function ({ getService }) {
2729

2830
it('"pattern" is required', async () => {
2931
uri = `${BASE_URI}`;
30-
({ body } = await supertest.get(uri).expect(400));
32+
({ body } = await supertest
33+
.get(uri)
34+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
35+
.expect(400));
3136
expect(body.message).to.contain(
3237
'[request query.pattern]: expected value of type [string]'
3338
);
@@ -42,7 +47,10 @@ export default function ({ getService }) {
4247
},
4348
{ sort: false }
4449
)}`;
45-
({ body } = await supertest.get(uri).expect(404));
50+
({ body } = await supertest
51+
.get(uri)
52+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
53+
.expect(404));
4654
expect(body.message).to.contain('No indices match "foo"');
4755
});
4856
});
@@ -61,7 +69,10 @@ export default function ({ getService }) {
6169
rollup_index: rollupIndex,
6270
};
6371
const uri = `${BASE_URI}?${stringify(params, { sort: false })}`;
64-
const { body } = await supertest.get(uri).expect(200);
72+
const { body } = await supertest
73+
.get(uri)
74+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
75+
.expect(200);
6576

6677
// Verify that the fields for wildcard correspond to our declared mappings
6778
// noting that testTotalField and testTagField are not shown in the field caps results

0 commit comments

Comments
 (0)