Skip to content

Commit

Permalink
Improve type usages
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry350 committed Feb 18, 2020
1 parent e437cd3 commit 5a5813a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
3 changes: 1 addition & 2 deletions x-pack/plugins/infra/server/lib/snapshot/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
*/

import { JsonObject } from '../../../common/typed_json';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { InfraSourceConfiguration } from '../../../public/graphql/types';
import { InfraSourceConfiguration } from '../../../common/graphql/types';
import { SnapshotRequest } from '../../../common/http_api/snapshot_api';

export interface InfraSnapshotRequestOptions
Expand Down
39 changes: 12 additions & 27 deletions x-pack/test/api_integration/apis/infra/metrics_explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { first } from 'lodash';
import moment from 'moment';
import { DATES } from './constants';
import { FtrProviderContext } from '../../ftr_provider_context';
import { metricsExplorerResponseRT } from '../../../../plugins/infra/common/http_api/metrics_explorer';
import { decodeOrThrow } from '../../../../plugins/infra/common/runtime_types';

const { min, max } = DATES['7.0.0'].hosts;

Expand Down Expand Up @@ -47,13 +49,10 @@ export default function({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'xxx')
.send(postBody)
.expect(200);
const body = response.body;
expect(body).to.have.property('series');
const body = decodeOrThrow(metricsExplorerResponseRT)(response.body);
expect(body.series).length(1);
const firstSeries = first(body.series) as Record<string, any>;
const firstSeries = first(body.series);
expect(firstSeries).to.have.property('id', 'ALL');
expect(firstSeries).to.have.property('columns');
expect(firstSeries).to.have.property('rows');
expect(firstSeries.columns).to.eql([
{ name: 'timestamp', type: 'date' },
{ name: 'metric_0', type: 'number' },
Expand Down Expand Up @@ -91,13 +90,10 @@ export default function({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'xxx')
.send(postBody)
.expect(200);
const body = response.body;
expect(body).to.have.property('series');
const body = decodeOrThrow(metricsExplorerResponseRT)(response.body);
expect(body.series).length(1);
const firstSeries = first(body.series) as Record<string, any>;
const firstSeries = first(body.series);
expect(firstSeries).to.have.property('id', 'ALL');
expect(firstSeries).to.have.property('columns');
expect(firstSeries).to.have.property('rows');
expect(firstSeries.columns).to.eql([
{ name: 'timestamp', type: 'date' },
{ name: 'metric_0', type: 'number' },
Expand Down Expand Up @@ -125,13 +121,10 @@ export default function({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'xxx')
.send(postBody)
.expect(200);
const body = response.body;
expect(body).to.have.property('series');
const body = decodeOrThrow(metricsExplorerResponseRT)(response.body);
expect(body.series).length(1);
const firstSeries = first(body.series) as Record<string, any>;
const firstSeries = first(body.series);
expect(firstSeries).to.have.property('id', 'ALL');
expect(firstSeries).to.have.property('columns');
expect(firstSeries).to.have.property('rows');
expect(firstSeries.columns).to.eql([]);
expect(firstSeries.rows).to.have.length(0);
});
Expand Down Expand Up @@ -160,13 +153,10 @@ export default function({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'xxx')
.send(postBody)
.expect(200);
const body = response.body;
expect(body).to.have.property('series');
const body = decodeOrThrow(metricsExplorerResponseRT)(response.body);
expect(body.series).length(3);
const firstSeries = first(body.series) as Record<string, any>;
const firstSeries = first(body.series);
expect(firstSeries).to.have.property('id', 'system.diskio');
expect(firstSeries).to.have.property('columns');
expect(firstSeries).to.have.property('rows');
expect(firstSeries.columns).to.eql([
{ name: 'timestamp', type: 'date' },
{ name: 'metric_0', type: 'number' },
Expand All @@ -178,7 +168,6 @@ export default function({ getService }: FtrProviderContext) {
metric_0: 24,
timestamp: 1547571300000,
});
expect(body).to.have.property('pageInfo');
expect(body.pageInfo).to.eql({
afterKey: 'system.fsstat',
total: 12,
Expand Down Expand Up @@ -211,12 +200,10 @@ export default function({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'xxx')
.send(postBody)
.expect(200);
const body = response.body;
expect(body).to.have.property('series');
const body = decodeOrThrow(metricsExplorerResponseRT)(response.body);
expect(body.series).length(1);
expect(body.series[0]!).to.have.property('rows');
expect(body.series[0]!.rows).length(0);
expect(body).to.have.property('pageInfo');
expect(body.pageInfo).to.eql({
afterKey: null,
total: 0,
Expand Down Expand Up @@ -247,10 +234,8 @@ export default function({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'xxx')
.send(postBody)
.expect(200);
const body = response.body;
expect(body).to.have.property('series');
const body = decodeOrThrow(metricsExplorerResponseRT)(response.body);
expect(body.series).length(0);
expect(body).to.have.property('pageInfo');
expect(body.pageInfo).to.eql({
afterKey: null,
total: 0,
Expand Down

0 comments on commit 5a5813a

Please sign in to comment.