From 2a4552087fb35cf5040dd25bd811c9565abc1bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Tue, 19 Jan 2021 18:54:48 +0100 Subject: [PATCH 1/3] [FTR] Use new ES client instead of legacyEs service --- .../apis/home/{index.js => index.ts} | 4 +- .../home/{sample_data.js => sample_data.ts} | 11 ++--- .../apis/{index.js => index.ts} | 4 +- .../apis/kql_telemetry/{index.js => index.ts} | 4 +- .../{kql_telemetry.js => kql_telemetry.ts} | 9 ++-- .../{bulk_create.js => bulk_create.ts} | 13 +++--- .../{bulk_get.js => bulk_get.ts} | 10 ++--- .../{bulk_update.js => bulk_update.ts} | 10 ++--- .../saved_objects/{create.js => create.ts} | 12 +++--- .../saved_objects/{delete.js => delete.ts} | 10 ++--- .../apis/saved_objects/export.ts | 7 +--- .../apis/saved_objects/{find.js => find.ts} | 42 ++++++++++++------- .../apis/saved_objects/{get.js => get.ts} | 10 ++--- .../apis/saved_objects/{index.js => index.ts} | 4 +- ...ort_errors.js => resolve_import_errors.ts} | 3 +- .../saved_objects/{update.js => update.ts} | 10 ++--- .../apis/saved_objects_management/find.ts | 7 +--- .../apis/saved_objects_management/get.ts | 7 +--- .../{ui_counters.js => ui_counters.ts} | 0 ...{telemetry_local.js => telemetry_local.ts} | 25 +++++++---- .../telemetry/telemetry_optin_notice_seen.ts | 27 +++++------- .../apis/ui_counters/{index.js => index.ts} | 4 +- .../{ui_counters.js => ui_counters.ts} | 26 +++++++----- .../apis/ui_metric/{index.js => index.ts} | 4 +- .../ui_metric/{ui_metric.js => ui_metric.ts} | 33 +++++++++------ .../telemetry/telemetry_optin_notice_seen.ts | 27 +++++------- 26 files changed, 168 insertions(+), 155 deletions(-) rename test/api_integration/apis/home/{index.js => index.ts} (77%) rename test/api_integration/apis/home/{sample_data.js => sample_data.ts} (90%) rename test/api_integration/apis/{index.js => index.ts} (90%) rename test/api_integration/apis/kql_telemetry/{index.js => index.ts} (76%) rename test/api_integration/apis/kql_telemetry/{kql_telemetry.js => kql_telemetry.ts} (93%) rename test/api_integration/apis/saved_objects/{bulk_create.js => bulk_create.ts} (93%) rename test/api_integration/apis/saved_objects/{bulk_get.js => bulk_get.ts} (95%) rename test/api_integration/apis/saved_objects/{bulk_update.js => bulk_update.ts} (97%) rename test/api_integration/apis/saved_objects/{create.js => create.ts} (90%) rename test/api_integration/apis/saved_objects/{delete.js => delete.ts} (89%) rename test/api_integration/apis/saved_objects/{find.js => find.ts} (92%) rename test/api_integration/apis/saved_objects/{get.js => get.ts} (93%) rename test/api_integration/apis/saved_objects/{index.js => index.ts} (88%) rename test/api_integration/apis/saved_objects/{resolve_import_errors.js => resolve_import_errors.ts} (98%) rename test/api_integration/apis/saved_objects/{update.js => update.ts} (95%) rename test/api_integration/apis/telemetry/__fixtures__/{ui_counters.js => ui_counters.ts} (100%) rename test/api_integration/apis/telemetry/{telemetry_local.js => telemetry_local.ts} (93%) rename test/api_integration/apis/ui_counters/{index.js => index.ts} (77%) rename test/api_integration/apis/ui_counters/{ui_counters.js => ui_counters.ts} (71%) rename test/api_integration/apis/ui_metric/{index.js => index.ts} (76%) rename test/api_integration/apis/ui_metric/{ui_metric.js => ui_metric.ts} (74%) diff --git a/test/api_integration/apis/home/index.js b/test/api_integration/apis/home/index.ts similarity index 77% rename from test/api_integration/apis/home/index.js rename to test/api_integration/apis/home/index.ts index 51b599cdd0816..95ff370456866 100644 --- a/test/api_integration/apis/home/index.js +++ b/test/api_integration/apis/home/index.ts @@ -6,7 +6,9 @@ * Public License, v 1. */ -export default function ({ loadTestFile }) { +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { describe('home apis', () => { loadTestFile(require.resolve('./sample_data')); }); diff --git a/test/api_integration/apis/home/sample_data.js b/test/api_integration/apis/home/sample_data.ts similarity index 90% rename from test/api_integration/apis/home/sample_data.js rename to test/api_integration/apis/home/sample_data.ts index bac1ef11f1070..042aff1375267 100644 --- a/test/api_integration/apis/home/sample_data.js +++ b/test/api_integration/apis/home/sample_data.ts @@ -7,10 +7,11 @@ */ import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../ftr_provider_context'; -export default function ({ getService }) { +export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - const es = getService('legacyEs'); + const es = getService('es'); const MILLISECOND_IN_WEEK = 1000 * 60 * 60 * 24 * 7; @@ -43,7 +44,7 @@ export default function ({ getService }) { }); it('should load elasticsearch index containing sample data with dates relative to current time', async () => { - const resp = await es.search({ + const { body: resp } = await es.search({ index: 'kibana_sample_data_flights', }); @@ -61,7 +62,7 @@ export default function ({ getService }) { .post(`/api/sample_data/flights?now=${nowString}`) .set('kbn-xsrf', 'kibana'); - const resp = await es.search({ + const { body: resp } = await es.search({ index: 'kibana_sample_data_flights', }); @@ -80,7 +81,7 @@ export default function ({ getService }) { }); it('should remove elasticsearch index containing sample data', async () => { - const resp = await es.indices.exists({ + const { body: resp } = await es.indices.exists({ index: 'kibana_sample_data_flights', }); expect(resp).to.be(false); diff --git a/test/api_integration/apis/index.js b/test/api_integration/apis/index.ts similarity index 90% rename from test/api_integration/apis/index.js rename to test/api_integration/apis/index.ts index 25f46feab693a..73629231b5951 100644 --- a/test/api_integration/apis/index.js +++ b/test/api_integration/apis/index.ts @@ -6,7 +6,9 @@ * Public License, v 1. */ -export default function ({ loadTestFile }) { +import { FtrProviderContext } from '../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { describe('apis', () => { loadTestFile(require.resolve('./core')); loadTestFile(require.resolve('./general')); diff --git a/test/api_integration/apis/kql_telemetry/index.js b/test/api_integration/apis/kql_telemetry/index.ts similarity index 76% rename from test/api_integration/apis/kql_telemetry/index.js rename to test/api_integration/apis/kql_telemetry/index.ts index 18e2fa680c432..afcb96ea8981c 100644 --- a/test/api_integration/apis/kql_telemetry/index.js +++ b/test/api_integration/apis/kql_telemetry/index.ts @@ -6,7 +6,9 @@ * Public License, v 1. */ -export default function ({ loadTestFile }) { +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { describe('KQL', () => { loadTestFile(require.resolve('./kql_telemetry')); }); diff --git a/test/api_integration/apis/kql_telemetry/kql_telemetry.js b/test/api_integration/apis/kql_telemetry/kql_telemetry.ts similarity index 93% rename from test/api_integration/apis/kql_telemetry/kql_telemetry.js rename to test/api_integration/apis/kql_telemetry/kql_telemetry.ts index 1963b4edebb66..027206b971c45 100644 --- a/test/api_integration/apis/kql_telemetry/kql_telemetry.js +++ b/test/api_integration/apis/kql_telemetry/kql_telemetry.ts @@ -9,11 +9,12 @@ import expect from '@kbn/expect'; import Bluebird from 'bluebird'; import { get } from 'lodash'; +import { FtrProviderContext } from '../../ftr_provider_context'; -export default function ({ getService }) { +export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); const esArchiver = getService('esArchiver'); - const es = getService('legacyEs'); + const es = getService('es'); describe('telemetry API', () => { before(() => esArchiver.load('saved_objects/basic')); @@ -31,7 +32,7 @@ export default function ({ getService }) { index: '.kibana', q: 'type:kql-telemetry', }) - .then((response) => { + .then(({ body: response }) => { const kqlTelemetryDoc = get(response, 'hits.hits[0]._source.kql-telemetry'); expect(kqlTelemetryDoc.optInCount).to.be(1); }); @@ -49,7 +50,7 @@ export default function ({ getService }) { index: '.kibana', q: 'type:kql-telemetry', }) - .then((response) => { + .then(({ body: response }) => { const kqlTelemetryDoc = get(response, 'hits.hits[0]._source.kql-telemetry'); expect(kqlTelemetryDoc.optOutCount).to.be(1); }); diff --git a/test/api_integration/apis/saved_objects/bulk_create.js b/test/api_integration/apis/saved_objects/bulk_create.ts similarity index 93% rename from test/api_integration/apis/saved_objects/bulk_create.js rename to test/api_integration/apis/saved_objects/bulk_create.ts index 2c18df8bc3b19..903332a0a930f 100644 --- a/test/api_integration/apis/saved_objects/bulk_create.js +++ b/test/api_integration/apis/saved_objects/bulk_create.ts @@ -7,10 +7,11 @@ */ import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../ftr_provider_context'; -export default function ({ getService }) { +export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - const es = getService('legacyEs'); + const es = getService('es'); const esArchiver = getService('esArchiver'); const BULK_REQUESTS = [ @@ -74,11 +75,10 @@ export default function ({ getService }) { it('should not return raw id when object id is unspecified', async () => await supertest .post(`/api/saved_objects/_bulk_create`) - // eslint-disable-next-line no-unused-vars .send(BULK_REQUESTS.map(({ id, ...rest }) => rest)) .expect(200) .then((resp) => { - resp.body.saved_objects.map(({ id }) => + resp.body.saved_objects.map(({ id }: { id: string }) => expect(id).not.match(/visualization|dashboard/) ); })); @@ -88,10 +88,7 @@ export default function ({ getService }) { before( async () => // just in case the kibana server has recreated it - await es.indices.delete({ - index: '.kibana', - ignore: [404], - }) + await es.indices.delete({ index: '.kibana' }, { ignore: [404] }) ); it('should return 200 with individual responses', async () => diff --git a/test/api_integration/apis/saved_objects/bulk_get.js b/test/api_integration/apis/saved_objects/bulk_get.ts similarity index 95% rename from test/api_integration/apis/saved_objects/bulk_get.js rename to test/api_integration/apis/saved_objects/bulk_get.ts index 7870f880b5f74..e552c08a58cf0 100644 --- a/test/api_integration/apis/saved_objects/bulk_get.js +++ b/test/api_integration/apis/saved_objects/bulk_get.ts @@ -7,10 +7,11 @@ */ import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../ftr_provider_context'; -export default function ({ getService }) { +export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - const es = getService('legacyEs'); + const es = getService('es'); const esArchiver = getService('esArchiver'); const BULK_REQUESTS = [ @@ -98,10 +99,7 @@ export default function ({ getService }) { before( async () => // just in case the kibana server has recreated it - await es.indices.delete({ - index: '.kibana', - ignore: [404], - }) + await es.indices.delete({ index: '.kibana' }, { ignore: [404] }) ); it('should return 200 with individual responses', async () => diff --git a/test/api_integration/apis/saved_objects/bulk_update.js b/test/api_integration/apis/saved_objects/bulk_update.ts similarity index 97% rename from test/api_integration/apis/saved_objects/bulk_update.js rename to test/api_integration/apis/saved_objects/bulk_update.ts index b7e48a467c26a..5a2496b6dde81 100644 --- a/test/api_integration/apis/saved_objects/bulk_update.js +++ b/test/api_integration/apis/saved_objects/bulk_update.ts @@ -8,10 +8,11 @@ import expect from '@kbn/expect'; import _ from 'lodash'; +import { FtrProviderContext } from '../../ftr_provider_context'; -export default function ({ getService }) { +export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - const es = getService('legacyEs'); + const es = getService('es'); const esArchiver = getService('esArchiver'); describe('bulkUpdate', () => { @@ -234,10 +235,7 @@ export default function ({ getService }) { before( async () => // just in case the kibana server has recreated it - await es.indices.delete({ - index: '.kibana', - ignore: [404], - }) + await es.indices.delete({ index: '.kibana' }, { ignore: [404] }) ); it('should return generic 404', async () => { diff --git a/test/api_integration/apis/saved_objects/create.js b/test/api_integration/apis/saved_objects/create.ts similarity index 90% rename from test/api_integration/apis/saved_objects/create.js rename to test/api_integration/apis/saved_objects/create.ts index 06e3b68121a26..b1cd5a8dfdae4 100644 --- a/test/api_integration/apis/saved_objects/create.js +++ b/test/api_integration/apis/saved_objects/create.ts @@ -7,10 +7,11 @@ */ import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../ftr_provider_context'; -export default function ({ getService }) { +export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - const es = getService('legacyEs'); + const es = getService('es'); const esArchiver = getService('esArchiver'); describe('create', () => { @@ -58,10 +59,7 @@ export default function ({ getService }) { before( async () => // just in case the kibana server has recreated it - await es.indices.delete({ - index: '.kibana', - ignore: [404], - }) + await es.indices.delete({ index: '.kibana' }, { ignore: [404] }) ); it('should return 200 and create kibana index', async () => { @@ -99,7 +97,7 @@ export default function ({ getService }) { expect(resp.body.migrationVersion).to.be.ok(); }); - expect(await es.indices.exists({ index: '.kibana' })).to.be(true); + expect((await es.indices.exists({ index: '.kibana' })).body).to.be(true); }); }); }); diff --git a/test/api_integration/apis/saved_objects/delete.js b/test/api_integration/apis/saved_objects/delete.ts similarity index 89% rename from test/api_integration/apis/saved_objects/delete.js rename to test/api_integration/apis/saved_objects/delete.ts index f78080dc62b30..9ba51b4b91468 100644 --- a/test/api_integration/apis/saved_objects/delete.js +++ b/test/api_integration/apis/saved_objects/delete.ts @@ -7,10 +7,11 @@ */ import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../ftr_provider_context'; -export default function ({ getService }) { +export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - const es = getService('legacyEs'); + const es = getService('es'); const esArchiver = getService('esArchiver'); describe('delete', () => { @@ -43,10 +44,7 @@ export default function ({ getService }) { before( async () => // just in case the kibana server has recreated it - await es.indices.delete({ - index: '.kibana', - ignore: [404], - }) + await es.indices.delete({ index: '.kibana' }, { ignore: [404] }) ); it('returns generic 404 when kibana index is missing', async () => diff --git a/test/api_integration/apis/saved_objects/export.ts b/test/api_integration/apis/saved_objects/export.ts index 59847906e6165..a84f3050fdd17 100644 --- a/test/api_integration/apis/saved_objects/export.ts +++ b/test/api_integration/apis/saved_objects/export.ts @@ -14,7 +14,7 @@ function ndjsonToObject(input: string) { } export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - const es = getService('legacyEs'); + const es = getService('es'); const esArchiver = getService('esArchiver'); describe('export', () => { @@ -524,10 +524,7 @@ export default function ({ getService }: FtrProviderContext) { before( async () => // just in case the kibana server has recreated it - await es.indices.delete({ - index: '.kibana', - ignore: [404], - }) + await es.indices.delete({ index: '.kibana' }, { ignore: [404] }) ); it('should return empty response', async () => { diff --git a/test/api_integration/apis/saved_objects/find.js b/test/api_integration/apis/saved_objects/find.ts similarity index 92% rename from test/api_integration/apis/saved_objects/find.js rename to test/api_integration/apis/saved_objects/find.ts index a6dc1645dfbc9..23f988820c921 100644 --- a/test/api_integration/apis/saved_objects/find.js +++ b/test/api_integration/apis/saved_objects/find.ts @@ -7,10 +7,12 @@ */ import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../ftr_provider_context'; +import { SavedObject } from '../../../../src/core/server'; -export default function ({ getService }) { +export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - const es = getService('legacyEs'); + const es = getService('es'); const esArchiver = getService('esArchiver'); describe('find', () => { @@ -256,6 +258,7 @@ export default function ({ getService }) { ) .expect(400) .then((resp) => { + // eslint-disable-next-line no-console console.log('body', JSON.stringify(resp.body)); expect(resp.body).to.eql({ error: 'Bad Request', @@ -271,6 +274,7 @@ export default function ({ getService }) { ) .expect(400) .then((resp) => { + // eslint-disable-next-line no-console console.log('body', JSON.stringify(resp.body)); expect(resp.body).to.eql({ error: 'Bad Request', @@ -297,7 +301,10 @@ export default function ({ getService }) { .expect(200) .then((resp) => { const objects = resp.body.saved_objects; - expect(objects.map((obj) => obj.id)).to.eql(['only-ref-1', 'ref-1-and-ref-2']); + expect(objects.map((obj: SavedObject) => obj.id)).to.eql([ + 'only-ref-1', + 'ref-1-and-ref-2', + ]); }); }); @@ -315,7 +322,7 @@ export default function ({ getService }) { .expect(200) .then((resp) => { const objects = resp.body.saved_objects; - expect(objects.map((obj) => obj.id)).to.eql([ + expect(objects.map((obj: SavedObject) => obj.id)).to.eql([ 'only-ref-1', 'ref-1-and-ref-2', 'only-ref-2', @@ -337,7 +344,7 @@ export default function ({ getService }) { .expect(200) .then((resp) => { const objects = resp.body.saved_objects; - expect(objects.map((obj) => obj.id)).to.eql(['ref-1-and-ref-2']); + expect(objects.map((obj: SavedObject) => obj.id)).to.eql(['ref-1-and-ref-2']); }); }); }); @@ -358,7 +365,9 @@ export default function ({ getService }) { .expect(200) .then((resp) => { const savedObjects = resp.body.saved_objects; - expect(savedObjects.map((so) => so.attributes.title)).to.eql(['my-visualization']); + expect( + savedObjects.map((so: SavedObject<{ title: string }>) => so.attributes.title) + ).to.eql(['my-visualization']); })); it('can search with the prefix search character just after a special one', async () => @@ -372,7 +381,9 @@ export default function ({ getService }) { .expect(200) .then((resp) => { const savedObjects = resp.body.saved_objects; - expect(savedObjects.map((so) => so.attributes.title)).to.eql(['my-visualization']); + expect( + savedObjects.map((so: SavedObject<{ title: string }>) => so.attributes.title) + ).to.eql(['my-visualization']); })); it('can search for objects with asterisk', async () => @@ -386,7 +397,9 @@ export default function ({ getService }) { .expect(200) .then((resp) => { const savedObjects = resp.body.saved_objects; - expect(savedObjects.map((so) => so.attributes.title)).to.eql(['some*visualization']); + expect( + savedObjects.map((so: SavedObject<{ title: string }>) => so.attributes.title) + ).to.eql(['some*visualization']); })); it('can still search tokens by prefix', async () => @@ -400,10 +413,9 @@ export default function ({ getService }) { .expect(200) .then((resp) => { const savedObjects = resp.body.saved_objects; - expect(savedObjects.map((so) => so.attributes.title)).to.eql([ - 'my-visualization', - 'some*visualization', - ]); + expect( + savedObjects.map((so: SavedObject<{ title: string }>) => so.attributes.title) + ).to.eql(['my-visualization', 'some*visualization']); })); }); @@ -411,10 +423,7 @@ export default function ({ getService }) { before( async () => // just in case the kibana server has recreated it - await es.indices.delete({ - index: '.kibana', - ignore: [404], - }) + await es.indices.delete({ index: '.kibana' }, { ignore: [404] }) ); it('should return 200 with empty response', async () => @@ -513,6 +522,7 @@ export default function ({ getService }) { ) .expect(400) .then((resp) => { + // eslint-disable-next-line no-console console.log('body', JSON.stringify(resp.body)); expect(resp.body).to.eql({ error: 'Bad Request', diff --git a/test/api_integration/apis/saved_objects/get.js b/test/api_integration/apis/saved_objects/get.ts similarity index 93% rename from test/api_integration/apis/saved_objects/get.js rename to test/api_integration/apis/saved_objects/get.ts index f9c16c41c42f7..7134917122177 100644 --- a/test/api_integration/apis/saved_objects/get.js +++ b/test/api_integration/apis/saved_objects/get.ts @@ -7,10 +7,11 @@ */ import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../ftr_provider_context'; -export default function ({ getService }) { +export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - const es = getService('legacyEs'); + const es = getService('es'); const esArchiver = getService('esArchiver'); describe('get', () => { @@ -69,10 +70,7 @@ export default function ({ getService }) { before( async () => // just in case the kibana server has recreated it - await es.indices.delete({ - index: '.kibana', - ignore: [404], - }) + await es.indices.delete({ index: '.kibana' }, { ignore: [404] }) ); it('should return basic 404 without mentioning index', async () => diff --git a/test/api_integration/apis/saved_objects/index.js b/test/api_integration/apis/saved_objects/index.ts similarity index 88% rename from test/api_integration/apis/saved_objects/index.js rename to test/api_integration/apis/saved_objects/index.ts index 3feb8be0aa7f0..0e07b3c1ed060 100644 --- a/test/api_integration/apis/saved_objects/index.js +++ b/test/api_integration/apis/saved_objects/index.ts @@ -6,7 +6,9 @@ * Public License, v 1. */ -export default function ({ loadTestFile }) { +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { describe('saved_objects', () => { loadTestFile(require.resolve('./bulk_create')); loadTestFile(require.resolve('./bulk_get')); diff --git a/test/api_integration/apis/saved_objects/resolve_import_errors.js b/test/api_integration/apis/saved_objects/resolve_import_errors.ts similarity index 98% rename from test/api_integration/apis/saved_objects/resolve_import_errors.js rename to test/api_integration/apis/saved_objects/resolve_import_errors.ts index eafe350e76ae4..5f3929f26aba6 100644 --- a/test/api_integration/apis/saved_objects/resolve_import_errors.js +++ b/test/api_integration/apis/saved_objects/resolve_import_errors.ts @@ -8,8 +8,9 @@ import expect from '@kbn/expect'; import { join } from 'path'; +import { FtrProviderContext } from '../../ftr_provider_context'; -export default function ({ getService }) { +export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); const esArchiver = getService('esArchiver'); diff --git a/test/api_integration/apis/saved_objects/update.js b/test/api_integration/apis/saved_objects/update.ts similarity index 95% rename from test/api_integration/apis/saved_objects/update.js rename to test/api_integration/apis/saved_objects/update.ts index d7c80431e9860..d5346e82ce98c 100644 --- a/test/api_integration/apis/saved_objects/update.js +++ b/test/api_integration/apis/saved_objects/update.ts @@ -7,10 +7,11 @@ */ import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../ftr_provider_context'; -export default function ({ getService }) { +export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - const es = getService('legacyEs'); + const es = getService('es'); const esArchiver = getService('esArchiver'); describe('update', () => { @@ -120,10 +121,7 @@ export default function ({ getService }) { before( async () => // just in case the kibana server has recreated it - await es.indices.delete({ - index: '.kibana', - ignore: [404], - }) + await es.indices.delete({ index: '.kibana' }, { ignore: [404] }) ); it('should return generic 404', async () => diff --git a/test/api_integration/apis/saved_objects_management/find.ts b/test/api_integration/apis/saved_objects_management/find.ts index 66761e62bda52..d7b486e8ab5cf 100644 --- a/test/api_integration/apis/saved_objects_management/find.ts +++ b/test/api_integration/apis/saved_objects_management/find.ts @@ -11,7 +11,7 @@ import { Response } from 'supertest'; import { FtrProviderContext } from '../../ftr_provider_context'; export default function ({ getService }: FtrProviderContext) { - const es = getService('legacyEs'); + const es = getService('es'); const supertest = getService('supertest'); const esArchiver = getService('esArchiver'); @@ -174,10 +174,7 @@ export default function ({ getService }: FtrProviderContext) { before( async () => // just in case the kibana server has recreated it - await es.indices.delete({ - index: '.kibana', - ignore: [404], - }) + await es.indices.delete({ index: '.kibana' }, { ignore: [404] }) ); it('should return 200 with empty response', async () => diff --git a/test/api_integration/apis/saved_objects_management/get.ts b/test/api_integration/apis/saved_objects_management/get.ts index 456711f06a1d7..bc05d7e392bb9 100644 --- a/test/api_integration/apis/saved_objects_management/get.ts +++ b/test/api_integration/apis/saved_objects_management/get.ts @@ -11,7 +11,7 @@ import { Response } from 'supertest'; import { FtrProviderContext } from '../../ftr_provider_context'; export default function ({ getService }: FtrProviderContext) { - const es = getService('legacyEs'); + const es = getService('es'); const supertest = getService('supertest'); const esArchiver = getService('esArchiver'); @@ -45,10 +45,7 @@ export default function ({ getService }: FtrProviderContext) { before( async () => // just in case the kibana server has recreated it - await es.indices.delete({ - index: '.kibana', - ignore: [404], - }) + await es.indices.delete({ index: '.kibana' }, { ignore: [404] }) ); it('should return 404 for object that no longer exists', async () => diff --git a/test/api_integration/apis/telemetry/__fixtures__/ui_counters.js b/test/api_integration/apis/telemetry/__fixtures__/ui_counters.ts similarity index 100% rename from test/api_integration/apis/telemetry/__fixtures__/ui_counters.js rename to test/api_integration/apis/telemetry/__fixtures__/ui_counters.ts diff --git a/test/api_integration/apis/telemetry/telemetry_local.js b/test/api_integration/apis/telemetry/telemetry_local.ts similarity index 93% rename from test/api_integration/apis/telemetry/telemetry_local.js rename to test/api_integration/apis/telemetry/telemetry_local.ts index beba2e211b04c..52a779a3bb453 100644 --- a/test/api_integration/apis/telemetry/telemetry_local.js +++ b/test/api_integration/apis/telemetry/telemetry_local.ts @@ -9,22 +9,27 @@ import expect from '@kbn/expect'; import _ from 'lodash'; import { basicUiCounters } from './__fixtures__/ui_counters'; +import { FtrProviderContext } from '../../ftr_provider_context'; +import { SavedObject } from '../../../../src/core/server'; /* * Create a single-level array with strings for all the paths to values in the * source object, up to 3 deep. Going deeper than 3 causes a bit too much churn * in the tests. */ -function flatKeys(source) { - const recursivelyFlatKeys = (obj, path = [], depth = 0) => { +function flatKeys(source: any) { + const recursivelyFlatKeys = (obj: any, path: string[] = [], depth = 0): string[] => { return depth < 3 && _.isObject(obj) - ? _.map(obj, (v, k) => recursivelyFlatKeys(v, [...path, k], depth + 1)) - : path.join('.'); + ? Object.entries(obj).reduce( + (acc, [k, v]) => [...acc, ...recursivelyFlatKeys(v, [...path, k], depth + 1)], + [] as string[] + ) + : [path.join('.')]; }; return _.uniq(_.flattenDeep(recursivelyFlatKeys(source))).sort((a, b) => a.localeCompare(b)); } -export default function ({ getService }) { +export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); const es = getService('es'); const esArchiver = getService('esArchiver'); @@ -52,7 +57,7 @@ export default function ({ getService }) { const stats = body[0]; expect(stats.collection).to.be('local'); expect(stats.collectionSource).to.be('local'); - expect(stats.license).to.be.undefined; // OSS cannot get the license + expect(stats.license).to.be(undefined); // OSS cannot get the license expect(stats.stack_stats.kibana.count).to.be.a('number'); expect(stats.stack_stats.kibana.indices).to.be.a('number'); expect(stats.stack_stats.kibana.os.platforms[0].platform).to.be.a('string'); @@ -153,7 +158,7 @@ export default function ({ getService }) { }); describe('application usage limits', () => { - function createSavedObject(viewId) { + function createSavedObject(viewId?: string) { return supertest .post('/api/saved_objects/application_usage_transactional') .send({ @@ -170,7 +175,7 @@ export default function ({ getService }) { } describe('basic behaviour', () => { - let savedObjectIds = []; + let savedObjectIds: string[] = []; before('create application usage entries', async () => { savedObjectIds = await Promise.all([ createSavedObject(), @@ -245,7 +250,9 @@ export default function ({ getService }) { })) ) .expect(200) - .then((resp) => resp.body.saved_objects.forEach(({ id }) => savedObjectIds.push(id))); + .then((resp) => + resp.body.saved_objects.forEach(({ id }: SavedObject) => savedObjectIds.push(id)) + ); }); after('clean them all', async () => { // The SavedObjects API does not allow bulk deleting, and deleting one by one takes ages and the tests timeout diff --git a/test/api_integration/apis/telemetry/telemetry_optin_notice_seen.ts b/test/api_integration/apis/telemetry/telemetry_optin_notice_seen.ts index a3f24ab80389c..dd1aee560af86 100644 --- a/test/api_integration/apis/telemetry/telemetry_optin_notice_seen.ts +++ b/test/api_integration/apis/telemetry/telemetry_optin_notice_seen.ts @@ -7,37 +7,32 @@ */ import expect from '@kbn/expect'; -import { Client, DeleteDocumentParams, GetParams, GetResponse } from 'elasticsearch'; -import { TelemetrySavedObjectAttributes } from 'src/plugins/telemetry/server/telemetry_repository'; import { FtrProviderContext } from '../../ftr_provider_context'; export default function optInTest({ getService }: FtrProviderContext) { - const client: Client = getService('legacyEs'); + const client = getService('es'); const supertest = getService('supertest'); describe('/api/telemetry/v2/userHasSeenNotice API Telemetry User has seen OptIn Notice', () => { it('should update telemetry setting field via PUT', async () => { - try { - await client.delete({ + await client.delete( + { index: '.kibana', id: 'telemetry:telemetry', - } as DeleteDocumentParams); - } catch (err) { - if (err.statusCode !== 404) { - throw err; - } - } + }, + { ignore: [404] } + ); await supertest.put('/api/telemetry/v2/userHasSeenNotice').set('kbn-xsrf', 'xxx').expect(200); const { - _source: { telemetry }, - }: GetResponse<{ - telemetry: TelemetrySavedObjectAttributes; - }> = await client.get({ + body: { + _source: { telemetry }, + }, + } = await client.get({ index: '.kibana', id: 'telemetry:telemetry', - } as GetParams); + }); expect(telemetry.userHasSeenNotice).to.be(true); }); diff --git a/test/api_integration/apis/ui_counters/index.js b/test/api_integration/apis/ui_counters/index.ts similarity index 77% rename from test/api_integration/apis/ui_counters/index.js rename to test/api_integration/apis/ui_counters/index.ts index f01855223264d..7944b38802d93 100644 --- a/test/api_integration/apis/ui_counters/index.js +++ b/test/api_integration/apis/ui_counters/index.ts @@ -6,7 +6,9 @@ * Public License, v 1. */ -export default function ({ loadTestFile }) { +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { describe('UI Counters', () => { loadTestFile(require.resolve('./ui_counters')); }); diff --git a/test/api_integration/apis/ui_counters/ui_counters.js b/test/api_integration/apis/ui_counters/ui_counters.ts similarity index 71% rename from test/api_integration/apis/ui_counters/ui_counters.js rename to test/api_integration/apis/ui_counters/ui_counters.ts index d84db0275349a..1cf16fe433bf9 100644 --- a/test/api_integration/apis/ui_counters/ui_counters.js +++ b/test/api_integration/apis/ui_counters/ui_counters.ts @@ -7,14 +7,15 @@ */ import expect from '@kbn/expect'; -import { ReportManager, METRIC_TYPE } from '@kbn/analytics'; +import { ReportManager, METRIC_TYPE, UiCounterMetricType } from '@kbn/analytics'; import moment from 'moment'; +import { FtrProviderContext } from '../../ftr_provider_context'; -export default function ({ getService }) { +export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - const es = getService('legacyEs'); + const es = getService('es'); - const createUiCounterEvent = (eventName, type, count = 1) => ({ + const createUiCounterEvent = (eventName: string, type: UiCounterMetricType, count = 1) => ({ eventName, appName: 'myApp', type, @@ -38,9 +39,9 @@ export default function ({ getService }) { .send({ report }) .expect(200); - const response = await es.search({ index: '.kibana', q: 'type:ui-counter' }); + const { body: response } = await es.search({ index: '.kibana', q: 'type:ui-counter' }); - const ids = response.hits.hits.map(({ _id }) => _id); + const ids = response.hits.hits.map(({ _id }: { _id: string }) => _id); expect(ids.includes(`ui-counter:myApp:${dayDate}:${METRIC_TYPE.COUNT}:my_event`)).to.eql( true ); @@ -64,21 +65,26 @@ export default function ({ getService }) { .expect(200); const { - hits: { hits }, + body: { + hits: { hits }, + }, } = await es.search({ index: '.kibana', q: 'type:ui-counter' }); const countTypeEvent = hits.find( - (hit) => hit._id === `ui-counter:myApp:${dayDate}:${METRIC_TYPE.COUNT}:${uniqueEventName}` + (hit: { _id: string }) => + hit._id === `ui-counter:myApp:${dayDate}:${METRIC_TYPE.COUNT}:${uniqueEventName}` ); expect(countTypeEvent._source['ui-counter'].count).to.eql(1); const clickTypeEvent = hits.find( - (hit) => hit._id === `ui-counter:myApp:${dayDate}:${METRIC_TYPE.CLICK}:${uniqueEventName}` + (hit: { _id: string }) => + hit._id === `ui-counter:myApp:${dayDate}:${METRIC_TYPE.CLICK}:${uniqueEventName}` ); expect(clickTypeEvent._source['ui-counter'].count).to.eql(2); const secondEvent = hits.find( - (hit) => hit._id === `ui-counter:myApp:${dayDate}:${METRIC_TYPE.COUNT}:${uniqueEventName}_2` + (hit: { _id: string }) => + hit._id === `ui-counter:myApp:${dayDate}:${METRIC_TYPE.COUNT}:${uniqueEventName}_2` ); expect(secondEvent._source['ui-counter'].count).to.eql(1); }); diff --git a/test/api_integration/apis/ui_metric/index.js b/test/api_integration/apis/ui_metric/index.ts similarity index 76% rename from test/api_integration/apis/ui_metric/index.js rename to test/api_integration/apis/ui_metric/index.ts index 1cee9c395eb91..2b749f8a01196 100644 --- a/test/api_integration/apis/ui_metric/index.js +++ b/test/api_integration/apis/ui_metric/index.ts @@ -6,7 +6,9 @@ * Public License, v 1. */ -export default function ({ loadTestFile }) { +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { describe('UI Metric', () => { loadTestFile(require.resolve('./ui_metric')); }); diff --git a/test/api_integration/apis/ui_metric/ui_metric.js b/test/api_integration/apis/ui_metric/ui_metric.ts similarity index 74% rename from test/api_integration/apis/ui_metric/ui_metric.js rename to test/api_integration/apis/ui_metric/ui_metric.ts index 0539bb25b1fd9..d330cb037d1a1 100644 --- a/test/api_integration/apis/ui_metric/ui_metric.js +++ b/test/api_integration/apis/ui_metric/ui_metric.ts @@ -7,20 +7,26 @@ */ import expect from '@kbn/expect'; -import { ReportManager, METRIC_TYPE } from '@kbn/analytics'; +import { ReportManager, METRIC_TYPE, UiCounterMetricType } from '@kbn/analytics'; +import { UserAgentMetric } from '@kbn/analytics/target/types/metrics/user_agent'; +import { FtrProviderContext } from '../../ftr_provider_context'; -export default function ({ getService }) { +export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - const es = getService('legacyEs'); + const es = getService('es'); - const createStatsMetric = (eventName, type = METRIC_TYPE.CLICK, count = 1) => ({ + const createStatsMetric = ( + eventName: string, + type: UiCounterMetricType = METRIC_TYPE.CLICK, + count = 1 + ) => ({ eventName, appName: 'myApp', type, count, }); - const createUserAgentMetric = (appName) => ({ + const createUserAgentMetric = (appName: string): UserAgentMetric => ({ appName, type: METRIC_TYPE.USER_AGENT, userAgent: @@ -39,8 +45,8 @@ export default function ({ getService }) { .send({ report }) .expect(200); - const response = await es.search({ index: '.kibana', q: 'type:ui-metric' }); - const ids = response.hits.hits.map(({ _id }) => _id); + const { body: response } = await es.search({ index: '.kibana', q: 'type:ui-metric' }); + const ids = response.hits.hits.map(({ _id }: { _id: string }) => _id); expect(ids.includes('ui-metric:myApp:myEvent')).to.eql(true); }); @@ -64,8 +70,8 @@ export default function ({ getService }) { .send({ report }) .expect(200); - const response = await es.search({ index: '.kibana', q: 'type:ui-metric' }); - const ids = response.hits.hits.map(({ _id }) => _id); + const { body: response } = await es.search({ index: '.kibana', q: 'type:ui-metric' }); + const ids = response.hits.hits.map(({ _id }: { _id: string }) => _id); expect(ids.includes('ui-metric:myApp:myEvent')).to.eql(true); expect(ids.includes(`ui-metric:myApp:${uniqueEventName}`)).to.eql(true); expect(ids.includes(`ui-metric:kibana-user_agent:${userAgentMetric.userAgent}`)).to.eql(true); @@ -77,7 +83,6 @@ export default function ({ getService }) { const nano = hrTime[0] * 1000000000 + hrTime[1]; const uniqueEventName = `my_event_${nano}`; const { report } = reportManager.assignReports([ - , createStatsMetric(uniqueEventName, METRIC_TYPE.CLICK, 2), createStatsMetric(uniqueEventName, METRIC_TYPE.LOADED), ]); @@ -89,10 +94,14 @@ export default function ({ getService }) { .expect(200); const { - hits: { hits }, + body: { + hits: { hits }, + }, } = await es.search({ index: '.kibana', q: 'type:ui-metric' }); - const countTypeEvent = hits.find((hit) => hit._id === `ui-metric:myApp:${uniqueEventName}`); + const countTypeEvent = hits.find( + (hit: { _id: string }) => hit._id === `ui-metric:myApp:${uniqueEventName}` + ); expect(countTypeEvent._source['ui-metric'].count).to.eql(3); }); }); diff --git a/x-pack/test/api_integration/apis/telemetry/telemetry_optin_notice_seen.ts b/x-pack/test/api_integration/apis/telemetry/telemetry_optin_notice_seen.ts index 4821eea095d88..6c1a9f0be2461 100644 --- a/x-pack/test/api_integration/apis/telemetry/telemetry_optin_notice_seen.ts +++ b/x-pack/test/api_integration/apis/telemetry/telemetry_optin_notice_seen.ts @@ -5,37 +5,32 @@ */ import expect from '@kbn/expect'; -import { Client, DeleteDocumentParams, GetParams, GetResponse } from 'elasticsearch'; -import { TelemetrySavedObjectAttributes } from '../../../../../src/plugins/telemetry/server/telemetry_repository'; import { FtrProviderContext } from '../../ftr_provider_context'; export default function optInTest({ getService }: FtrProviderContext) { - const client: Client = getService('legacyEs'); + const client = getService('es'); const supertest = getService('supertest'); describe('/api/telemetry/v2/userHasSeenNotice API Telemetry User has seen OptIn Notice', () => { it('should update telemetry setting field via PUT', async () => { - try { - await client.delete({ + await client.delete( + { index: '.kibana', id: 'telemetry:telemetry', - } as DeleteDocumentParams); - } catch (err) { - if (err.statusCode !== 404) { - throw err; - } - } + }, + { ignore: [404] } + ); await supertest.put('/api/telemetry/v2/userHasSeenNotice').set('kbn-xsrf', 'xxx').expect(200); const { - _source: { telemetry }, - }: GetResponse<{ - telemetry: TelemetrySavedObjectAttributes; - }> = await client.get({ + body: { + _source: { telemetry }, + }, + } = await client.get({ index: '.kibana', id: 'telemetry:telemetry', - } as GetParams); + }); expect(telemetry.userHasSeenNotice).to.be(true); }); From a4d50c27394eefa43a429e1ba63183a2cad06238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Wed, 20 Jan 2021 12:26:56 +0100 Subject: [PATCH 2/3] Remove `any` --- test/api_integration/apis/telemetry/telemetry_local.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/api_integration/apis/telemetry/telemetry_local.ts b/test/api_integration/apis/telemetry/telemetry_local.ts index 52a779a3bb453..25d29a807bdad 100644 --- a/test/api_integration/apis/telemetry/telemetry_local.ts +++ b/test/api_integration/apis/telemetry/telemetry_local.ts @@ -16,8 +16,8 @@ import { SavedObject } from '../../../../src/core/server'; * source object, up to 3 deep. Going deeper than 3 causes a bit too much churn * in the tests. */ -function flatKeys(source: any) { - const recursivelyFlatKeys = (obj: any, path: string[] = [], depth = 0): string[] => { +function flatKeys(source: Record) { + const recursivelyFlatKeys = (obj: unknown, path: string[] = [], depth = 0): string[] => { return depth < 3 && _.isObject(obj) ? Object.entries(obj).reduce( (acc, [k, v]) => [...acc, ...recursivelyFlatKeys(v, [...path, k], depth + 1)], From 085df7138152fe471b487f1955348a88ab8900e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Wed, 20 Jan 2021 14:07:25 +0100 Subject: [PATCH 3/3] Remove console.log --- test/api_integration/apis/saved_objects/find.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/api_integration/apis/saved_objects/find.ts b/test/api_integration/apis/saved_objects/find.ts index 23f988820c921..a3ce70888049c 100644 --- a/test/api_integration/apis/saved_objects/find.ts +++ b/test/api_integration/apis/saved_objects/find.ts @@ -258,8 +258,6 @@ export default function ({ getService }: FtrProviderContext) { ) .expect(400) .then((resp) => { - // eslint-disable-next-line no-console - console.log('body', JSON.stringify(resp.body)); expect(resp.body).to.eql({ error: 'Bad Request', message: 'This type dashboard is not allowed: Bad Request', @@ -274,8 +272,6 @@ export default function ({ getService }: FtrProviderContext) { ) .expect(400) .then((resp) => { - // eslint-disable-next-line no-console - console.log('body', JSON.stringify(resp.body)); expect(resp.body).to.eql({ error: 'Bad Request', message: @@ -522,8 +518,6 @@ export default function ({ getService }: FtrProviderContext) { ) .expect(400) .then((resp) => { - // eslint-disable-next-line no-console - console.log('body', JSON.stringify(resp.body)); expect(resp.body).to.eql({ error: 'Bad Request', message: 'This type dashboard is not allowed: Bad Request',