Skip to content

Commit

Permalink
Move literal value checks to (inline) snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
dgieselaar committed Sep 12, 2020
1 parent 129780e commit 4be2387
Show file tree
Hide file tree
Showing 30 changed files with 10,330 additions and 12,262 deletions.
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,20 @@ 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 4be2387

Please sign in to comment.