2020-06-25 17:19:38 +02:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
|
|
*/
|
2020-07-16 16:48:12 +02:00
|
|
|
import {
|
|
|
|
registerDataHandler,
|
|
|
|
getDataHandler,
|
|
|
|
unregisterDataHandler,
|
|
|
|
fetchHasData,
|
|
|
|
} from './data_handler';
|
2020-07-14 11:05:48 +02:00
|
|
|
import moment from 'moment';
|
2020-07-16 16:48:12 +02:00
|
|
|
import {
|
|
|
|
ApmFetchDataResponse,
|
|
|
|
LogsFetchDataResponse,
|
|
|
|
MetricsFetchDataResponse,
|
|
|
|
UptimeFetchDataResponse,
|
2020-10-05 19:15:13 +02:00
|
|
|
UxFetchDataResponse,
|
2020-07-16 16:48:12 +02:00
|
|
|
} from './typings';
|
2020-06-25 17:19:38 +02:00
|
|
|
|
|
|
|
const params = {
|
2020-07-14 11:05:48 +02:00
|
|
|
absoluteTime: {
|
|
|
|
start: moment('2020-07-02T13:25:11.629Z').valueOf(),
|
|
|
|
end: moment('2020-07-09T13:25:11.629Z').valueOf(),
|
|
|
|
},
|
|
|
|
relativeTime: {
|
|
|
|
start: 'now-15m',
|
|
|
|
end: 'now',
|
|
|
|
},
|
2020-06-25 17:19:38 +02:00
|
|
|
bucketSize: '10s',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('registerDataHandler', () => {
|
2020-07-16 16:48:12 +02:00
|
|
|
const originalConsole = global.console;
|
|
|
|
beforeAll(() => {
|
|
|
|
// mocks console to avoid poluting the test output
|
|
|
|
global.console = ({ error: jest.fn() } as unknown) as typeof console;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
global.console = originalConsole;
|
|
|
|
});
|
|
|
|
|
2020-06-25 17:19:38 +02:00
|
|
|
describe('APM', () => {
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'apm',
|
|
|
|
fetchData: async () => {
|
|
|
|
return {
|
|
|
|
title: 'apm',
|
|
|
|
appLink: '/apm',
|
|
|
|
stats: {
|
|
|
|
services: {
|
|
|
|
label: 'services',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
transactions: {
|
|
|
|
label: 'transactions',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
series: {
|
|
|
|
transactions: {
|
|
|
|
label: 'transactions',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
hasData: async () => true,
|
|
|
|
});
|
|
|
|
|
|
|
|
it('registered data handler', () => {
|
|
|
|
const dataHandler = getDataHandler('apm');
|
|
|
|
expect(dataHandler?.fetchData).toBeDefined();
|
|
|
|
expect(dataHandler?.hasData).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns data when fetchData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('apm');
|
|
|
|
const response = await dataHandler?.fetchData(params);
|
|
|
|
expect(response).toEqual({
|
|
|
|
title: 'apm',
|
|
|
|
appLink: '/apm',
|
|
|
|
stats: {
|
|
|
|
services: {
|
|
|
|
label: 'services',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
transactions: {
|
|
|
|
label: 'transactions',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
series: {
|
|
|
|
transactions: {
|
|
|
|
label: 'transactions',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true when hasData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('apm');
|
|
|
|
const hasData = await dataHandler?.hasData();
|
|
|
|
expect(hasData).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('Logs', () => {
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'infra_logs',
|
|
|
|
fetchData: async () => {
|
|
|
|
return {
|
|
|
|
title: 'logs',
|
|
|
|
appLink: '/logs',
|
|
|
|
stats: {
|
|
|
|
foo: {
|
|
|
|
label: 'Foo',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
label: 'bar',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
series: {
|
|
|
|
foo: {
|
|
|
|
label: 'Foo',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
label: 'Bar',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
hasData: async () => true,
|
|
|
|
});
|
|
|
|
|
|
|
|
it('registered data handler', () => {
|
|
|
|
const dataHandler = getDataHandler('infra_logs');
|
|
|
|
expect(dataHandler?.fetchData).toBeDefined();
|
|
|
|
expect(dataHandler?.hasData).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns data when fetchData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('infra_logs');
|
|
|
|
const response = await dataHandler?.fetchData(params);
|
|
|
|
expect(response).toEqual({
|
|
|
|
title: 'logs',
|
|
|
|
appLink: '/logs',
|
|
|
|
stats: {
|
|
|
|
foo: {
|
|
|
|
label: 'Foo',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
label: 'bar',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
series: {
|
|
|
|
foo: {
|
|
|
|
label: 'Foo',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
label: 'Bar',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true when hasData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('apm');
|
|
|
|
const hasData = await dataHandler?.hasData();
|
|
|
|
expect(hasData).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('Uptime', () => {
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'uptime',
|
|
|
|
fetchData: async () => {
|
|
|
|
return {
|
|
|
|
title: 'uptime',
|
|
|
|
appLink: '/uptime',
|
|
|
|
stats: {
|
|
|
|
monitors: {
|
|
|
|
label: 'Monitors',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
up: {
|
|
|
|
label: 'Up',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
down: {
|
|
|
|
label: 'Down',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
series: {
|
|
|
|
down: {
|
|
|
|
label: 'Down',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
up: {
|
|
|
|
label: 'Up',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
hasData: async () => true,
|
|
|
|
});
|
|
|
|
|
|
|
|
it('registered data handler', () => {
|
|
|
|
const dataHandler = getDataHandler('uptime');
|
|
|
|
expect(dataHandler?.fetchData).toBeDefined();
|
|
|
|
expect(dataHandler?.hasData).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns data when fetchData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('uptime');
|
|
|
|
const response = await dataHandler?.fetchData(params);
|
|
|
|
expect(response).toEqual({
|
|
|
|
title: 'uptime',
|
|
|
|
appLink: '/uptime',
|
|
|
|
stats: {
|
|
|
|
monitors: {
|
|
|
|
label: 'Monitors',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
up: {
|
|
|
|
label: 'Up',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
down: {
|
|
|
|
label: 'Down',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
series: {
|
|
|
|
down: {
|
|
|
|
label: 'Down',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
up: {
|
|
|
|
label: 'Up',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true when hasData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('apm');
|
|
|
|
const hasData = await dataHandler?.hasData();
|
|
|
|
expect(hasData).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
2020-10-05 19:15:13 +02:00
|
|
|
describe('Ux', () => {
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'ux',
|
|
|
|
fetchData: async () => {
|
|
|
|
return {
|
|
|
|
title: 'User Experience',
|
|
|
|
appLink: '/ux',
|
|
|
|
coreWebVitals: {
|
|
|
|
cls: '0.01',
|
|
|
|
fid: 5,
|
|
|
|
lcp: 1464.3333333333333,
|
|
|
|
tbt: 232.92166666666665,
|
|
|
|
fcp: 1154.8,
|
|
|
|
lcpRanks: [73, 16, 11],
|
|
|
|
fidRanks: [85, 4, 11],
|
|
|
|
clsRanks: [88, 7, 5],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
hasData: async () => ({ hasData: true, serviceName: 'elastic-co-frontend' }),
|
|
|
|
});
|
|
|
|
|
|
|
|
it('registered data handler', () => {
|
|
|
|
const dataHandler = getDataHandler('ux');
|
|
|
|
expect(dataHandler?.fetchData).toBeDefined();
|
|
|
|
expect(dataHandler?.hasData).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns data when fetchData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('ux');
|
|
|
|
const response = await dataHandler?.fetchData(params);
|
|
|
|
expect(response).toEqual({
|
|
|
|
title: 'User Experience',
|
|
|
|
appLink: '/ux',
|
|
|
|
coreWebVitals: {
|
|
|
|
cls: '0.01',
|
|
|
|
fid: 5,
|
|
|
|
lcp: 1464.3333333333333,
|
|
|
|
tbt: 232.92166666666665,
|
|
|
|
fcp: 1154.8,
|
|
|
|
lcpRanks: [73, 16, 11],
|
|
|
|
fidRanks: [85, 4, 11],
|
|
|
|
clsRanks: [88, 7, 5],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true when hasData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('ux');
|
|
|
|
const hasData = await dataHandler?.hasData();
|
|
|
|
expect(hasData).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-25 17:19:38 +02:00
|
|
|
describe('Metrics', () => {
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'infra_metrics',
|
|
|
|
fetchData: async () => {
|
|
|
|
return {
|
|
|
|
title: 'metrics',
|
|
|
|
appLink: '/metrics',
|
|
|
|
stats: {
|
|
|
|
hosts: {
|
|
|
|
label: 'hosts',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
cpu: {
|
|
|
|
label: 'cpu',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
memory: {
|
|
|
|
label: 'memory',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
disk: {
|
|
|
|
label: 'disk',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
inboundTraffic: {
|
|
|
|
label: 'inboundTraffic',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
outboundTraffic: {
|
|
|
|
label: 'outboundTraffic',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
series: {
|
|
|
|
inboundTraffic: {
|
|
|
|
label: 'inbound Traffic',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
outboundTraffic: {
|
|
|
|
label: 'outbound Traffic',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
hasData: async () => true,
|
|
|
|
});
|
|
|
|
|
|
|
|
it('registered data handler', () => {
|
|
|
|
const dataHandler = getDataHandler('infra_metrics');
|
|
|
|
expect(dataHandler?.fetchData).toBeDefined();
|
|
|
|
expect(dataHandler?.hasData).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns data when fetchData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('infra_metrics');
|
|
|
|
const response = await dataHandler?.fetchData(params);
|
|
|
|
expect(response).toEqual({
|
|
|
|
title: 'metrics',
|
|
|
|
appLink: '/metrics',
|
|
|
|
stats: {
|
|
|
|
hosts: {
|
|
|
|
label: 'hosts',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
cpu: {
|
|
|
|
label: 'cpu',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
memory: {
|
|
|
|
label: 'memory',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
disk: {
|
|
|
|
label: 'disk',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
inboundTraffic: {
|
|
|
|
label: 'inboundTraffic',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
outboundTraffic: {
|
|
|
|
label: 'outboundTraffic',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
series: {
|
|
|
|
inboundTraffic: {
|
|
|
|
label: 'inbound Traffic',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
outboundTraffic: {
|
|
|
|
label: 'outbound Traffic',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true when hasData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('apm');
|
|
|
|
const hasData = await dataHandler?.hasData();
|
|
|
|
expect(hasData).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
2020-07-16 16:48:12 +02:00
|
|
|
describe('fetchHasData', () => {
|
|
|
|
it('returns false when an exception happens', async () => {
|
|
|
|
unregisterDataHandler({ appName: 'apm' });
|
|
|
|
unregisterDataHandler({ appName: 'infra_logs' });
|
|
|
|
unregisterDataHandler({ appName: 'infra_metrics' });
|
|
|
|
unregisterDataHandler({ appName: 'uptime' });
|
2020-10-05 19:15:13 +02:00
|
|
|
unregisterDataHandler({ appName: 'ux' });
|
2020-07-16 16:48:12 +02:00
|
|
|
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'apm',
|
|
|
|
fetchData: async () => (({} as unknown) as ApmFetchDataResponse),
|
|
|
|
hasData: async () => {
|
|
|
|
throw new Error('BOOM');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'infra_logs',
|
|
|
|
fetchData: async () => (({} as unknown) as LogsFetchDataResponse),
|
|
|
|
hasData: async () => {
|
|
|
|
throw new Error('BOOM');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'infra_metrics',
|
|
|
|
fetchData: async () => (({} as unknown) as MetricsFetchDataResponse),
|
|
|
|
hasData: async () => {
|
|
|
|
throw new Error('BOOM');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'uptime',
|
|
|
|
fetchData: async () => (({} as unknown) as UptimeFetchDataResponse),
|
|
|
|
hasData: async () => {
|
|
|
|
throw new Error('BOOM');
|
|
|
|
},
|
|
|
|
});
|
2020-10-05 19:15:13 +02:00
|
|
|
registerDataHandler({
|
|
|
|
appName: 'ux',
|
|
|
|
fetchData: async () => (({} as unknown) as UxFetchDataResponse),
|
|
|
|
hasData: async () => {
|
|
|
|
throw new Error('BOOM');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(await fetchHasData({ end: 1601632271769, start: 1601631371769 })).toEqual({
|
2020-07-16 16:48:12 +02:00
|
|
|
apm: false,
|
|
|
|
uptime: false,
|
|
|
|
infra_logs: false,
|
|
|
|
infra_metrics: false,
|
2020-10-05 19:15:13 +02:00
|
|
|
ux: false,
|
2020-07-16 16:48:12 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
it('returns true when has data and false when an exception happens', async () => {
|
|
|
|
unregisterDataHandler({ appName: 'apm' });
|
|
|
|
unregisterDataHandler({ appName: 'infra_logs' });
|
|
|
|
unregisterDataHandler({ appName: 'infra_metrics' });
|
|
|
|
unregisterDataHandler({ appName: 'uptime' });
|
2020-10-05 19:15:13 +02:00
|
|
|
unregisterDataHandler({ appName: 'ux' });
|
2020-07-16 16:48:12 +02:00
|
|
|
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'apm',
|
|
|
|
fetchData: async () => (({} as unknown) as ApmFetchDataResponse),
|
|
|
|
hasData: async () => true,
|
|
|
|
});
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'infra_logs',
|
|
|
|
fetchData: async () => (({} as unknown) as LogsFetchDataResponse),
|
|
|
|
hasData: async () => true,
|
|
|
|
});
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'infra_metrics',
|
|
|
|
fetchData: async () => (({} as unknown) as MetricsFetchDataResponse),
|
|
|
|
hasData: async () => {
|
|
|
|
throw new Error('BOOM');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'uptime',
|
|
|
|
fetchData: async () => (({} as unknown) as UptimeFetchDataResponse),
|
|
|
|
hasData: async () => {
|
|
|
|
throw new Error('BOOM');
|
|
|
|
},
|
|
|
|
});
|
2020-10-05 19:15:13 +02:00
|
|
|
registerDataHandler({
|
|
|
|
appName: 'ux',
|
|
|
|
fetchData: async () => (({} as unknown) as UxFetchDataResponse),
|
|
|
|
hasData: async () => {
|
|
|
|
throw new Error('BOOM');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(await fetchHasData({ end: 1601632271769, start: 1601631371769 })).toEqual({
|
2020-07-16 16:48:12 +02:00
|
|
|
apm: true,
|
|
|
|
uptime: false,
|
|
|
|
infra_logs: true,
|
|
|
|
infra_metrics: false,
|
2020-10-05 19:15:13 +02:00
|
|
|
ux: false,
|
2020-07-16 16:48:12 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
it('returns true when has data', async () => {
|
|
|
|
unregisterDataHandler({ appName: 'apm' });
|
|
|
|
unregisterDataHandler({ appName: 'infra_logs' });
|
|
|
|
unregisterDataHandler({ appName: 'infra_metrics' });
|
|
|
|
unregisterDataHandler({ appName: 'uptime' });
|
2020-10-05 19:15:13 +02:00
|
|
|
unregisterDataHandler({ appName: 'ux' });
|
2020-07-16 16:48:12 +02:00
|
|
|
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'apm',
|
|
|
|
fetchData: async () => (({} as unknown) as ApmFetchDataResponse),
|
|
|
|
hasData: async () => true,
|
|
|
|
});
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'infra_logs',
|
|
|
|
fetchData: async () => (({} as unknown) as LogsFetchDataResponse),
|
|
|
|
hasData: async () => true,
|
|
|
|
});
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'infra_metrics',
|
|
|
|
fetchData: async () => (({} as unknown) as MetricsFetchDataResponse),
|
|
|
|
hasData: async () => true,
|
|
|
|
});
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'uptime',
|
|
|
|
fetchData: async () => (({} as unknown) as UptimeFetchDataResponse),
|
|
|
|
hasData: async () => true,
|
|
|
|
});
|
2020-10-05 19:15:13 +02:00
|
|
|
registerDataHandler({
|
|
|
|
appName: 'ux',
|
|
|
|
fetchData: async () => (({} as unknown) as UxFetchDataResponse),
|
|
|
|
hasData: async () => ({
|
|
|
|
hasData: true,
|
|
|
|
serviceName: 'elastic-co',
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
expect(await fetchHasData({ end: 1601632271769, start: 1601631371769 })).toEqual({
|
2020-07-16 16:48:12 +02:00
|
|
|
apm: true,
|
|
|
|
uptime: true,
|
|
|
|
infra_logs: true,
|
|
|
|
infra_metrics: true,
|
2020-10-05 19:15:13 +02:00
|
|
|
ux: {
|
|
|
|
hasData: true,
|
|
|
|
serviceName: 'elastic-co',
|
|
|
|
},
|
2020-07-16 16:48:12 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
it('returns false when has no data', async () => {
|
|
|
|
unregisterDataHandler({ appName: 'apm' });
|
|
|
|
unregisterDataHandler({ appName: 'infra_logs' });
|
|
|
|
unregisterDataHandler({ appName: 'infra_metrics' });
|
|
|
|
unregisterDataHandler({ appName: 'uptime' });
|
2020-10-05 19:15:13 +02:00
|
|
|
unregisterDataHandler({ appName: 'ux' });
|
2020-07-16 16:48:12 +02:00
|
|
|
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'apm',
|
|
|
|
fetchData: async () => (({} as unknown) as ApmFetchDataResponse),
|
|
|
|
hasData: async () => false,
|
|
|
|
});
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'infra_logs',
|
|
|
|
fetchData: async () => (({} as unknown) as LogsFetchDataResponse),
|
|
|
|
hasData: async () => false,
|
|
|
|
});
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'infra_metrics',
|
|
|
|
fetchData: async () => (({} as unknown) as MetricsFetchDataResponse),
|
|
|
|
hasData: async () => false,
|
|
|
|
});
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'uptime',
|
|
|
|
fetchData: async () => (({} as unknown) as UptimeFetchDataResponse),
|
|
|
|
hasData: async () => false,
|
|
|
|
});
|
2020-10-05 19:15:13 +02:00
|
|
|
registerDataHandler({
|
|
|
|
appName: 'ux',
|
|
|
|
fetchData: async () => (({} as unknown) as UxFetchDataResponse),
|
|
|
|
hasData: async () => false,
|
|
|
|
});
|
|
|
|
expect(await fetchHasData({ end: 1601632271769, start: 1601631371769 })).toEqual({
|
2020-07-16 16:48:12 +02:00
|
|
|
apm: false,
|
|
|
|
uptime: false,
|
|
|
|
infra_logs: false,
|
|
|
|
infra_metrics: false,
|
2020-10-05 19:15:13 +02:00
|
|
|
ux: false,
|
2020-07-16 16:48:12 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
it('returns false when has data was not registered', async () => {
|
|
|
|
unregisterDataHandler({ appName: 'apm' });
|
|
|
|
unregisterDataHandler({ appName: 'infra_logs' });
|
|
|
|
unregisterDataHandler({ appName: 'infra_metrics' });
|
|
|
|
unregisterDataHandler({ appName: 'uptime' });
|
2020-10-05 19:15:13 +02:00
|
|
|
unregisterDataHandler({ appName: 'ux' });
|
2020-07-16 16:48:12 +02:00
|
|
|
|
2020-10-05 19:15:13 +02:00
|
|
|
expect(await fetchHasData({ end: 1601632271769, start: 1601631371769 })).toEqual({
|
2020-07-16 16:48:12 +02:00
|
|
|
apm: false,
|
|
|
|
uptime: false,
|
|
|
|
infra_logs: false,
|
|
|
|
infra_metrics: false,
|
2020-10-05 19:15:13 +02:00
|
|
|
ux: false,
|
2020-07-16 16:48:12 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-06-25 17:19:38 +02:00
|
|
|
});
|