Skip to content

Commit

Permalink
fix api functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkime committed Jun 12, 2023
1 parent f49f8cd commit d325913
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/plugins/data_views/server/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,9 @@ export type SERVICE_KEY_TYPE = typeof SERVICE_KEY | typeof SERVICE_KEY_LEGACY;
*/

export const INITIAL_REST_VERSION = '2023-10-31';

/**
* Initial REST version internal
*/

export const INITIAL_REST_VERSION_INTERNAL = '1';
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { estypes } from '@elastic/elasticsearch';
import { schema } from '@kbn/config-schema';
import { IRouter, RequestHandler, StartServicesAccessor } from '@kbn/core/server';
import { FullValidationConfig } from '@kbn/core-http-server';
import { INITIAL_REST_VERSION_INTERNAL as version } from '../../constants';
import { IndexPatternsFetcher } from '../../fetcher';
import type {
DataViewsServerPluginStart,
Expand Down Expand Up @@ -38,7 +39,6 @@ export const parseFields = (fields: string | string[]): string[] => {
};

const path = '/api/index_patterns/_fields_for_wildcard';
const version = '1';
const access = 'internal';

type IBody = { index_filter?: estypes.QueryDslQueryContainer } | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

import expect from '@kbn/expect';
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import { INITIAL_REST_VERSION } from '@kbn/data-views-plugin/server/constants';
import { FtrProviderContext } from '../../../../ftr_provider_context';
import { configArray } from '../../constants';

const version = '2023-10-31';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');

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

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

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

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

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

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

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

.post(config.path)
.set(ELASTIC_HTTP_VERSION_HEADER, version)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION)
.send({
[config.serviceKey]: {
title,
Expand All @@ -65,7 +64,7 @@ export default function ({ getService }: FtrProviderContext) {
await supertest.get(`${config.path}/${response1.body[config.serviceKey].id}`);
const response2 = await supertest
.delete(`${config.path}/${response1.body[config.serviceKey].id}`)
.set(ELASTIC_HTTP_VERSION_HEADER, version);
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION);

// verify empty response
expect(Object.keys(response2.body).length).to.be(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* Side Public License, v 1.
*/

import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import { INITIAL_REST_VERSION_INTERNAL } from '@kbn/data-views-plugin/server/constants';

export default function ({ getService }) {
const esArchiver = getService('esArchiver');
const supertest = getService('supertest');
Expand All @@ -25,6 +28,7 @@ export default function ({ getService }) {
it('accepts include_unmapped param', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
include_unmapped: true,
Expand All @@ -34,6 +38,7 @@ export default function ({ getService }) {
it('rejects unexpected query params', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: randomness.word(),
[randomness.word()]: randomness.word(),
Expand All @@ -44,6 +49,7 @@ export default function ({ getService }) {
it('accepts a JSON formatted fields query param', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
fields: JSON.stringify(['baz']),
Expand All @@ -53,6 +59,7 @@ export default function ({ getService }) {
it('accepts meta_fields query param in string array', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
fields: ['baz', 'foo'],
Expand All @@ -62,6 +69,7 @@ export default function ({ getService }) {
it('accepts single array fields query param', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
fields: ['baz'],
Expand All @@ -71,6 +79,7 @@ export default function ({ getService }) {
it('accepts single fields query param', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
fields: 'baz',
Expand All @@ -80,6 +89,7 @@ export default function ({ getService }) {
it('rejects a comma-separated list of fields', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
fields: 'foo,bar',
Expand All @@ -91,6 +101,7 @@ export default function ({ getService }) {
it('accepts a JSON formatted meta_fields query param', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
meta_fields: JSON.stringify(['meta']),
Expand All @@ -100,6 +111,7 @@ export default function ({ getService }) {
it('accepts meta_fields query param in string array', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
meta_fields: ['_id', 'meta'],
Expand All @@ -109,6 +121,7 @@ export default function ({ getService }) {
it('accepts single meta_fields query param', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
meta_fields: ['_id'],
Expand All @@ -118,6 +131,7 @@ export default function ({ getService }) {
it('rejects a comma-separated list of meta_fields', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
meta_fields: 'foo,bar',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* 2.0.
*/

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

it('"pattern" is required', async () => {
uri = `${BASE_URI}`;
({ body } = await supertest.get(uri).expect(400));
({ body } = await supertest
.get(uri)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.expect(400));
expect(body.message).to.contain(
'[request query.pattern]: expected value of type [string]'
);
Expand All @@ -42,7 +47,10 @@ export default function ({ getService }) {
},
{ sort: false }
)}`;
({ body } = await supertest.get(uri).expect(404));
({ body } = await supertest
.get(uri)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.expect(404));
expect(body.message).to.contain('No indices match "foo"');
});
});
Expand All @@ -61,7 +69,10 @@ export default function ({ getService }) {
rollup_index: rollupIndex,
};
const uri = `${BASE_URI}?${stringify(params, { sort: false })}`;
const { body } = await supertest.get(uri).expect(200);
const { body } = await supertest
.get(uri)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.expect(200);

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

0 comments on commit d325913

Please sign in to comment.