Rename conversion function, extract to module scope and add tests. (#89018)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
c6cfdee5b0
commit
3fe2e95e35
|
@ -5,9 +5,19 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getUptimeESMockClient } from './helper';
|
import { getUptimeESMockClient } from './helper';
|
||||||
import { getNetworkEvents } from './get_network_events';
|
import { getNetworkEvents, secondsToMillis } from './get_network_events';
|
||||||
|
|
||||||
describe('getNetworkEvents', () => {
|
describe('getNetworkEvents', () => {
|
||||||
|
describe('secondsToMillis conversion', () => {
|
||||||
|
it('returns -1 for -1 value', () => {
|
||||||
|
expect(secondsToMillis(-1)).toBe(-1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns a value of seconds as milliseconds', () => {
|
||||||
|
expect(secondsToMillis(10)).toBe(10_000);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
let mockHits: any;
|
let mockHits: any;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|
|
@ -12,6 +12,10 @@ interface GetNetworkEventsParams {
|
||||||
stepIndex: string;
|
stepIndex: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const secondsToMillis = (seconds: number) =>
|
||||||
|
// -1 is a special case where a value was unavailable
|
||||||
|
seconds === -1 ? -1 : seconds * 1000;
|
||||||
|
|
||||||
export const getNetworkEvents: UMElasticsearchQueryFn<
|
export const getNetworkEvents: UMElasticsearchQueryFn<
|
||||||
GetNetworkEventsParams,
|
GetNetworkEventsParams,
|
||||||
{ events: NetworkEvent[]; total: number }
|
{ events: NetworkEvent[]; total: number }
|
||||||
|
@ -35,17 +39,15 @@ export const getNetworkEvents: UMElasticsearchQueryFn<
|
||||||
|
|
||||||
const { body: result } = await uptimeEsClient.search({ body: params });
|
const { body: result } = await uptimeEsClient.search({ body: params });
|
||||||
|
|
||||||
const microToMillis = (micro: number): number => (micro === -1 ? -1 : micro * 1000);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
total: result.hits.total.value,
|
total: result.hits.total.value,
|
||||||
events: result.hits.hits.map<NetworkEvent>((event: any) => {
|
events: result.hits.hits.map<NetworkEvent>((event: any) => {
|
||||||
const requestSentTime = microToMillis(event._source.synthetics.payload.request_sent_time);
|
const requestSentTime = secondsToMillis(event._source.synthetics.payload.request_sent_time);
|
||||||
const loadEndTime = microToMillis(event._source.synthetics.payload.load_end_time);
|
const loadEndTime = secondsToMillis(event._source.synthetics.payload.load_end_time);
|
||||||
const requestStartTime =
|
const requestStartTime =
|
||||||
event._source.synthetics.payload.response &&
|
event._source.synthetics.payload.response &&
|
||||||
event._source.synthetics.payload.response.timing
|
event._source.synthetics.payload.response.timing
|
||||||
? microToMillis(event._source.synthetics.payload.response.timing.request_time)
|
? secondsToMillis(event._source.synthetics.payload.response.timing.request_time)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in a new issue