Skip to content

Commit

Permalink
t push originMerge branch 'master' of github.com:elastic/kibana into …
Browse files Browse the repository at this point in the history
…telemetry/update_lodash_to_4_x
  • Loading branch information
Bamieh committed Sep 14, 2020
2 parents 95684b1 + aed9932 commit 8202fb6
Show file tree
Hide file tree
Showing 34 changed files with 10,567 additions and 12,265 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ describe('docTable', function () {
expect(getSort([['foo', 'bar']], indexPattern)).toEqual([]);
expect(getSort([{ foo: 'bar' }], indexPattern)).toEqual([]);
});

test('should convert a legacy sort to an array of objects', function () {
expect(getSort(['foo', 'desc'], indexPattern)).toEqual([{ foo: 'desc' }]);
expect(getSort(['foo', 'asc'], indexPattern)).toEqual([{ foo: 'asc' }]);
});
});

describe('getSortArray function', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,25 @@ function createSortObject(
}
}

export function isLegacySort(sort: SortPair[] | SortPair): sort is SortPair {
return (
sort.length === 2 && typeof sort[0] === 'string' && (sort[1] === 'desc' || sort[1] === 'asc')
);
}

/**
* Take a sorting array and make it into an object
* @param {array} sort two dimensional array [[fieldToSort, directionToSort]]
* or an array of objects [{fieldToSort: directionToSort}]
* @param {object} indexPattern used for determining default sort
* @returns Array<{object}> an array of sort objects
*/
export function getSort(sort: SortPair[], indexPattern: IndexPattern): SortPairObj[] {
export function getSort(sort: SortPair[] | SortPair, indexPattern: IndexPattern): SortPairObj[] {
if (Array.isArray(sort)) {
if (isLegacySort(sort)) {
// To stay compatible with legacy sort, which just supported a single sort field
return [{ [sort[0]]: sort[1] }];
}
return sort
.map((sortPair: SortPair) => createSortObject(sortPair, indexPattern))
.filter((sortPairObj) => typeof sortPairObj === 'object') as SortPairObj[];
Expand Down
3 changes: 3 additions & 0 deletions x-pack/test/apm_api_integration/basic/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { FtrProviderContext } from '../../common/ftr_provider_context';
import { registerMochaHooksForSnapshots } from '../../common/match_snapshot';

export default function apmApiIntegrationTests({ loadTestFile }: FtrProviderContext) {
describe('APM specs (basic)', function () {
registerMochaHooksForSnapshots();

this.tags('ciGroup1');

loadTestFile(require.resolve('./feature_controls'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import expect from '@kbn/expect';
import { expectSnapshot } from '../../../common/match_snapshot';
import { FtrProviderContext } from '../../../common/ftr_provider_context';

export default function ApiTest({ getService }: FtrProviderContext) {
Expand All @@ -22,7 +23,12 @@ export default function ApiTest({ getService }: FtrProviderContext) {
`/api/apm/observability_overview?start=${start}&end=${end}&bucketSize=${bucketSize}`
);
expect(response.status).to.be(200);
expect(response.body).to.eql({ serviceCount: 0, transactionCoordinates: [] });
expectSnapshot(response.body).toMatchInline(`
Object {
"serviceCount": 0,
"transactionCoordinates": Array [],
}
`);
});
});
describe('when data is loaded', () => {
Expand All @@ -34,13 +40,21 @@ export default function ApiTest({ getService }: FtrProviderContext) {
`/api/apm/observability_overview?start=${start}&end=${end}&bucketSize=${bucketSize}`
);
expect(response.status).to.be(200);
expect(response.body).to.eql({
serviceCount: 3,
transactionCoordinates: [
{ x: 1593413220000, y: 0.016666666666666666 },
{ x: 1593413280000, y: 1.0458333333333334 },
],
});
expectSnapshot(response.body).toMatchInline(`
Object {
"serviceCount": 3,
"transactionCoordinates": Array [
Object {
"x": 1593413220000,
"y": 0.016666666666666666,
},
Object {
"x": 1593413280000,
"y": 1.0458333333333334,
},
],
}
`);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { sortBy } from 'lodash';
import expect from '@kbn/expect';
import { expectSnapshot } from '../../../common/match_snapshot';
import { FtrProviderContext } from '../../../common/ftr_provider_context';

export default function ApiTest({ getService }: FtrProviderContext) {
Expand Down Expand Up @@ -41,32 +42,38 @@ export default function ApiTest({ getService }: FtrProviderContext) {
const services = sortBy(response.body.items, ['serviceName']);

expect(response.status).to.be(200);
expect(services).to.eql([
{
serviceName: 'client',
agentName: 'rum-js',
transactionsPerMinute: 2,
errorsPerMinute: 2.75,
avgResponseTime: 116375,
environments: [],
},
{
serviceName: 'opbeans-java',
agentName: 'java',
transactionsPerMinute: 30.75,
errorsPerMinute: 4.5,
avgResponseTime: 25636.349593495936,
environments: ['production'],
},
{
serviceName: 'opbeans-node',
agentName: 'nodejs',
transactionsPerMinute: 31,
errorsPerMinute: 3.75,
avgResponseTime: 38682.52419354839,
environments: ['production'],
},
]);
expectSnapshot(services).toMatchInline(`
Array [
Object {
"agentName": "rum-js",
"avgResponseTime": 116375,
"environments": Array [],
"errorsPerMinute": 2.75,
"serviceName": "client",
"transactionsPerMinute": 2,
},
Object {
"agentName": "java",
"avgResponseTime": 25636.349593495936,
"environments": Array [
"production",
],
"errorsPerMinute": 4.5,
"serviceName": "opbeans-java",
"transactionsPerMinute": 30.75,
},
Object {
"agentName": "nodejs",
"avgResponseTime": 38682.52419354839,
"environments": Array [
"production",
],
"errorsPerMinute": 3.75,
"serviceName": "opbeans-node",
"transactionsPerMinute": 31,
},
]
`);

expect(response.body.hasHistoricalData).to.be(true);
expect(response.body.hasLegacyData).to.be(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import expect from '@kbn/expect';
import { expectSnapshot } from '../../../common/match_snapshot';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

export default function ApiTest({ getService }: FtrProviderContext) {
Expand All @@ -23,7 +24,8 @@ export default function ApiTest({ getService }: FtrProviderContext) {
);

expect(response.status).to.be(200);
expect(response.body).to.eql({ transactionTypes: [] });

expect(response.body.transactionTypes.length).to.be(0);
});
});

Expand All @@ -37,7 +39,14 @@ export default function ApiTest({ getService }: FtrProviderContext) {
);

expect(response.status).to.be(200);
expect(response.body).to.eql({ transactionTypes: ['request', 'Worker'] });
expectSnapshot(response.body).toMatchInline(`
Object {
"transactionTypes": Array [
"request",
"Worker",
],
}
`);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ export default function apiTest({ getService }: FtrProviderContext) {
describe('when calling the endpoint for listing jobs', () => {
it('returns an error because the user does not have access', async () => {
const { body } = await getAnomalyDetectionJobs();
expect(body).to.eql({ statusCode: 404, error: 'Not Found', message: 'Not Found' });

expect(body.statusCode).to.be(404);
expect(body.error).to.be('Not Found');
});
});

describe('when calling create endpoint', () => {
it('returns an error because the user does not have access', async () => {
const { body } = await createAnomalyDetectionJobs(['production', 'staging']);
expect(body).to.eql({ statusCode: 404, error: 'Not Found', message: 'Not Found' });

expect(body.statusCode).to.be(404);
expect(body.error).to.be('Not Found');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import expect from '@kbn/expect';
import { expectSnapshot } from '../../../../common/match_snapshot';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

export default function apiTest({ getService }: FtrProviderContext) {
Expand All @@ -25,19 +26,21 @@ export default function apiTest({ getService }: FtrProviderContext) {
describe('when calling the endpoint for listing jobs', () => {
it('returns an error because the user is on basic license', async () => {
const { body } = await getAnomalyDetectionJobs();
expect(body).to.eql({
statusCode: 403,
error: 'Forbidden',
message:
"To use anomaly detection, you must be subscribed to an Elastic Platinum license. With it, you'll be able to monitor your services with the aid of machine learning.",
});

expect(body.statusCode).to.be(403);
expect(body.error).to.be('Forbidden');

expectSnapshot(body.message).toMatchInline(
`"To use anomaly detection, you must be subscribed to an Elastic Platinum license. With it, you'll be able to monitor your services with the aid of machine learning."`
);
});
});

describe('when calling create endpoint', () => {
it('returns an error because the user does not have access', async () => {
const { body } = await createAnomalyDetectionJobs(['production', 'staging']);
expect(body).to.eql({ statusCode: 404, error: 'Not Found', message: 'Not Found' });
expect(body.statusCode).to.be(404);
expect(body.error).to.be('Not Found');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import expect from '@kbn/expect';
import { expectSnapshot } from '../../../../common/match_snapshot';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

export default function apiTest({ getService }: FtrProviderContext) {
Expand All @@ -25,24 +26,25 @@ export default function apiTest({ getService }: FtrProviderContext) {
describe('when calling the endpoint for listing jobs', () => {
it('returns an error because the user is on basic license', async () => {
const { body } = await getAnomalyDetectionJobs();
expect(body).to.eql({
statusCode: 403,
error: 'Forbidden',
message:
"To use anomaly detection, you must be subscribed to an Elastic Platinum license. With it, you'll be able to monitor your services with the aid of machine learning.",
});

expect(body.statusCode).to.be(403);
expect(body.error).to.be('Forbidden');
expectSnapshot(body.message).toMatchInline(
`"To use anomaly detection, you must be subscribed to an Elastic Platinum license. With it, you'll be able to monitor your services with the aid of machine learning."`
);
});
});

describe('when calling create endpoint', () => {
it('returns an error because the user is on basic license', async () => {
const { body } = await createAnomalyDetectionJobs(['production', 'staging']);
expect(body).to.eql({
statusCode: 403,
error: 'Forbidden',
message:
"To use anomaly detection, you must be subscribed to an Elastic Platinum license. With it, you'll be able to monitor your services with the aid of machine learning.",
});

expect(body.statusCode).to.be(403);
expect(body.error).to.be('Forbidden');

expectSnapshot(body.message).toMatchInline(
`"To use anomaly detection, you must be subscribed to an Elastic Platinum license. With it, you'll be able to monitor your services with the aid of machine learning."`
);
});
});
});
Expand Down
Loading

0 comments on commit 8202fb6

Please sign in to comment.