[7.x] [FTR] Use new ES client instead of legacyEs service (#88720) (#88845)

This commit is contained in:
Alejandro Fernández Haro 2021-01-20 17:48:30 +00:00 committed by GitHub
parent 00995045be
commit ee5b6d22a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 165 additions and 158 deletions

View file

@ -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'));
});

View file

@ -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);

View file

@ -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'));

View file

@ -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'));
});

View file

@ -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);
});

View file

@ -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 () =>

View file

@ -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 () =>

View file

@ -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 () => {

View file

@ -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);
});
});
});

View file

@ -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 () =>

View file

@ -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 () => {

View file

@ -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,7 +258,6 @@ export default function ({ getService }) {
)
.expect(400)
.then((resp) => {
console.log('body', JSON.stringify(resp.body));
expect(resp.body).to.eql({
error: 'Bad Request',
message: 'This type dashboard is not allowed: Bad Request',
@ -271,7 +272,6 @@ export default function ({ getService }) {
)
.expect(400)
.then((resp) => {
console.log('body', JSON.stringify(resp.body));
expect(resp.body).to.eql({
error: 'Bad Request',
message:
@ -297,7 +297,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 +318,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 +340,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 +361,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 +377,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 +393,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 +409,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 +419,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,7 +518,6 @@ export default function ({ getService }) {
)
.expect(400)
.then((resp) => {
console.log('body', JSON.stringify(resp.body));
expect(resp.body).to.eql({
error: 'Bad Request',
message: 'This type dashboard is not allowed: Bad Request',

View file

@ -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 () =>

View file

@ -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'));

View file

@ -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');

View file

@ -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 () =>

View file

@ -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 () =>

View file

@ -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 () =>

View file

@ -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: Record<string, unknown>) {
const recursivelyFlatKeys = (obj: unknown, 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

View file

@ -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);
});

View file

@ -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'));
});

View file

@ -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,
@ -39,9 +40,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
);
@ -65,21 +66,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);
});

View file

@ -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'));
});

View file

@ -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);
});
});

View file

@ -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);
});